Example #1
0
        public async Task BanAsync([RequireBotHierarchy("ban")][RequireInvokerHierarchy("ban")] SocketGuildUser user, string prune = null, [Remainder] string reason = null)
        {
            List <Task> cmds = int.TryParse(prune, out int pruneDays)
                ? new List <Task>()
            {
                user.BanAsync(pruneDays, reason)
            }
                : new List <Task>()
            {
                user.BanAsync(0, reason)
            };

            EmbedBuilder embed = new EmbedBuilder()
                                 .WithColor(new Color(130, 0, 0))
                                 .WithDescription($"The communist spy {user.Mention} has been given the ~~ban~~ freedom hammer.");

            EmbedFieldBuilder reasonField = new EmbedFieldBuilder()
                                            .WithIsInline(false)
                                            .WithName("Reason")
                                            .WithValue($"{reason ?? "[none given]"}");

            embed.AddField(reasonField);

            cmds.AddRange(new List <Task>()
            {
                Context.Channel.SendMessageAsync(embed: embed.Build()),
                BanModLog.SendToModLogAsync(Context.User as SocketGuildUser, user, null, reason)
            });
            await Task.WhenAll(cmds);
        }
        public async Task BanUserAsync([Summary("The user who will be banned")] SocketGuildUser target, [Remainder] string reason = "No reason specified")
        {
            Logger.LogInfo($"Banning {target}");

            if (target.IsBot)
            {
                await ReplyAsync($"{Context.User.Mention} You cannot ban a bot");

                return;
            }

            if (target == Context.User)
            {
                await ReplyAsync($"{Context.User.Mention} You cannot ban yourself");

                return;
            }

            bool isHigherRole = IsBotHigherRoleThan(target);

            if (isHigherRole)
            {
                IDMChannel dm = await target.GetOrCreateDMChannelAsync();

                await dm.SendMessageAsync($"You have been banned from {Context.Guild.Name}");

                await target.BanAsync(0, reason);
                await ReplyAsync($"Banned {target.Mention}");
            }
            else
            {
                await ReplyAsync($"Can't ban {target.Mention} with higher role than me");
            }
        }
Example #3
0
        public static async Task PerformAsync(this BlacklistAction action, VolteContext ctx, SocketGuildUser member, string word)
        {
            switch (action)
            {
            case BlacklistAction.Warn:
                await member.WarnAsync(ctx, $"Used blacklisted word \"{word}\".");

                break;

            case BlacklistAction.Kick:
                await member.KickAsync($"Used blacklisted word \"{word}\".");

                break;

            case BlacklistAction.Ban:
                await member.BanAsync(7, $"Used blacklisted word \"{word}\".");

                break;

            case BlacklistAction.Nothing:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(action), action, null);
            }
        }
        public async Task HPly_Rus(SocketGuildUser mention, string num = null)
        {
            String reason = "";
            int    bullet = new Random().Next(0, 7);

            if (Context.User.Username == mention.Username)
            {
                if (bullet == 1)
                {
                    var channel = await mention.GetOrCreateDMChannelAsync();

                    await channel.SendMessageAsync(reason == null?$"You've been banned from {Context.Guild.Name} for losing a game of Russian Roulette." : $"You've been banned from {Context.Guild.Name} for losing a gqame of Russian Roulette.");

                    await Task.Delay(2000);

                    await mention.BanAsync();

                    await ReplyAsync(reason == null?$"{mention.Username} died." : $"{ mention.Username} died");
                }
                else
                {
                    await ReplyAsync(reason == null?$"{mention.Username} has survived" : $"{mention.Username} has survived");
                }
            }
            else
            {
                await ReplyAsync(reason == null?$"{Context.User.Username} you can't shoot someone. Thats illegal." : $"{Context.User.Username} you can't shoot someone. Thats illegal.");
            }
        }
