Example #1
0
        public async Task PermaBan([Summary("The user to ban")] SocketGuildUser user,
                                   [Summary("Reason for ban")] string reason,
                                   [Summary("Number of days for which to prune the user's messages")] int pruneDays = 0)
        {
            var author             = Context.User as SocketGuildUser;
            var authorsHighestRole = author.Roles.OrderByDescending(x => x.Position).First();
            var usersHighestRole   = user.Roles.OrderByDescending(x => x.Position).First();

            if (usersHighestRole.Position >= authorsHighestRole.Position)
            {
                await ReplyAsync(":x: You cannot ban someone above or equal to you in the role hierarchy.");

                return;
            }

            if (_service.PermaBanMessage != null && _service.UnmuteMessage != "")
            {
                var dmChannel = await user.GetOrCreateDMChannelAsync();

                await dmChannel.SendMessageAsync(_service.PermaBanMessage.Replace("{g}", user.Guild.Name)
                                                 .Replace("{r}", reason));
            }

            await Context.Guild.AddBanAsync(user, pruneDays);

            var name = user.Nickname == null
                ? user.Username
                : $"{user.Username} (nickname: {user.Nickname})";
            await _records.AddPermaBanAsync(new PermaBan
            {
                GuildId     = Context.Guild.Id,
                SubjectId   = user.Id,
                SubjectName = user.Username,
                ModeratorId = Context.User.Id,
                Timestamp   = DateTime.UtcNow,
                Reason      = reason
            });

            _records.DisposeContext();
            await _log.LogModMessageAsync($"**{author.Nickname ?? author.Username}** permabanned **{name} ({user.Id})** for `{reason}`");

            await ReplyAsync(":ok:");
        }