Exemplo n.º 1
0
        private async Task UpdateWrapper(
            AudioClientWrapper wrapper,
            IUserMessage msg,
            IGuild guild,
            SocketReaction reaction)
        {
            await msg.RemoveReactionAsync(reaction.Emote, reaction.User.Value).ConfigureAwait(false);

            await GetAction(reaction.Emote).ConfigureAwait(false);

            Task GetAction(IEmote emote)
            {
                switch (emote.Name)
                {
                case "\u25B6":     //play
                    if (wrapper.IsPlaying())
                    {
                        return(ResumePlayback(guild));
                    }

                    Task.Run(() => Playlist(guild).ConfigureAwait(false));
                    goto default;

                case "\u23F8":     //pause
                    return(PausePlayback(guild));

                case "\u23F9":     //stop
                    StopPlaying(guild);
                    goto default;

                case "\u23ED":     //fwd
                    NextSong(guild);
                    goto default;

                case "\u23CF":     //eject
                    return(LeaveAudio(guild));

                default:
                    return(Task.CompletedTask);
                }
            }
        }
Exemplo n.º 2
0
        internal async Task JoinAudio(IGuild guild, IMessageChannel channel, IVoiceChannel target)
        {
            if (Clients.TryGetValue(guild.Id, out _))
            {
                return;
            }
            if (target.Guild.Id != guild.Id)
            {
                return;
            }


            var guildConfig = await Config.GetConfigForGuildAsync(guild);

            var audioClient = await target.ConnectAsync().ConfigureAwait(false);

            var message = await channel.SendMessageAsync("", embed : _initEmbed).ConfigureAwait(false);

            var wrapper = new AudioClientWrapper(audioClient, message, Config, guildConfig);

            if (Clients.TryAdd(guild.Id, wrapper))
            {
                await Log(LogSeverity.Info, $"Connected to voice channel '{target.Name}' on '{guild.Name}'.").ConfigureAwait(false);

                //audioClient.Connected += AudioClient_Connected;
                //audioClient.Disconnected += AudioClient_Disconnected;
            }

            if (guildConfig?.ShowSongListOnJoin ?? Config.ShowSongListOnJoin)
            {
                ListSongs(channel);
            }

            if (guildConfig?.AutoPlay ?? Config.AutoPlay)
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Task.Run(() => Playlist(guild).ConfigureAwait(false));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }
        }