Example #5
0
        public async Task BanAsync(SocketGuildUser User, [Remainder] string Reason = null)
        {
            if (!CommandUtils.HasPermission(Context.Guild.GetUser(Context.User.Id), GuildPermission.BanMembers))
            {
                await ReplyAsync("You are missing the permissions to ban other users.");

                return;
            }

            if (!CommandUtils.HasPermission(Context.Guild.CurrentUser, GuildPermission.BanMembers))
            {
                await ReplyAsync("I am missing the permissions to ban other users.");

                return;
            }

            try {
                await User.BanAsync(reason : Reason);
                await ReplyAsync($"{User.ToString()} has been banned from the server.\n**Reason**: {Reason ?? "None"}");

                Embed modlog = await CommandUtils.CreateModlog(Context.Guild, Context.User, User as SocketUser, CommandUtils.ModlogType.Ban, Reason);

                await Context.Guild.GetTextChannel(FileSystem.GetGuild(Context.Guild).ModlogChannel.Value).SendMessageAsync("", embed: modlog);
            }
            catch (OperationCanceledException e) {
                return;
            }
            catch (Exception e) {
                await ReplyAsync("Something has gone horribly wrong and the dev has been notified.");

                await Context.Client.GetUser(config.AuthorId).SendMessageAsync($"ERROR on message from {Context.User.ToString()}:\n{Context.Message.Content}\nThrew error: {e.Message}");
            }
        }
Example #6
0
        public async Task <ActionResult> BanAsync([CheckHierarchy, EnsureNotSelf, Description("The member to ban.")]
                                                  SocketGuildUser member,
                                                  [Remainder, Description("The reason for the ban.")]
                                                  string reason = "Banned by a Moderator.")
        {
            var e = Context
                    .CreateEmbedBuilder(
                $"You've been banned from {Format.Bold(Context.Guild.Name)} for {Format.Bold(reason)}.")
                    .ApplyConfig(Context.GuildData);

            if (!await member.TrySendMessageAsync(embed: e.Build()))
            {
                Logger.Warn(LogSource.Module, $"encountered a 403 when trying to message {member}!");
            }

            try
            {
                await member.BanAsync(7, reason);

                return(Ok($"Successfully banned **{member}** from this guild.", _ =>
                          ModerationService.OnModActionCompleteAsync(ModActionEventArgs.New
                                                                     .WithDefaultsFromContext(Context)
                                                                     .WithActionType(ModActionType.Ban)
                                                                     .WithTarget(member)
                                                                     .WithReason(reason))
                          ));
            }
            catch
            {
                return(BadRequest(
                           "An error occurred banning that member. Do I have permission; or are they higher than me in the role list?"));
            }
        }
Example #7
0
        public async Task Ban(SocketGuildUser user, int Days = 365, [Remainder] string Message = "An admin determined your services were no longer required.")
        {
            var Me = Context.Guild.CurrentUser;

            if (user.Id == Me.Id)
            {
                await ReplyAsync("Sorry, I do not wish to kick myself. You may ask me to leave though.");
            }
            //Do a permissions check.
            else if (user.Hierarchy > Me.Hierarchy)
            {
                await ReplyAsync($"The target user is a member of a higher role then I am. I cannot ban that user.");
            }
            else
            {
                await user.BanAsync(Days, Message);

                var eb = new EmbedBuilder()
                         .WithTitle("User Banned")
                         .WithColor(Color.Red)
                         .WithDescription($"User {user.Mention} has been banned from this guild by {Context.GuildUser.Mention}.")
                         .AddField("Reason", Message)
                         .AddField("Days", Days);

                await ReplyAsync(embed : eb.Build());
            }
        }
Example #8
0
        public async Task <ActionResult> BanAsync([CheckHierarchy] SocketGuildUser user,
                                                  [Remainder] string reason = "Banned by a Moderator.")
        {
            if (!await user.TrySendMessageAsync(
                    embed: Context.CreateEmbed($"You've been banned from **{Context.Guild.Name}** for **{reason}**.")))
            {
                Logger.Warn(LogSource.Volte,
                            $"encountered a 403 when trying to message {user}!");
            }

            try
            {
                await user.BanAsync(7, reason);

                return(Ok($"Successfully banned **{user}** from this guild.", _ =>
                          ModLogService.DoAsync(ModActionEventArgs.New
                                                .WithDefaultsFromContext(Context)
                                                .WithActionType(ModActionType.Ban)
                                                .WithTarget(user)
                                                .WithReason(reason))
                          ));
            }
            catch
            {
                return(BadRequest("An error occurred banning that user. Do I have permission; or are they higher than me in the role list?"));
            }
        }
