示例#1
0
        /// <summary>Makes bot leave voice channel and reacts to user message with 'byeEmoji'.
        /// </summary>
        public async Task LeaveAsync(SocketCommandContext context)
        {
            var guild = context.Guild;

            var byeEmoji = new Emoji("👋");

            if (!_lavaNode.HasPlayer(guild))
            {
                await context.Message.AddReactionAsync(byeEmoji);

                return;
            }

            try
            {
                //Get The Player Via GuildID.
                var player = _lavaNode.GetPlayer(guild);

                //if The Player is playing, Stop it.
                if (player.PlayerState is PlayerState.Playing)
                {
                    await player.StopAsync();
                }

                //Leave the voice channel.
                await _lavaNode.LeaveAsync(player.VoiceChannel);

                await context.Message.AddReactionAsync(byeEmoji);
            }
            //Tell the user about the error so they can report it back to us.
            catch (Exception ex)
            {
                await context.Channel.SendMessageAsync(embed : CustomFormats.CreateErrorEmbed(ex.Message));
            }
        }
示例#2
0
        private static async Task InitiateDisconnectAsync(LavaPlayer player, TimeSpan timeSpan)
        {
            Language lang = Commands.GetLanguage(player.VoiceChannel.GuildId);

            if (!_disconnectTokens.TryGetValue(player.VoiceChannel.Id, out CancellationTokenSource value))
            {
                value = new CancellationTokenSource();
                _disconnectTokens.TryAdd(player.VoiceChannel.Id, value);
            }
            else if (value.IsCancellationRequested)
            {
                _disconnectTokens.TryUpdate(player.VoiceChannel.Id, new CancellationTokenSource(), value);
                value = _disconnectTokens[player.VoiceChannel.Id];
            }

            await player.TextChannel.SendMessageAsync($"Auto disconnect initiated! Disconnecting in {timeSpan}...");

            bool isCancelled = SpinWait.SpinUntil(() => value.IsCancellationRequested, timeSpan);

            if (isCancelled)
            {
                return;
            }

            await _lavaNode.LeaveAsync(player.VoiceChannel);

            await player.TextChannel.SendMessageAsync(lang.Goodbye);
        }
示例#3
0
 private async Task UserVoiceStateUpdate(SocketUser user, SocketVoiceState oldstate, SocketVoiceState newState)
 {
     if (!AdminUsers.ContainsKey(user.Id))
     {
         return;
     }
     if (oldstate.VoiceChannel == newState.VoiceChannel)
     {
         return;
     }
     AdminUsers.Remove(user.Id);
     await _lavaNode.LeaveAsync(oldstate.VoiceChannel);
 }
示例#4
0
        public async Task <LavaPlayer?> JoinAsync(ICommandContext context, ITextChannel textChannel, bool sendMsg = true, bool sendAdv = true)
        {
            if (context.Guild == null)
            {
                return(null);
            }
            ;
            _audio.TryGetPlayer(context.Guild, out var guild);
            var usersVc = context.UsersVC() as SocketVoiceChannel;
            var user    = context.User as IGuildUser;

            if (usersVc == null)
            {
                if (sendMsg)
                {
                    await textChannel.SendMessageAsync($":musical_note: {context.User.Mention} You are not in a voice channel.");
                }
                return(null);
            }
            if (guild == null)
            {
                if (sendMsg && sendAdv)
                {
                    await textChannel.SendMessageAsync($":musical_note: {context.User.Mention} Successfuly joined your voice channel!");
                }
                return(await _audio.JoinAsync(context.UsersVC(), textChannel));
            }
            else if (usersVc.Id == guild.VoiceChannel.Id)
            {
                if (sendMsg && sendAdv)
                {
                    await textChannel.SendMessageAsync($":musical_note: {context.User.Mention} We are in the same voice channel already!");
                }
                return(guild);
            }
            else if (usersVc.Users.Count > 1 && !user.HasRole("DJ"))
            {
                if (sendMsg)
                {
                    await textChannel.SendMessageAsync($":musical_note: {context.User.Mention} You don't have the valid permissions to do this action.");
                }
                return(null);
            }
            if (sendMsg && sendAdv)
            {
                await textChannel.SendMessageAsync($":musical_note: {context.User.Mention} Successfuly joined your voice channel!");
            }
            await _audio.LeaveAsync(guild.VoiceChannel);

            return(await _audio.JoinAsync(context.UsersVC(), textChannel));
        }
