Exemplo 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);
        }
        public async Task ClearInfractionsAsync(
            [Summary("The user to clear the infractions from.")] GuildUserProxy user)
        {
            ulong userId = user.HasValue ? user.GuildUser.Id : user.ID;

            int clearedInfractions = Moderation.ClearInfractions(userId);

            EmbedBuilder builder = GetDefaultBuilder()
                                   .WithColor(Color.Green);

            if (user.HasValue)
            {
                builder.WithDescription($"**{clearedInfractions}** infraction(s) were cleared from {user.GuildUser}.");
            }
            else
            {
                builder.WithDescription($"**{clearedInfractions}** infraction(s) were cleared from {userId}.");
            }

            await builder.Build()
            .SendToChannel(Context.Channel);

            if (clearedInfractions > 0)
            {
                await ModerationLog.CreateEntry(ModerationLogEntry.New
                                                .WithDefaultsFromContext(Context)
                                                .WithActionType(ModerationActionType.ClearInfractions)
                                                .WithTarget(userId));
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public async Task TempmuteAsync(
            [Summary("The user to mute.")] GuildUserProxy user,
            [Summary("The duration for the mute."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration,
            [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!");
            }

            bool   unlimitedTime         = (Context.User as IGuildUser).GetPermissionLevel(Data.Configuration) >= PermissionLevel.Moderator;
            double givenDuration         = duration.TotalMilliseconds;
            int    maxHelperMuteDuration = Data.Configuration.HelperMuteMaxDuration;

            if (!unlimitedTime && givenDuration > maxHelperMuteDuration)
            {
                duration = TimeSpan.FromMilliseconds(maxHelperMuteDuration);
            }

            await user.GuildUser.MuteAsync(Context);

            SetUserMuted(user.ID, true);

            Infraction infraction = Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempMute, user.GuildUser, Context.User, duration, reason);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithInfractionId(infraction.ID)
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.TempMute)
                                            .WithTarget(user)
                                            .WithDuration(duration)
                                            .WithReason(reason), Context.Channel);
        }
Exemplo n.º 7
0
        public async Task ClearMessagesAsync(
            [Summary("The user to clear messages of")] SocketGuildUser user,
            [Summary("The amount of messages to clear")] int count,
            [Summary("The history length to delete from")] int history = 100)
        {
            int maxHistory = Context.Configuration.ClearMessageMaxHistory;

            if (history > maxHistory)
            {
                history = maxHistory;
            }

            var aMessages = await Context.Channel.GetMessagesAsync(history).FlattenAsync();

            var fMessages = aMessages.Where(m => m.Author.Id == user.Id)
                            .Where(m => (DateTimeOffset.Now - m.CreatedAt).Days < 14);

            if (fMessages.Count() > 0)
            {
                var messages = fMessages.Take(count);
                await(Context.Channel as ITextChannel).DeleteMessagesAsync(messages);

                await ModerationLog.CreateEntry(ModerationLogEntry.New
                                                .WithDefaultsFromContext(Context)
                                                .WithReason($"Deleted {messages.Count()} message(s) of {user.Mention}")
                                                .WithActionType(ModerationActionType.ClearMessages)
                                                .WithChannel(Context.Channel as ITextChannel));
            }
        }
Exemplo n.º 8
0
        public async Task UnbanAsync(
            [Summary("The user ID to unban.")] GuildUserProxy user)
        {
            await Context.Guild.RemoveBanAsync(user.ID);

            Moderation.ClearTemporaryInfraction(TemporaryInfractionType.TempBan, user.ID);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Unban)
                                            .WithTarget(user.ID), Context.Channel);
        }
Exemplo n.º 9
0
        public async Task UnmuteAsync(
            [Summary("The user to unmute.")] SocketGuildUser user)
        {
            await user.UnmuteAsync(Context);

            SetUserMuted(user.Id, false);

            Moderation.ClearTemporaryInfraction(TemporaryInfractionType.TempMute, user);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Unmute)
                                            .WithTarget(user), Context.Channel);
        }
Exemplo n.º 10
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);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Ban)
                                            .WithTarget(user.ID)
                                            .WithReason(reason), Context.Channel);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public async Task BanAsync(
            [Summary("The user to ban")] GuildUserProxy user,
            [Summary("The duration for the ban."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration,
            [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason)
        {
            // Since the user cannot be found (we are using the GuildUserProxy) we don't need to attempt to message him
            await Context.Guild.AddBanAsync(user.ID, _pruneDays, reason);

            Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempBan, user.ID, Context.User, duration, reason);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.TempBan)
                                            .WithTarget(user.ID)
                                            .WithDuration(duration)
                                            .WithReason(reason), Context.Channel);
        }