Example #9
0
        public async Task <ActionResult> SoftBanAsync(
            [CheckHierarchy, EnsureNotSelf, Description("The member to softban.")]
            SocketGuildUser user, [Description("The amount of days of messages to delete. Defaults to 7.")]
            int daysToDelete = 0,
            [Remainder, Description("The reason for the softban.")]
            string reason = "Softbanned by a Moderator.")
        {
            var e = Context.CreateEmbedBuilder(
                $"You've been softbanned from **{Context.Guild.Name}** for **{reason}**.")
                    .ApplyConfig(Context.GuildData);

            if (!await user.TrySendMessageAsync(embed: e.Build()))
            {
                Logger.Warn(LogSource.Module, $"encountered a 403 when trying to message {user}!");
            }

            try
            {
                await user.BanAsync(daysToDelete == 0? 7 : daysToDelete, reason);

                await Context.Guild.RemoveBanAsync(user);

                return(Ok($"Successfully softbanned **{user.Username}#{user.Discriminator}**.", _ =>
                          ModerationService.OnModActionCompleteAsync(ModActionEventArgs.New
                                                                     .WithDefaultsFromContext(Context)
                                                                     .WithTarget(user)
                                                                     .WithReason(reason))
                          ));
            }
            catch
            {
                return(BadRequest(
                           "An error occurred softbanning that user. Do I have permission; or are they higher than me in the role list?"));
            }
        }
Example #10
0
        public async Task BanUser(SocketGuildUser user, [Remainder] string reason = null)
        {
            var embed = new KaguyaEmbedBuilder();

            reason ??= "<No reason provided>";

            try
            {
                await user.BanAsync(reason : reason);

                if (user.Id != 159985870458322944)
                {
                    embed.Description = $"Successfully banned `{user}` with reason `{reason}`\n";
                }
                else // Easter egg lol
                {
                    embed.Description = $"Successfully banned `{user}` with reason `{reason}`\n" +
                                        $"*Nice choice* <:Kaguya:581581938884608001> 👍";
                }
            }
            catch (Exception)
            {
                embed.Description = $"Failed to ban `{user}`\n";
            }

            await ReplyAsync(embed : embed.Build());
        }
Example #11
0
        public async Task BanAsync(SocketGuildUser User, string Reason = "")
        {
            if (!CommandUtils.HasPermission(Context.Guild.GetUser(Context.User.Id), GuildPermission.BanMembers))
            {
                await ReplyAsync("You are missing the permissions to ban other users.");

                return;
            }

            if (!CommandUtils.HasPermission(Context.Guild.CurrentUser, GuildPermission.BanMembers))
            {
                await ReplyAsync("I am missing the permissions to ban other users.");

                return;
            }

            try {
                await User.BanAsync(reason : Reason);
                await ReplyAsync($"{User.ToString()} has been banned from the server.\n**Reason**: {Reason}");
            }
            catch (Exception e) {
                await ReplyAsync("Something has gone horribly wrong and the dev has been notified.");

                await Context.Client.GetUser(config.AuthorId).SendMessageAsync($"ERROR on message from {Context.User.ToString()}:\n{Context.Message.Content}\nThrew error: {e.Message}");
            }
        }