示例#5
0
        private async Task InitDisconnect(LavaPlayer player, TimeSpan timeSpan)
        {
            //If player hasn't got cancellation token, create one
            if (!_disconnectTokens.TryGetValue(player.VoiceChannel.Id, out var value))
            {
                value = new CancellationTokenSource();
                _disconnectTokens.TryAdd(player.VoiceChannel.Id, value);
            }

            //if token already existed and is active
            else if (value.IsCancellationRequested)
            {
                _disconnectTokens.TryUpdate(player.VoiceChannel.Id, new CancellationTokenSource(), value);
                value = _disconnectTokens[player.VoiceChannel.Id];
            }

            await player.TextChannel.SendMessageAsync(
                $"No more tracks to play, I will auto-disconnect in {timeSpan.Minutes} minues if you won't play anything!");

            //wait for the timeSpan for Cancellationtoken to be in cancellation state
            var isCancelled = SpinWait.SpinUntil(() => value.IsCancellationRequested, timeSpan);

            if (isCancelled)
            {
                return;
            }

            value.Dispose();
            _disconnectTokens.TryUpdate(player.VoiceChannel.Id, new CancellationTokenSource(), value);
            //disconnect
            await _lavaNode.LeaveAsync(player.VoiceChannel);

            await player.TextChannel.SendMessageAsync(
                $"I wasn't playing any track for {timeSpan.Minutes} minutes. **Disconnecting**");
        }
示例#6
0
        public async Task LeaveAsync()
        {
            if (!_lavaNode.TryGetPlayer(Context.Guild, out var player))
            {
                await ReplyAsync("F**k you.");

                return;
            }

            var voiceChannel = (Context.User as IVoiceState).VoiceChannel ?? player.VoiceChannel;

            if (voiceChannel == null)
            {
                await ReplyAsync("From Where?");

                return;
            }

            try
            {
                await _lavaNode.LeaveAsync(voiceChannel);
                await ReplyAsync($"I'm outta {voiceChannel.Name} bitch.");
            }
            catch (Exception ex)
            {
                await ReplyAsync(ex.Message);
            }
        }
示例#7
0
        private async Task OnReady()
        {
            if (!lavaNode.IsConnected)
            {
                await lavaNode.ConnectAsync();
            }

            if (data.Count <= 0)
            {
                return;
            }

            foreach (KeyValuePair <ulong, LavalinkData> data in data)
            {
                await lavaNode.LeaveAsync(data.Value.VoiceChannel);

                NixPlayer player = await CreatePlayerForGuildAsync(
                    data.Value.VoiceChannel.Guild,
                    data.Value.VoiceChannel,
                    data.Value.TextChannel);

                players.TryAdd(data.Key, player);
                await player.PlayAsync(data.Value);
            }

            data.Clear();
        }
示例#8
0
        public async Task LeaveAsync()
        {
            if (!_lavaNode.TryGetPlayer(Context.Guild, out var player))
            {
                await ReplyAndDeleteAsync($"{Global.ENo} | I'm not connected to any voice channels!");

                return;
            }

            var voiceChannel = (Context.User as IVoiceState).VoiceChannel ?? player.VoiceChannel;

            if (voiceChannel == null)
            {
                await ReplyAndDeleteAsync($"{Global.ENo} | I cannot disconnect from a voice channel you are not in!");

                return;
            }

            try
            {
                await _lavaNode.LeaveAsync(voiceChannel);
                await ReplyAsync($"✅ **|** I've left **{voiceChannel.Name}**!");
            }
            catch (Exception exception)
            {
                await ReplyAsync(exception.Message);
            }
        }
