示例#1
0
        public async Task ListAsync(CommandContext ctx)
        {
            IReadOnlyList <PrivilegedUser> privileged = await this.Service.GetAsync();

            var notFound = new List <PrivilegedUser>();
            var valid    = new List <DiscordUser>();

            foreach (PrivilegedUser pu in privileged)
            {
                try {
                    DiscordUser user = await ctx.Client.GetUserAsync(pu.UserId);

                    valid.Add(user);
                } catch (NotFoundException) {
                    LogExt.Debug(ctx, "Found 404 privileged user: {UserId}", pu.UserId);
                    notFound.Add(pu);
                }
            }

            if (!valid.Any())
            {
                throw new CommandFailedException(ctx, "cmd-err-choice-none");
            }

            await ctx.PaginateAsync(
                "str-priv",
                valid,
                user => user.ToString(),
                this.ModuleColor,
                10
                );

            LogExt.Information(ctx, "Removing {Count} not found privileged users", notFound.Count);
            await this.Service.RemoveAsync(notFound);
        }
        public static Task GuildAvailableEventHandlerAsync(TheGodfatherBot bot, GuildCreateEventArgs e)
        {
            LogExt.Information(bot.GetId(e.Guild.Id), "Available: {AvailableGuild}", e.Guild);
            GuildConfigService gcs = bot.Services.GetRequiredService <GuildConfigService>();

            return(gcs.IsGuildRegistered(e.Guild.Id) ? Task.CompletedTask : gcs.RegisterGuildAsync(e.Guild.Id));
        }
示例#3
0
 public static Task CommandExecutionEventHandler(TheGodfatherBot bot, CommandExecutionEventArgs e)
 {
     if (e.Command is null || e.Command.QualifiedName.StartsWith("help"))
     {
         return(Task.CompletedTask);
     }
     LogExt.Information(
         bot.GetId(e.Context.Guild?.Id),
         new[] { "Executed: {ExecutedCommand}", "{User}", "{Guild}", "{Channel}" },
         e.Command.QualifiedName, e.Context.User, e.Context.Guild?.ToString() ?? "DM", e.Context.Channel
         );
     return(Task.CompletedTask);
 }
        public static async Task GuildCreateEventHandlerAsync(TheGodfatherBot bot, GuildCreateEventArgs e)
        {
            LogExt.Information(bot.GetId(e.Guild.Id), "Joined {NewGuild}", e.Guild);

            if (bot.Services.GetRequiredService <BlockingService>().IsGuildBlocked(e.Guild.Id))
            {
                LogExt.Information(bot.GetId(e.Guild.Id), "{Guild} is blocked. Leaving...", e.Guild);
                await e.Guild.LeaveAsync();

                return;
            }

            IReadOnlyCollection <DiscordMember> members = await e.Guild.GetAllMembersAsync();

            int botCount = members.Where(m => m.IsBot).Count();

            if (botCount > 25 || (members.Count - botCount < 0))
            {
                LogExt.Information(bot.GetId(e.Guild.Id), "{Guild} is most likely a bot farm. Leaving and blocking...", e.Guild);
                await e.Guild.LeaveAsync();

                await bot.Services.GetRequiredService <BlockingService>().BlockGuildAsync(e.Guild.Id, "Bot farm");

                return;
            }

            await bot.Services.GetRequiredService <GuildConfigService>().RegisterGuildAsync(e.Guild.Id);

            DiscordChannel defChannel = e.Guild.GetDefaultChannel();

            if (!defChannel.PermissionsFor(e.Guild.CurrentMember).HasPermission(Permissions.SendMessages))
            {
                return;
            }

            string prefix = bot.Services.GetRequiredService <BotConfigService>().CurrentConfiguration.Prefix;
            string owners = bot.Client.CurrentApplication.Owners.Select(o => o.ToDiscriminatorString()).Humanize(", ");
            await defChannel.EmbedAsync(
                $"{Formatter.Bold("Thank you for adding me!")}\n\n" +
                $"{Emojis.SmallBlueDiamond} The default prefix for commands is {Formatter.Bold(prefix)}, but it can be changed " +
                $"via {Formatter.Bold("prefix")} command.\n" +
                $"{Emojis.SmallBlueDiamond} I advise you to run the configuration wizard for this guild in order to quickly configure " +
                $"functions like logging, notifications etc. The wizard can be invoked using {Formatter.Bold("config setup")} command.\n" +
                $"{Emojis.SmallBlueDiamond} You can use the {Formatter.Bold("help")} command as a guide, though it is recommended to " +
                $"read the documentation @ https://github.com/ivan-ristovic/the-godfather \n" +
                $"{Emojis.SmallBlueDiamond} If you have any questions or problems, feel free to use the {Formatter.Bold("report")} " +
                $"command in order to send a message to the bot owners ({owners}). Alternatively, you can create an issue on " +
                $"GitHub or join WorldMafia Discord server for quick support (https://worldmafia.net/discord)."
                , Emojis.Wave
                );
        }