Example #12
0
        public async Task SoftbanAsync(SocketGuildUser user, [Remainder] string reason)
        {
            var user1     = Context.User as SocketGuildUser;
            var staffRole = user1.Roles.FirstOrDefault(x => x.Name == "Staff");

            if (staffRole != null)
            {
                if (DiscordBot.Instance.currentServer != null)
                {
                    EmbedBuilder builder = new EmbedBuilder();
                    builder.WithTitle($"**{user.Username}#{user.Discriminator} has been soft banned.**").WithColor(Discord.Color.Red);

                    EmbedBuilder builder1 = new EmbedBuilder();
                    builder1.WithTitle($"**You have been kicked from the OEA**").WithDescription($"Reason: {reason}").WithColor(Discord.Color.Red)
                    .WithFooter("If you think this was an error, please contact a moderator.");

                    await user.SendMessageAsync("", false, builder1.Build());

                    await user.BanAsync();

                    await DiscordBot.Instance.currentServer.RemoveBanAsync(user);
                    await ReplyAsync("", false, builder.Build());
                }
                else
                {
                    await ReplyAsync("Please run the setup command before using this command.");
                }
            }
            else
            {
                await ReplyAsync("You do not have permission to use this command.");
            }
        }
Example #13
0
        public async Task <ActionResult> SoftBanAsync([CheckHierarchy] SocketGuildUser user, int daysToDelete,
                                                      [Remainder] string reason = "Softbanned by a Moderator.")
        {
            try
            {
                await Context.CreateEmbed($"You've been softbanned from **{Context.Guild.Name}** for **{reason}**.")
                .SendToAsync(user);
            }
            catch (Discord.Net.HttpException e) when(e.HttpCode == HttpStatusCode.Forbidden)
            {
                Logger.Warn(LogSource.Volte,
                            $"encountered a 403 when trying to message {user}!", e);
            }

            await user.BanAsync(daysToDelete, reason);

            await Context.Guild.RemoveBanAsync(user);

            return(Ok($"Successfully softbanned **{user.Username}#{user.Discriminator}**.", _ =>
                      ModLogService.DoAsync(ModActionEventArgs.New
                                            .WithDefaultsFromContext(Context)
                                            .WithTarget(user)
                                            .WithReason(reason))
                      ));
        }
Example #14
0
        public async Task Ban(SocketGuildUser user, [Remainder] string reason = "")
        {
            await user.BanAsync();

            if (reason == "")
            {
                await ReplyAsync($":white_check_mark: {user.Mention} has been banned.");
            }
            else
            {
                await ReplyAsync($":white_check_mark: {user.Mention} has been banned. | Reason: {reason}");
            }

            EmbedBuilder embed = new EmbedBuilder();

            embed.WithTitle("User Banned");
            embed.WithAuthor(Context.User);
            embed.WithColor(255, 0, 0);
            embed.AddField("User", user);
            embed.WithFooter($"UserID: {user.Id}");
            if (reason != "")
            {
                embed.AddField("Reason", reason);
            }

            SocketTextChannel logChannel = (SocketTextChannel)Constants.IGuilds.Jordan(Context).Channels.First(x => x.Id == Methods.Data.GetChnlId("moderation-log"));
            await logChannel.SendMessageAsync("", false, embed.Build());
        }
Example #15
0
        public async Task <BaseResult> BanUserAsync(
            [Name("Ban Target")][Description("The user to ban.")]
            SocketGuildUser target,
            [Name("Ban Reason")][Description("The audit log reason for the ban.")][DefaultValueDescription("None")]
            string reason = null,
            [Name("Prune Day Count")][Description("The amount of days going back that messages sent from this user will be removed.")]
            int pruneDays = 0)
        {
            if (target.Id == Context.Invoker.Id)
            {
                return(BadRequest("I can't ban you!"));
            }

            if (target.Id == Context.Client.CurrentUser.Id)
            {
                return(BadRequest("I can't ban myself!"));
            }

            try
            {
                await target.BanAsync(pruneDays,
                                      reason != null
                                      ?$"Action performed by {Context.Invoker} (ID {Context.Invoker.Id}) with reason: {reason}"
                                      : $"Action performed by {Context.Invoker} (ID {Context.Invoker.Id}) with no reason");
            }
            catch (HttpException e) when(e.HttpCode == HttpStatusCode.Forbidden)
            {
                return(BadRequest(
                           $"Cannot ban '{target.Nickname ?? target.Username}' because that user is more powerful than me!"));
            }

            return(Ok(
                       $":white_check_mark: Banned '{target.Nickname ?? target.Username}'{(reason != null ? " with reason '" + reason + "'" : "")}. {(pruneDays != 0 ? $"Removing {pruneDays} worth of messages from them." : "")}"));
        }