示例#9
0
        public async Task LeaveAsync()
        {
            if (!_lavaNode.HasPlayer(Context.Guild))
            {
                await ReplyAsync("I'm not connected to a voice channel!");

                return;
            }
            var voiceState = Context.User as IVoiceState;

            if (voiceState?.VoiceChannel == null)
            {
                await ReplyAsync("You must be connected to a voice channel!");

                return;
            }
            try
            {
                await _lavaNode.LeaveAsync(voiceState.VoiceChannel);
                await ReplyAsync($"Joined {voiceState.VoiceChannel.Name}!");
            }
            catch (Exception exception)
            {
                await ReplyAsync(exception.Message);
            }
        }
示例#10
0
        public async Task <string> LeaveChannel(IGuild guild, IVoiceChannel voiceChannel)
        {
            await lavaNode.LeaveAsync(voiceChannel);

            guildInfo.TryRemove(guild, out var value);
            return($"Left {voiceChannel.Name}.");
        }
示例#11
0
        // ---------------------------- Victoria Event Helpers ----------------------------

        private async Task InitiateDisconnectAsync(LavaPlayer player, TimeSpan timeSpan)
        {
            if (!_disconnectTokens.TryGetValue(player.VoiceChannel.Id, out var value))
            {
                value = new CancellationTokenSource();
                _disconnectTokens.TryAdd(player.VoiceChannel.Id, value);
            }
            else if (value.IsCancellationRequested)
            {
                _disconnectTokens.TryUpdate(player.VoiceChannel.Id, new CancellationTokenSource(), value);
                value = _disconnectTokens[player.VoiceChannel.Id];
            }

            await player.TextChannel.SendMessageAsync($"Auto disconnect initiated, Disconnecting in: {timeSpan}...");

            var isCancelled = SpinWait.SpinUntil(() => value.IsCancellationRequested, timeSpan);

            if (isCancelled)
            {
                return;
            }

            await _lavaNode.LeaveAsync(player.VoiceChannel);

            await player.TextChannel.SendMessageAsync("Lets do it again sometime.");
        }
示例#12
0
    public async Task LeaveAsync()
    {
        if (!_lavaNode.TryGetPlayer(Context.Guild, out var player))
        {
            await ReplyAsync("I'm not connected to any voice channels!");

            return;
        }

        var voiceChannel = (Context.User as IVoiceState)?.VoiceChannel ?? player.VoiceChannel;

        if (voiceChannel == null)
        {
            await ReplyAsync("Not sure which voice channel to disconnect from.");

            return;
        }

        try
        {
            await _lavaNode.LeaveAsync(voiceChannel);
            await ReplyAsync($"I've left {voiceChannel.Name}!");
        }
        catch (Exception exception)
        {
            await ReplyAsync(exception.Message);
        }
    }
示例#13
0
        public async Task LeaveVc()
        {
            if (!_node.TryGetPlayer(Context.Guild, out var player))
            {
                await ReplyFailureEmbed("I'm not connected to any VC in this guild");

                return;
            }

            var playerVc = player.VoiceChannel;

            if (!await CheckIfSameVc(playerVc) && CheckChannelIsStillValid(playerVc))
            {
                return;
            }

            try
            {
                await _node.LeaveAsync(playerVc);
            }
            catch (Exception)
            {
                await ReplyFailureEmbed("Something went wrong when i tried to leave :/");
            }
        }
示例#14
0
        // Called when the bot leaves the channel
        public async Task <Embed> LeaveAsync(IGuild guild)
        {
            try
            {
                //Get The Player Via GuildID.
                var player = _lavaNode.GetPlayer(guild);

                //if The Player is playing, Stop it.
                if (player.PlayerState is PlayerState.Playing)
                {
                    await player.StopAsync();
                }

                //Leave the voice channel.
                await _lavaNode.LeaveAsync(player.VoiceChannel);

                await player.DisposeAsync();

                Log.Information("Music", $"Bot has left.");
                return(await EmbedHandler.CreateBasicEmbed("Night Rune", $"Leaving voice channel.", Color.Blue));
            }
            //Tell the user about the error so they can report it back to us.
            catch (InvalidOperationException ex)
            {
                return(await EmbedHandler.CreateErrorEmbed("Music, Leave", ex.Message));
            }
        }
