Ejemplo n.º 1
0
        public static async Task FindBadGuilds(bool ignoreExcessiveAmount = false)
        {
            // Create a copy of the GuildSettings
            List <GuildSettings> allGuildSettings = new List <GuildSettings>(Configuration.LoadedConfiguration.DiscordConfig.GuildSettings);

            // Create a list for deregistration candidates
            List <SocketGuildChannel> deregistrationCandidates = new List <SocketGuildChannel>();

            foreach (GuildSettings guildSettings in allGuildSettings)
            {
                foreach (KeyValuePair <ulong, DynamicSettingsData> pair in guildSettings.ChannelSettings)
                {
                    // Get the channel
                    SocketGuildChannel channel = (SocketGuildChannel)DiscordBot.GetChannel(pair.Key);

                    // Check if the channel no longer exists
                    if (channel == null)
                    {
                        continue;
                    }

                    // Get the Permissions
                    ChannelPermissions permissions = channel.Guild.CurrentUser.GetPermissions(channel);

                    // Check if we can't write to this channel
                    if (!permissions.Has(ChannelPermission.SendMessages))
                    {
                        deregistrationCandidates.Add(channel);
                    }
                }
            }

            // Skip deregistration if there are a large number of guilds to deregister
            if (deregistrationCandidates.Count > 5 && !ignoreExcessiveAmount)
            {
                await DiscordBot.LoggingChannel.SendMessageAsync($"**[DiscordUtil]** Skipping deregistration, there seems to be an excessive amount of guilds to deregister ({deregistrationCandidates.Count})");

                return;
            }

            foreach (SocketGuildChannel guildChannel in deregistrationCandidates)
            {
                // Remove the channel settings
                Configuration.LoadedConfiguration.DiscordConfig.GuildSettings.Where(g => g.GuildId == guildChannel.Guild.Id).FirstOrDefault().ChannelSettings.TryRemove(guildChannel.Id, out DynamicSettingsData data);

                // Send a message to this server that their guild has been deregistered
                Embed embed = new EmbedBuilder()
                              .WithTitle("Warning")
                              .WithDescription(Localizer.Localize("discord.guild.deregister", (Language)data.GetSetting("language")))
                              .WithColor(Color.Orange)
                              .Build();

                await DiscordBot.SendMessageToFirstWritableChannel(guildChannel.Guild, embed : embed);

                await DiscordBot.LoggingChannel.SendMessageAsync($"**[Guild]** Deregistered \"#{guildChannel.Name}\" ({guildChannel.Id}) on \"{guildChannel.Guild.Name}\"");
            }
        }
Ejemplo n.º 2
0
        public static async Task ProcessJoinedGuild(SocketGuild socketGuild)
        {
            // Build an Embed
            Embed embed = new EmbedBuilder()
                          .WithTitle("Welcome")
                          .WithDescription(Localizer.Localize("discord.guild.join", Language.EnglishUS))
                          .WithColor(Color.Blue)
                          .Build();

            await DiscordBot.SendMessageToFirstWritableChannel(socketGuild, embed : embed);

            await DiscordBot.LoggingChannel.SendMessageAsync($"**[Guild]** Joined \"{socketGuild.Name}\" ({socketGuild.Id})");
        }