Пример #1
0
        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
                );
        }
Пример #2
0
        public static async Task MessageCreateEventHandlerAsync(TheGodfatherBot bot, MessageCreateEventArgs e)
        {
            if (e.Author.IsBot)
            {
                return;
            }

            if (e.Guild is null)
            {
                LogExt.Debug(bot.GetId(null), new[] { "DM message received from {User}:", "{Message}" }, e.Author, e.Message);
                return;
            }

            if (bot.Services.GetRequiredService <BlockingService>().IsBlocked(e.Guild.Id, e.Channel.Id, e.Author.Id))
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(e.Message?.Content))
            {
                return;
            }

            if (!e.Message.Content.StartsWith(bot.Services.GetRequiredService <GuildConfigService>().GetGuildPrefix(e.Guild.Id)))
            {
                short rank = bot.Services.GetRequiredService <UserRanksService>().ChangeXp(e.Guild.Id, e.Author.Id);
                if (rank != 0)
                {
                    LocalizationService ls = bot.Services.GetRequiredService <LocalizationService>();
                    LevelRole?          lr = await bot.Services.GetRequiredService <LevelRoleService>().GetAsync(e.Guild.Id, rank);

                    DiscordRole?levelRole = lr is { } ? e.Guild.GetRole(lr.RoleId) : null;
Пример #3
0
        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));
        }
Пример #4
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 MessageReactionAddedEventHandlerAsync(TheGodfatherBot bot, MessageReactionAddEventArgs e)
        {
            if (e.Guild is null || e.Channel is null || e.Message is null)
            {
                return;
            }

            StarboardService ss = bot.Services.GetRequiredService <StarboardService>();

            if (ss.IsStarboardEnabled(e.Guild.Id, out ulong cid, out string star) && cid != e.Channel.Id && e.Emoji.GetDiscordName() == star)
            {
                LogExt.Debug(bot.GetId(e.Guild.Id), "Reacted with star emoji: Message {MessageId}, {Guild}", e.Message.Id, e.Guild);
                ss.RegisterModifiedMessage(e.Guild.Id, e.Channel.Id, e.Message.Id);
            }

            ReactionRoleService rrs = bot.Services.GetRequiredService <ReactionRoleService>();
            ReactionRole?       rr  = await rrs.GetAsync(e.Guild.Id, e.Emoji.GetDiscordName());

            if (rr is { })
Пример #6
0
        public static async Task GuildMemberJoinEventHandlerAsync(TheGodfatherBot bot, GuildMemberAddEventArgs e)
        {
            if (e.Guild is null)
            {
                return;
            }

            LogExt.Debug(bot.GetId(e.Guild.Id), "Member added: {Member} {Guild}", e.Member, e.Guild);

            GuildConfigService gcs  = bot.Services.GetRequiredService <GuildConfigService>();
            GuildConfig        gcfg = await gcs.GetConfigAsync(e.Guild.Id);

            await Task.Delay(TimeSpan.FromSeconds(gcfg.AntiInstantLeaveSettings.Cooldown + 1));

            if (e.Member.Guild is null)     // User left in meantime
            {
                return;
            }

            // TODO move to service
            DiscordChannel?wchn = e.Guild.GetChannel(gcfg.WelcomeChannelId);

            if (wchn is { })
Пример #7
0
 public static Task GuildUnvailableEventHandlerAsync(TheGodfatherBot bot, GuildDeleteEventArgs e)
 {
     LogExt.Warning(bot.GetId(e.Guild.Id), "Unvailable: {UnvailableGuild}", e.Guild);
     return(Task.CompletedTask);
 }