Exemplo n.º 13
0
        public async Task TempmuteAsync(
            [Summary("The user to mute.")] SocketGuildUser user,
            [Summary("The duration for the mute."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration,
            [Summary("The reason why to mute the user."), Remainder] string reason = DefaultReason)
        {
            await user.MuteAsync(Context);

            SetUserMuted(user.Id, true);

            Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempMute, user, Context.User, duration, reason);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.TempMute)
                                            .WithTarget(user)
                                            .WithDuration(duration)
                                            .WithReason(reason), Context.Channel);
        }
Exemplo n.º 14
0
        public async Task TempbanAsync(
            [Summary("The user to temporarily ban.")] SocketGuildUser user,
            [Summary("The duration for the ban."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration,
            [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason)
        {
            await user.TrySendMessageAsync($"You were banned from **{Context.Guild.Name}** for {duration.Humanize(7)} because of **{reason}**.");

            await user.BanAsync(_pruneDays, reason);

            Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempBan, user, Context.User, duration, reason);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.TempBan)
                                            .WithTarget(user)
                                            .WithDuration(duration)
                                            .WithReason(reason), Context.Channel);
        }
Exemplo n.º 15
0
        public async Task ClearMessagesAsync(
            [Summary("The amount of messages to clear")] int count)
        {
            int maxHistory = Context.Configuration.ClearMessageMaxHistory;

            count = count + 1 > maxHistory ? maxHistory : count + 1;

            var messages = await Context.Channel.GetMessagesAsync(count).FlattenAsync();

            var validMessages = messages.Where(m => (DateTimeOffset.Now - m.CreatedAt).Days < 14);

            await(Context.Channel as ITextChannel).DeleteMessagesAsync(validMessages);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.ClearMessages)
                                            .WithChannel(Context.Channel as ITextChannel));
        }
Exemplo n.º 16
0
        public async Task ClearInfractionsAsync(
            [Summary("The user to clear the infractions from.")] SocketGuildUser user)
        {
            int clearedInfractions = Moderation.ClearInfractions(user);

            await GetDefaultBuilder()
            .WithDescription($"{clearedInfractions} infraction(s) were cleared from {user.Mention}.")
            .Build()
            .SendToChannel(Context.Channel);

            if (clearedInfractions > 0)
            {
                await ModerationLog.CreateEntry(ModerationLogEntry.New
                                                .WithDefaultsFromContext(Context)
                                                .WithActionType(ModerationActionType.ClearInfractions)
                                                .WithTarget(user));
            }
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        public async Task UnmuteAsync(
            [Summary("The user to unmute.")] GuildUserProxy user)
        {
            if (!user.HasValue)
            {
                throw new ArgumentException($"User with ID {user.ID} is not in the server!");
            }

            await user.GuildUser.UnmuteAsync(Context);

            SetUserMuted(user.ID, false);

            Moderation.ClearTemporaryInfraction(TemporaryInfractionType.TempMute, user.GuildUser);

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithActionType(ModerationActionType.Unmute)
                                            .WithTarget(user), Context.Channel);
        }
Exemplo n.º 19
0
        private async Task SetLockdown(bool lockdown = false)
        {
            IRole            everyone       = Context.Guild.EveryoneRole;
            GuildPermissions newPermissions = everyone.Permissions.Modify(sendMessages: !lockdown);

            await everyone.ModifyAsync(x => x.Permissions = newPermissions);

            string message = $"Lockdown {(lockdown ? "enabled" : "disabled")}!";

            await ModerationLog.CreateEntry(ModerationLogEntry.New
                                            .WithDefaultsFromContext(Context)
                                            .WithReason(message)
                                            .WithActionType(ModerationActionType.Lockdown));

            await new EmbedBuilder()
            .WithColor(Color.DarkGreen)
            .WithDescription(message)
            .Build()
            .SendToChannel(Context.Channel);
        }
Exemplo n.º 20
0
        public async Task SlowModeAsync(
            [Summary("The duration of slowmode"), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration)
        {
            EmbedBuilder builder          = new EmbedBuilder();
            int          slowmodeDuration = (int)duration.TotalSeconds;

            if (slowmodeDuration > _maxSlowMode || slowmodeDuration < 0)
            {
                builder.WithColor(Color.Red)
                .WithDescription($"Duration ({duration.Humanize(3)}) out of bounds (0 - {_maxSlowMode / 3600} hours)!");
            }
            else
            {
                builder.WithColor(Color.Green);

                if (slowmodeDuration == 0)
                {
                    builder.WithDescription($"Slowmode is turned off!");
                }
                else
                {
                    builder.WithDescription($"Slowmode is set to {duration.Humanize(3)}!");
                }

                ITextChannel channel = await Context.Guild.GetTextChannelAsync(Context.Channel.Id);

                await channel.ModifyAsync(x => x.SlowModeInterval = slowmodeDuration);

                await ModerationLog.CreateEntry(ModerationLogEntry.New
                                                .WithDefaultsFromContext(Context)
                                                .WithActionType(ModerationActionType.SlowMode)
                                                .WithDuration(duration));
            }

            await builder.Build().SendToChannel(Context.Channel);
        }