示例#15
0
        public async Task DisconnectAsync()
        {
            if (!_lavaNode.HasPlayer(Context.Guild))
            {
                await ReplyAsync("I'm not in a voice channel!");

                return;
            }

            var voiceState = Context.User as IVoiceState;

            if (voiceState?.VoiceChannel == null)
            {
                await ReplyAsync("You must be connected to a voice channel!");

                return;
            }

            try
            {
                await _lavaNode.LeaveAsync(voiceState.VoiceChannel);

                await Context.Channel.SendSuccessAsync("Success", $"Disconnected from {voiceState.VoiceChannel.Name}");
            }
            catch (Exception exception)
            {
                await Context.Channel.SendErrorAsync("Error", exception.Message);
            }
        }
示例#16
0
        public static async Task EjectAsync(
            this LavaNode node,
            EmbedHelper embedHelper,
            IGuild guild,
            SocketCommandContext context = null)
        {
            if (context == null)
            {
                return;
            }

            if (!node.TryGetPlayer(guild, out var player))
            {
                return;
            }

            player.Queue.Clear();
            await node.LeaveAsync(player.VoiceChannel);

            if (context != null && !context.Guild.TextChannels.Where(x => x.Id == Program.BotConfig.ChannelId).Any())
            {
                return;
            }
            var embed = await EmbedHelper.BuildDefaultEmbed();

            await Program.BotConfig.BotEmbedMessage.ModifyAsync(x => { x.Content = AudioHelper.NoSongsInQueue; x.Embed = embed; });
        }
示例#17
0
        public async Task LeaveAsync()
        {
            if (!_lavaNode.TryGetPlayer(Context.Guild, out var player))
            {
                await ReplyAsync("I'm not connected to any voice channels!");

                return;
            }

            var voiceChannel = (Context.User as IVoiceState).VoiceChannel ?? player.VoiceChannel;

            if (voiceChannel == null)
            {
                await ReplyAsync("Not sure which voice channel to disconnect from.");

                return;
            }

            try
            {
                await _lavaNode.LeaveAsync(voiceChannel);
                await ReplyAsync($"I've left {voiceChannel.Name}!");
            }
            catch (Exception ex)
            {
                await this.LogAsync(new LogMessage(LogSeverity.Error, "Music Module", ex.Message));
                await ReplyAsync("Something happened that i can't leave the VC!");
            }
        }
示例#18
0
        public async Task <IXyloxServiceResult> LeaveAsync(ulong voiceId)
        {
            var voiceChannel = GetDiscordChannel <IVoiceChannel>(voiceId);
            await _lavaNode.LeaveAsync(voiceChannel);

            return(new XyloxServiceResult {
                Message = $"Now Left {voiceChannel.Name}"
            });
        }
示例#19
0
        public async Task Disconnect()
        {
            var voiceState = Context.User as IVoiceState;

            if (_lavaNode.HasPlayer(Context.Guild) && voiceState.VoiceChannel != null)
            {
                await _lavaNode.LeaveAsync(voiceState.VoiceChannel);
                await ReplyAsync($"Disconnected from {voiceState.VoiceChannel.Name}!");
            }
        }
