コード例 #1
0
ファイル: MusicService.cs プロジェクト: oms064/YoYo-Ma
        /// <summary>
        /// Enqueues a new song in the relative channel queue
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        public void EnqueueSong(GuildMusicChannel channel, MusicData item)
        {
            if (channel.Queue.Count >= GuildMusicChannel.QUEUE_CAPACITY)
            {
                throw new IndexOutOfRangeException($"Queue reached maximum capacity of {GuildMusicChannel.QUEUE_CAPACITY}! Get a grip man...");
            }

            channel.Queue.Enqueue(item);
        }
コード例 #2
0
ファイル: MusicService.cs プロジェクト: oms064/YoYo-Ma
        /// <summary>
        /// Kills music process (if necessary) and dequeues current song from channel
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        public async Task <bool> TryDequeueSong(GuildMusicChannel channel)
        {
            if (channel.MusicProc != null)
            {
                await channel.MusicProc.Kill(ProcessStartMode.OUTPUT);

                channel.MusicProc = null;
            }
            channel.IsPlaying = false;
            return(channel.Queue.TryDequeue(out MusicData result));
        }
コード例 #3
0
ファイル: MusicService.cs プロジェクト: oms064/YoYo-Ma
 /// <summary>
 /// Sets the volume for the channel associated with a guild
 /// </summary>
 /// <param name="guild">Guild reference</param>
 /// <param name="volume">Volume to set [0, 100]</param>
 public void SetVolume(DiscordGuild guild, ushort volume)
 {
     if (this.MusicChannels.TryGetValue(guild.Id, out GuildMusicChannel channel))
     {
         channel.Volume = volume;
     }
     else
     {
         var newMusicChannel = new GuildMusicChannel(guild)
         {
             Volume = volume
         };
         this.MusicChannels.TryAdd(guild.Id, newMusicChannel);
     }
 }
コード例 #4
0
ファイル: MusicService.cs プロジェクト: oms064/YoYo-Ma
        /// <summary>
        /// Joins a voice channel
        /// </summary>
        /// <param name="vnext">VoiceNext instance</param>
        /// <param name="voiceChannel">Voice channel to join</param>
        /// <returns></returns>
        public async Task <GuildMusicChannel> JoinVoiceChannel(VoiceNextExtension vnext, DiscordChannel voiceChannel)
        {
            var vnc = vnext.GetConnection(voiceChannel.Guild);

            var channel = new GuildMusicChannel(voiceChannel.Guild);

            if (!this.MusicChannels.TryAdd(voiceChannel.GuildId, channel))
            {
                // If the add fails, it means there is already a channel for this guild, recover it
                this.MusicChannels.TryGetValue(voiceChannel.GuildId, out channel);
            }
            channel.IsConnected = true;

            if (vnc != null)
            {
                return(channel);
            }

            vnc = await vnext.ConnectAsync(voiceChannel);

            return(channel);
        }