Example #16
0
        /// <summary>
        /// Method to "silently" ban a user. This method is only called by the WarnHandler class.
        /// </summary>
        /// <param name="user">The user to ban.</param>
        /// <param name="reason">The reason for banning the user.</param>
        /// <returns></returns>
        public async Task AutoBanUserAsync(SocketGuildUser user, string reason)
        {
            // Not try-catched as the exception is handled elsewhere.
            await user.BanAsync(0, reason);

            await ConsoleLogger.LogAsync($"User auto-banned. Guild: [Name: {user.Guild.Name} | ID: {user.Guild.Id}] " +
                                         $"User: [Name: {user} | ID: {user.Id}]", LogLvl.DEBUG);
        }
Example #17
0
        public async Task BanUser(SocketGuildUser user)
        {
            await user.BanAsync();

            await Context.Guild.AddBanAsync(user);

            await Context.Channel.SendMessageAsync($"The user {user} has been banned by {Context.User.Username}. Next time follow those damn rules");
        }
Example #18
0
        public async Task TempBanAsync([RequireBotHierarchy("tempban")][RequireInvokerHierarchy("tempban")] SocketGuildUser user, string length, string prune = null, [Remainder] string reason = null)
        {
            if (!double.TryParse(length, out double days))
            {
                await Context.Channel.SendMessageAsync($"Unfortunately, {length} is not a valid prison sentence length.");

                return;
            }

            List <Task> cmds = int.TryParse(prune, out int pruneDays)
                ? new List <Task>()
            {
                user.BanAsync(pruneDays, reason)
            }
                : new List <Task>()
            {
                user.BanAsync(0, reason)
            };

            EmbedBuilder embed = new EmbedBuilder()
                                 .WithColor(new Color(130, 0, 0))
                                 .WithDescription($"The communist spy {user.Mention} has been sent to Brazil for {length} {(days == 1 ? "day" : "days")}.");

            EmbedFieldBuilder reasonField = new EmbedFieldBuilder()
                                            .WithIsInline(false)
                                            .WithName("Reason")
                                            .WithValue($"{reason ?? "[none given]"}");

            embed.AddField(reasonField);

            cmds.AddRange(new List <Task>()
            {
                Context.Channel.SendMessageAsync(embed: embed.Build()),
                BanModLog.SendToModLogAsync(Context.User as SocketGuildUser, user, length, reason)
            });
            await Task.WhenAll(cmds);

            await Task.Delay((int)(days * 24 * 60 * 60 * 1000));

            await Task.WhenAll
            (
                Context.Guild.RemoveBanAsync(user),
                UnbanModLog.SendToModLogAsync(Context.Guild.CurrentUser, user)
            );
        }
Example #19
0
        public async Task BanCommand(
            [Name("User")][Summary("The user you wish to ban.")] SocketGuildUser user,
            [Name("Reason")][Summary("The reason you are banning the user.")] string reason)
        {
            await user.BanAsync(pruneDays : 7, reason : reason);

            await ReplyAsync($"{user.Mention} has been banned for: {reason}.\n" +
                             $"User Banned by {Context.User.Mention}.");
        }
Example #20
0
        public async Task SoftBanCommand(
            [Name("User")][Summary("The user you wish to soft ban.")] SocketGuildUser user)
        {
            await user.BanAsync(pruneDays : 7);

            await ReplyAsync($"{user.Mention} has been soft banned. 7 Days of messages pruned.");

            await Context.Guild.RemoveBanAsync(user);
        }
Example #21
0
        public async Task BanUser([Name("User")][RequireHierarchy] SocketGuildUser user,
                                  [Name("Reason")] params string[] reason)
        {
            string reasonJoined = (reason != null ? string.Join(' ', reason) : null) !;
            await user.BanAsync(reason : reasonJoined);

            await ReplyAsync($"{user} is now b& :thumbsup:");

            //Bans will automatically logged
        }