示例#20
0
        private async Task OnUserVoiceStateUpdated(SocketUser user, SocketVoiceState oldState, SocketVoiceState newState)
        {
            var guild = newState.VoiceChannel?.Guild ?? oldState.VoiceChannel?.Guild;

            if (guild == null)
            {
                return;
            }
            if (!_lavaNode.TryGetPlayer(guild, out var player))
            {
                return;
            }
            // So this is a guild that has a currently active sora music player. Let's investigate
            if (player.VoiceChannel == null)
            {
                return;                              // shouldn't ever happen but we never know
            }
            SocketVoiceChannel vc = guild.CurrentUser.VoiceChannel;

            if (vc == null)
            {
                return;             // Sora is in none so we'll just ignore this.
            }
            var userCount = vc.Users.Count(x => !x.IsBot);

            if (userCount > 0)
            {
                // Check if channel is AFK channel
                if (guild.AFKChannel?.Id == player.VoiceChannel.Id)
                {
                    // leave this shit
                    await _lavaNode.LeaveAsync(player.VoiceChannel);

                    return;
                }
                // No action required
                return;
            }

            // Otherwise we leave the VC.
            await _lavaNode.LeaveAsync(player.VoiceChannel);
        }
示例#21
0
        public async Task LeaveAsync()
        {
            if (!_lavaNode.HasPlayer(Context.Guild))
            {
                await ReplyAsync("I'm not connected to a channel");

                return;
            }

            var voiceChannel = _lavaNode.GetPlayer(Context.Guild).VoiceChannel;
            await _lavaNode.LeaveAsync(voiceChannel);
        }
示例#22
0
        public async Task LeaveAsync(SocketVoiceChannel voiceChannel)
        {
            if (_player != null && _player.PlayerState == PlayerState.Playing)
            {
                await _player.StopAsync();
            }
            _player.Queue.Clear();
            await _lavaNode.LeaveAsync(voiceChannel);

            _loop  = false;
            _qloop = false;
        }
示例#23
0
        public async Task <Dictionary <ulong, ulong> > CheckCommand(ISocketMessageChannel channel, SocketReaction reaction, RestUserMessage message, LavaNode lavaNode, Dictionary <ulong, ulong> Providers)//переделать на симофор
        {
            var guild = (channel as SocketGuildChannel).Guild;

            if (reaction.User.Value.Id != Provider.Id)
            {
                return(Providers);
            }
            switch (reaction.Emote.Name)
            {
            case ("🔺"):
                await IncreaseVolumeAsync();

                break;

            case ("🔻"):
                await DecreaseVolumeAsync();

                break;

            case ("\u23EF"):
                await PauseOrResumeAsync();

                break;

            case ("\u23ED"):
                await AddPositionAsync();

                break;

            case ("\u23EE"):
                await RemovePositionAsync();

                break;

            case ("🔲"):
                await SkipAsync();

                break;

            case ("\u274C"):
                Providers.Remove(reaction.UserId);
                await channel.DeleteMessageAsync(reaction.MessageId);

                await lavaNode.LeaveAsync(guild.CurrentUser.VoiceChannel);

                break;
            }
            await ModifyMessage(message);

            return(Providers);
        }
示例#24
0
        public async Task LeaveAsync()
        {
            if (!_lavaNode.HasPlayer(Context.Guild))
            {
                await ReplyAndDeleteAsync(":x: I am not connected to a voice channel.");

                return;
            }

            var channel = _lavaNode.GetPlayer(Context.Guild).VoiceChannel;

            await _lavaNode.LeaveAsync(channel);

            await ReplyAndDeleteAsync($"Left **{channel.Name}**.");
        }
示例#25
0
        private async Task LeaveAsync(LavaNode lavaNode)
        {
            if (!lavaNode.HasPlayer(Context.Guild))
            {
                await ReplyAsync("I'm not connected to a voice channel.");

                return;
            }
            else
            {
                if (Context.User is IVoiceState voiceState)
                {
                    await lavaNode.LeaveAsync(voiceState.VoiceChannel);
                }
            }
        }
