public static void RemoveLeftoverChannels(SocketGuild server)
        {
            List <SocketVoiceChannel> toDelete = new List <SocketVoiceChannel> ();

            foreach (SocketVoiceChannel channel in server.VoiceChannels)
            {
                if (!defaultChannels.ContainsKey(channel.Id) && channel.Users.Count() == 0)
                {
                    toDelete.Add(channel);
                }
            }

            for (int i = IsDefaultFull() ? 1 : 0; i < toDelete.Count; i++)
            {
                SocketVoiceChannel channel     = toDelete [i];
                string             channelName = allVoiceChannels [channel.Id].name;
                if (channelName != postRebootChannelName && nameQueue.ContainsKey(channelName))
                {
                    nameQueue [channelName] = false;
                }

                temporaryChannels.Remove(channel);
                allVoiceChannels.Remove(channel.Id);
                channel.DeleteAsync();
            }

            ResetVoiceChannelPositions(server);
        }
        public static async Task RemoveVoiceChannelAsync(this SocketVoiceChannel toRemove, IVoiceChannel moveTo = null)
        {
            foreach (var user in toRemove.Users)
            {
                await user.ModifyAsync(u => u.Channel = Optional.Create(moveTo));
            }

            await toRemove.DeleteAsync();
        }
Exemplo n.º 3
0
        public static Task CheckVoiceChannelOnDelete(SocketChannel channel)
        {
            if (channel is SocketVoiceChannel voiceChannel)
            {
                DiscordServer    server = DiscordServer.GetServerFromID(voiceChannel.Guild.Id);
                VoiceChannelRole vcRole = server.voiceChannelRoles.Find(x => x.voiceChannelID == voiceChannel.Id);

                server.voiceChannelRoles.Remove(vcRole);

                SocketRole role = server.Guild.GetRole(vcRole.roleID);

                if (vcRole.voiceChannelID != 0)
                {
                    SocketTextChannel textChannelDeletion = server.Guild.GetTextChannel(vcRole.textChannelID);
                    if (textChannelDeletion != null)
                    {
                        textChannelDeletion.DeleteAsync();
                    }
                }

                if (role != null)
                {
                    role.DeleteAsync();
                }

                server.SaveData();
            }

            if (channel is SocketTextChannel textChannel)
            {
                DiscordServer    server = DiscordServer.GetServerFromID(textChannel.Guild.Id);
                VoiceChannelRole vcRole = server.voiceChannelRoles.Find(x => x.textChannelID == textChannel.Id);

                server.voiceChannelRoles.Remove(vcRole);

                SocketRole role = server.Guild.GetRole(vcRole.roleID);

                if (vcRole.voiceChannelID != 0)
                {
                    SocketVoiceChannel voiceChannelDeletion = server.Guild.GetVoiceChannel(vcRole.voiceChannelID);
                    if (voiceChannelDeletion != null)
                    {
                        voiceChannelDeletion.DeleteAsync();
                    }
                }

                if (role != null)
                {
                    role.DeleteAsync();
                }

                server.SaveData();
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 4
0
 public static async Task HandleEmptyChannel(SocketVoiceChannel vc)
 {
     if (bonfires.ContainsValue(vc.Id))
     {
         bonfires.Remove(bonfires.Where(kvp => kvp.Value == vc.Id).First().Key);
         await vc.DeleteAsync(new RequestOptions()
         {
             AuditLogReason = "User-created channel empty"
         });
     }
 }
Exemplo n.º 5
0
        private async Task DeleteGameRoleAndVoiceChannel(SocketGuild guild, IRole gameRole, SocketGuildUser user)
        {
            await user.RemoveRoleAsync(gameRole);

            if (!guild.Users.Where(x => x != user).Any(x => x.Roles.Contains(gameRole))) // raderar
            {
                SocketVoiceChannel channel = guild.VoiceChannels.Where(x => x.ToString().Equals(gameRole.Name) && x.Bitrate == 96000).FirstOrDefault();
                await gameRole.DeleteAsync();

                await channel.DeleteAsync();
            }
        }
Exemplo n.º 6
0
        private async Task LeaveChannel(SocketVoiceChannel channel, SocketGuildUser user)
        {
            try
            {
                if (channel == null)
                {
                    return;
                }

                if (channel.Users.Count != 0)
                {
                    if (channel.Users.Count != 1 || !channel.Users.First().Id.Equals(_client.CurrentUser.Id))
                    {
                        return;
                    }
                    var audioService = (AudioService)_services.GetService(typeof(AudioService));
                    audioService.BeforeExecute(channel.Guild.Id);
                    await audioService.TextChannel.SendMessageAsync("Music player was terminated. All users have left the voice channel.");

                    audioService.Stop();
                    return;
                }

                while (_channels.Contains(channel.Id))
                {
                    await Task.Delay(100);
                }

                var autoChannel = AutoChannel.Load(channel.Guild.Id);
                if (!autoChannel.IsControlledChannel(channel.Id))
                {
                    return;
                }
                var userName = user?.Nickname ?? user?.Username ?? "User";
                LogsHandler.Instance.Log("Channels", channel.Guild, $"{userName} left channel '{channel.Name}'.");
                autoChannel.RemoveChannel(channel.Id);
                autoChannel.Save();
                await channel.DeleteAsync();
            }
            catch (Exception e)
            {
                var info = channel == null ? "Null channel" : $"({channel.Guild.Id}) {channel.Id}, {channel.Name}";
                LogsHandler.Instance.Log("Crashes", $"LeaveChannel crashed. {info}. Stacktrace: {e}");
            }
        }
Exemplo n.º 7
0
        private async Task LeaveChannel(SocketVoiceChannel channel, SocketGuildUser user)
        {
            if (channel == null)
            {
                return;
            }
            try
            {
                if (channel.Users.Count > 0)
                {
                    return;
                }
                if (!await _channel.IsGeneratedChannel(channel))
                {
                    return;
                }
                while (_channels.Contains(channel.Id))
                {
                    await Task.Delay(100);
                }

                await Logs.Write("Channels", $"{user.Nickname()} left channel '{channel.Name}'.", channel.Guild);

                if (channel.Guild.GetChannel(channel.Id) == null)
                {
                    return;
                }
                await channel.DeleteAsync();

                await _channel.RemoveGeneratedChannel(channel.Guild.Id, channel.Id);
            }
            catch (Exception e)
            {
                await Logs.Write("Crashes",
                                 $"LeaveChannel crashed. ({channel.Guild.Id}) {channel.Id}, {channel.Name}.", e);
            }
        }
Exemplo n.º 8
0
 private async Task DeleteChannel(SocketVoiceChannel channel)
 {
     await channel.DeleteAsync();
 }