Example #22
0
        public async Task Ban([Remainder] SocketGuildUser user)
        {
            await Context.Channel.TriggerTypingAsync();

            await user.BanAsync();

            await Context.Channel.SendSuccessAsync("Banned", $"{user.Mention} was banned by {Context.User.Mention}!");

            await _serverHelper.SendLogAsync(Context.Guild, "Situation Log", $"{user.Mention} was banned by {Context.User.Mention}!");
        }
Example #23
0
        private async Task <bool> ProcessAutoban(SocketGuildUser guildUser)
        {
            var settings = await _settings.Read <AdministrationSettings>(guildUser.Guild.Id, false);

            if (settings == null)
            {
                return(false);
            }

            if (settings.AutobanUsernameRegex == default || settings.AutobanLogChannelId == default)
            {
                return(false);
            }

            var logger      = _logger.WithScope(guildUser);
            var currentUser = guildUser.Guild.CurrentUser;

            if (!currentUser.GuildPermissions.BanMembers)
            {
                logger.LogInformation("Missing permissions to process autoban");
                return(false);
            }

            var channel = guildUser.Guild.GetTextChannel(settings.AutobanLogChannelId);

            if (channel == null || !currentUser.GetPermissions(channel).SendMessages)
            {
                logger.LogInformation("Can't log autobans");
                return(false);
            }

            try
            {
                if (!Regex.IsMatch(guildUser.Username, settings.AutobanUsernameRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(200)))
                {
                    return(false);
                }
            }
            catch (RegexMatchTimeoutException ex)
            {
                logger.LogWarning(ex, "Failed to process autoban because of regex timeout");
                return(false);
            }

            await guildUser.BanAsync(1, "autobanned");

            var embed = new EmbedBuilder()
                        .WithFooter($"ID: {guildUser.Id}")
                        .WithDescription($"**Autobanned user {guildUser.Mention}:**\n Username `{guildUser.Username}` matches the autoban rule.").WithColor(Color.Red);

            await channel.SendMessageAsync("", embed : embed.Build());

            logger.LogInformation("Autobanned user");
            return(true);
        }
        public async Task BanAsync(SocketGuildUser user, [Remainder] string reason = "None")
        {
            EmbedBuilder embed = new EmbedBuilder
            {
                Title       = $"Banned {user.Username}#{user.DiscriminatorValue}",
                Description = $"Reason: {reason}"
            };
            await user.BanAsync(14, reason);

            await ReplyAsync("", false, embed.Build());
        }
Example #25
0
        private async Task ExecuteAction(MessageContext context, ModerationPunishment action, string reason, SocketGuildUser user = null)
        {
            user ??= context.socketServerUser ?? throw new ArgumentNullException($"Both {nameof(user)} and {nameof(context)}.{nameof(MessageContext.socketServerUser)} are null.");

            var embedBuilder = MopBot.GetEmbedBuilder(user.Guild)
                               .WithAuthor(user)
                               .WithDescription($"**Reason:** `{reason}`");

            bool RequirePermission(DiscordPermission discordPermission)
            {
                if (!context.server.CurrentUser.HasChannelPermission(context.socketServerChannel, DiscordPermission.BanMembers))
                {
                    action = ModerationPunishment.Announce;

                    embedBuilder.Title = $"{embedBuilder.Title}\r\n**Attempted to execute action '{action}', but the following permission was missing: `{DiscordPermission.BanMembers}`.";

                    return(false);
                }

                return(true);
            }

            switch (action)
            {
            case ModerationPunishment.Kick:
                if (RequirePermission(DiscordPermission.KickMembers))
                {
                    await user.KickAsync(reason : reason);

                    embedBuilder.Title = "User auto-kicked";
                }

                break;

            case ModerationPunishment.Ban:
                if (RequirePermission(DiscordPermission.KickMembers))
                {
                    await user.BanAsync(reason : reason);

                    embedBuilder.Title = "User auto-banned";
                }

                break;
            }

            if (action == ModerationPunishment.Announce)
            {
                embedBuilder.Title = "User violation detected";
            }

            var data = context.server.GetMemory().GetData <AutoModerationSystem, AutoModerationServerData>();

            await context.socketTextChannel.SendMessageAsync(data.announcementPrefix, embed : embedBuilder.Build());
        }