示例#26
0
        /// <summary>
        ///     Disconnect from a voice channel.
        /// </summary>
        /// <param name="voiceChannel">The voice channel to connect to.</param>
        /// <exception cref="InvalidPlayerException">Thrown if not connected to a voice channel.</exception>
        /// <exception cref="InvalidAudioChannelException">Thrown if not connected to the specified voice channel.</exception>
        public async Task Leave(IVoiceChannel voiceChannel)
        {
            if (_player == null)
            {
                throw new InvalidPlayerException("Not connected to a voice channel");
            }
            if (!_player.VoiceChannel.Id.Equals(voiceChannel.Id))
            {
                throw new InvalidAudioChannelException("The argument is not the same as the source.");
            }

            if (_player.Track != null)
            {
                await _player.StopAsync();
            }
            await _lavaNode.LeaveAsync(voiceChannel);
        }
示例#27
0
        public static async Task <string> LeaveAsync(IGuild guild)
        {
            try
            {
                var player = _lavaNode.GetPlayer(guild);
                if (player.PlayerState is PlayerState.Playing)
                {
                    await player.StopAsync();
                }
                await _lavaNode.LeaveAsync(player.VoiceChannel);

                Console.WriteLine($"[{DateTime.Now}]\t(AUDIO)\tBen kaçtım maymunlar bye.");
                return("Ben kaçtım maymunlar bye.");
            }
            catch (InvalidOperationException ex)
            {
                return($"ERROR: {ex.Message}");
            }
        }
示例#28
0
文件: Leave.cs 项目: kaguyabot/Kaguya
        public async Task Command()
        {
            Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id);

            LavaNode           node    = ConfigProperties.LavaNode;
            SocketGuildUser    curUser = Context.Guild.CurrentUser;
            SocketVoiceChannel curVc   = curUser.VoiceChannel;

            if (node.HasPlayer(Context.Guild))
            {
                if (curVc == null)
                {
                    await SendBasicErrorEmbedAsync($"{Context.User.Mention} Please ensure I " +
                                                   $"am actively in a voice channel before using " +
                                                   $"this command.");
                }
                else
                {
                    try
                    {
                        await node.LeaveAsync(curVc);
                    }
                    catch (Exception)
                    {
                        throw new KaguyaSupportException("Error when disconnecting from voice channel:\n\n" +
                                                         $"Channel name: `{curVc.Name}`\n" +
                                                         $"Users connected (including Kaguya): `{curVc.Users.Count:N0}`\n\n" +
                                                         $"Develper Note: `Please report this to the provided " +
                                                         $"Discord server and contact Stage. Thanks!`");
                    }

                    await SendBasicSuccessEmbedAsync(
                        $"{Context.User.Mention} Successfully disconnected from `{curVc.Name}`.");
                }
            }
            else
            {
                await SendBasicErrorEmbedAsync($"{Context.User.Mention} I must be in a voice channel via " +
                                               $"the `{server.CommandPrefix}join` command for this " +
                                               $"command to work. Please try **joining a new voice channel** via " +
                                               $"`{server.CommandPrefix}join` if I am refusing to connect/disconnect.");
            }
        }
示例#29
0
        public async Task Disconnect()
        {
            if (!_lavaNode.HasPlayer(Context.Guild))
            {
                await Context.Channel.SendErrorAsync("Music", "I'm not connected to a voice channel.");

                return;
            }

            var player = _lavaNode.GetPlayer(Context.Guild);

            if (player.PlayerState is PlayerState.Playing)
            {
                await player.StopAsync();
            }

            await _lavaNode.LeaveAsync(player.VoiceChannel);

            await Context.Channel.SendSuccessAsync("Music", "Disconnected from all voice channels!");
        }
示例#30
0
        public async Task LeaveAsync()
        {
            var voiceState = Context.User as IVoiceState;

            if (voiceState?.VoiceChannel == null)
            {
                await FormatEmbedMessage("You must be connected to a voice channel!");

                return;
            }

            try
            {
                await _lavaNode.LeaveAsync(voiceState.VoiceChannel);
                await FormatEmbedMessage($"Disconnected from {voiceState.VoiceChannel.Name}!");
            }
            catch (Exception exception)
            {
                await FormatEmbedMessage(exception.Message);
            }
        }