Esempio n. 1
0
        public async Task BanAsync(
            [Summary("The user to ban.")] GuildUserProxy user,
            [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason)
        {
            if (user.HasValue)
            {
                await user.GuildUser.TrySendMessageAsync($"You were banned from **{Context.Guild.Name}** because of {reason}.");
            }
            await Context.Guild.AddBanAsync(user.ID, _pruneDays, reason);

            Infraction infraction = Infraction.Create(Moderation.RequestInfractionID())
                                    .WithType(InfractionType.Ban)
                                    .WithModerator(Context.User)
                                    .WithDescription(reason);

            // Normally it would be preferred to use the AddInfraction(IUser, Infraction) method but that one implicitly
            //  sends a DM to the target which will not be in the server anymore at this point AND this method already
            //  attempts to send a DM to the target.
            Moderation.AddInfraction(user.ID, infraction);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithInfractionId(infraction.ID)
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Ban)
                                            .WithTarget(user.ID)
                                            .WithReason(reason), Context.Channel);
        }
Esempio n. 2
0
        public async Task WarnUserAsync(
            [Summary("The user to warn.")] SocketGuildUser user,
            [Summary("The reason to warn the user."), Remainder] string reason)
        {
            UserData data = Data.UserData.GetUser(user.Id);

            EmbedBuilder builder = new EmbedBuilder()
                                   .WithColor(Color.Orange);

            bool   printInfractions    = data != null && data.Infractions?.Count > 0;
            string previousInfractions = null;

            // Collect the previous infractions before applying new ones, otherwise we will also collect this
            //  new infraction when printing them
            if (printInfractions)
            {
                previousInfractions = string.Join('\n', data.Infractions.OrderByDescending(i => i.Time).Select(i => i.ToString()));
            }

            Moderation.AddInfraction(user, Infraction.Create(Moderation.RequestInfractionID())
                                     .WithType(InfractionType.Warning)
                                     .WithModerator(Context.User)
                                     .WithDescription(reason));

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Warn)
                                            .WithReason(reason)
                                            .WithTarget(user)
                                            .WithAdditionalInfo(previousInfractions), Context.Channel);
        }
Esempio n. 3
0
        public async Task KickUser(
            [Summary("The user to kick.")] GuildUserProxy user,
            [Summary("The reason to kick the user for."), Remainder] string reason = DefaultReason)
        {
            if (!user.HasValue)
            {
                throw new ArgumentException($"User with ID {user.ID} is not in the server!");
            }

            await user.GuildUser.KickAsync(reason);

            Infraction infraction = Infraction.Create(Moderation.RequestInfractionID())
                                    .WithType(InfractionType.Kick)
                                    .WithModerator(Context.User)
                                    .WithDescription(reason);

            if (user.HasValue)
            {
                Moderation.AddInfraction(user.GuildUser, infraction);
            }
            else
            {
                Moderation.AddInfraction(user.ID, infraction);
            }


            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithInfractionId(infraction.ID)
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Kick)
                                            .WithReason(reason)
                                            .WithTarget(user), Context.Channel);
        }
Esempio n. 4
0
        public async Task MuteAsync(
            [Summary("The user to mute.")] GuildUserProxy user,
            [Summary("The reason why to mute the user."), Remainder] string reason = DefaultReason)
        {
            if (!user.HasValue)
            {
                throw new ArgumentException($"User with ID {user.ID} is not in the server!");
            }

            await user.GuildUser.MuteAsync(Context);

            SetUserMuted(user.ID, true);

            Infraction infraction = Infraction.Create(Moderation.RequestInfractionID())
                                    .WithType(InfractionType.Mute)
                                    .WithModerator(Context.User)
                                    .WithDescription(reason);

            Moderation.AddInfraction(user.GuildUser, infraction);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithInfractionId(infraction.ID)
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Mute)
                                            .WithTarget(user)
                                            .WithReason(reason), Context.Channel);
        }
Esempio n. 5
0
        public async Task KickUser(
            [Summary("The user to kick.")] SocketGuildUser user,
            [Summary("The reason to kick the user for."), Remainder] string reason = DefaultReason)
        {
            await user.KickAsync(reason);

            Moderation.AddInfraction(user, Infraction.Create(Moderation.RequestInfractionID())
                                     .WithType(InfractionType.Kick)
                                     .WithModerator(Context.User)
                                     .WithDescription(reason));

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Kick)
                                            .WithReason(reason)
                                            .WithTarget(user), Context.Channel);
        }
Esempio n. 6
0
        public async Task MuteAsync(
            [Summary("The user to mute.")] SocketGuildUser user,
            [Summary("The reason why to mute the user."), Remainder] string reason = DefaultReason)
        {
            await user.MuteAsync(Context);

            SetUserMuted(user.Id, true);

            Moderation.AddInfraction(user, Infraction.Create(Moderation.RequestInfractionID())
                                     .WithType(InfractionType.Mute)
                                     .WithModerator(Context.User)
                                     .WithDescription(reason));

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Mute)
                                            .WithTarget(user)
                                            .WithReason(reason), Context.Channel);
        }