Example #26
0
 public async Task Ban(SocketGuildUser user, string reason = null)
 {
     try
     {
         await user.BanAsync(0, reason);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         await ReplyAsync("An unexpected error occurred");
     }
 }
Example #27
0
        public async Task BaneMember(SocketGuildUser user)
        {
            await user.BanAsync();

            var banMsg = await ReplyAsync($"{user.Username} has been banned.");

            await Task.Delay(5000);

            await banMsg.DeleteAsync();

            await Context.Message.DeleteAsync();
        }
Example #28
0
        public async Task <ActionResult> UnixBanAsync([CheckHierarchy, EnsureNotSelf, Description("The member to ban.")]
                                                      SocketGuildUser member,
                                                      [Remainder, Description("The modifications to the ban action you'd like to make.")]
                                                      Dictionary <string, string> modifications)
        {
            var daysToDelete = (modifications.TryGetValue("days", out var result) ||
                                modifications.TryGetValue("deleteDays", out result)) &&
                               int.TryParse(result, out var intResult)
                ? intResult
                : 0;

            var reason = modifications.TryGetValue("reason", out result) ? result : "Banned by a Moderator.";

            var e = Context
                    .CreateEmbedBuilder(
                $"You've been banned from {Format.Bold(Context.Guild.Name)} for {Format.Bold(reason)}.");

            if (!Context.GuildData.Configuration.Moderation.ShowResponsibleModerator ||
                modifications.TryGetValue("shadow", out _))
            {
                e = e.WithAuthor(author: null).WithSuccessColor();
            }

            if (!await member.TrySendMessageAsync(embed: e.Build()))
            {
                Logger.Warn(LogSource.Module, $"encountered a 403 when trying to message {member}!");
            }

            try
            {
                await member.BanAsync(daysToDelete, reason);

                if (modifications.TryGetValue("soft", out _) || modifications.TryGetValue("softly", out _))
                {
                    await Context.Guild.RemoveBanAsync(member.Id);
                }

                return(Ok($"Successfully banned **{member}** from this guild.", _ =>
                          ModerationService.OnModActionCompleteAsync(ModActionEventArgs.New
                                                                     .WithDefaultsFromContext(Context)
                                                                     .WithActionType(ModActionType.Ban)
                                                                     .WithTarget(member)
                                                                     .WithReason(reason))
                          ));
            }
            catch
            {
                return(BadRequest(
                           "An error occurred banning that member. Do I have permission; or are they higher than me in the role list?"));
            }
        }
Example #29
0
        public async Task <CommandResult> TempBanAsync([RequireHigherHierarchy, RequireHigherBotHierarchy] SocketGuildUser u, TimeSpan time, [Remainder] string reason = null)
        {
            await u.BanAsync(0, reason);

            try
            {
                await _databaseService.CreateNewCaseAsync(Context.Guild, reason, ActionType.TempBan, (int)time.TotalSeconds, Context.User, u);
            }
            catch (InvalidOperationException ex)
            {
                return(new QuiccbanFailResult(ex.Message));
            }
            return(new QuiccbanSuccessResult(string.Format(_responseService.Get("tempban_success"), u.ToString(), u.Mention, time.Humanize(4))));
        }
Example #30
0
        public async Task Ban([Remainder] string command)
        {
            SocketGuildUser user = Helpers.extractUser(Context, command);

            if (user == null)
            {
                await ReplyAsync("User not found!\n+ban [user]");
            }
            else
            {
                await user.BanAsync();
            }

            await ReplyAsync(user.Username + "#" + user.DiscriminatorValue + " has been banned! ID: " + user.Id);
        }