Esempio n. 1
0
        /// <summary>Kick specified user from the server with reason.
        /// </summary>
        public async Task <Embed> KickAsync(IUser user, string reason, SocketCommandContext context)
        {
            await SendPunishmentDm(user, ModerationFormats.DmPunishmentEmbed("You have been kicked!",
                                                                             $"You have been kicked from {context.Guild.Name}", context.Guild));

            await((IGuildUser)user).KickAsync(reason);

            var caseId = await GenerateModCaseId(context.Guild.Id);

            //Create mod case
            var modCase = new ModCase(context, user, caseId, PunishmentType.Kick, reason);
            await _botContext.ModCases.AddAsync(modCase);

            await _botContext.SaveChangesAsync();

            await SendModLog(context.Guild, modCase);

            return(ModerationFormats.CreateModerationEmbed(user, $"{user} kicked", $"{user} was kicked from the server for: {reason ?? "_No reason_"}.", Color.DarkGrey));
        }
Esempio n. 2
0
        /// <summary>
        ///     Ban specified user from the server with reason.
        /// </summary>
        public async Task <Embed> BanAsync(IUser user, int pruneDays, string reason, SocketCommandContext context)
        {
            await context.Message.DeleteAsync();

            if (pruneDays < 0 || pruneDays > 7)
            {
                return(CustomFormats.CreateErrorEmbed("Prune days must be between 0 and 7"));
            }

            //Check if user is already banned
            var isBanned = await context.Guild.GetBanAsync(user);

            if (isBanned != null)
            {
                return(CustomFormats.CreateErrorEmbed($"{user.Username} is already banned!"));
            }

            await SendPunishmentDm(user, ModerationFormats.DmPunishmentEmbed("You have been banned!",
                                                                             $"You have been permanently banned from {context.Guild.Name}", context.Guild));

            _banCache.Set(user.Id, new CacheModel(context.Guild.Id), TimeSpan.FromSeconds(5));

            //Ban user
            await context.Guild.AddBanAsync(user, pruneDays, reason);

            var caseId = await GenerateModCaseId(context.Guild.Id);

            //Create modCase
            var modCase = new ModCase(context.User, context.Guild.Id, user, caseId, PunishmentType.Ban, reason);
            await _botContext.ModCases.AddAsync(modCase);

            await _botContext.SaveChangesAsync();

            await SendModLog(context.Guild, modCase);

            return(ModerationFormats.CreateModerationEmbed(user, $"{user} banned",
                                                           $"{user} was banned from the server for: {reason ?? "_No reason_"}.", Color.DarkGrey));
        }