示例#1
0
        private async Task <WarningState> ApplyWarningWithSeverity(IUser user, Warning[] history, Warning warning,
                                                                   Embed tempEmbed)
        {
            var state = WarningState.FromDatabase(history);

            warning.Amount = await RequestSeverity(user, history,
                                                   AddWarningsToEmbed(tempEmbed.ToEmbedBuilder(), state).Build());

            if (history.Contains(warning))
            {
                state = WarningState.FromDatabase(history);
            }
            else
            {
                state.Add(warning.Amount, warning.IssueDate);
            }

            if (state.MutedUntil.HasValue)
            {
                await MuteWatcher.MuteUser(
                    new Mute
                {
                    UserId     = user.Id,
                    IssuerId   = Context.Client.GetGuild(DiscordSettings.GuildId).CurrentUser.Id,
                    IssueDate  = DateTime.UtcNow,
                    ExpiryDate = state.MutedUntil.Value.UtcDateTime
                }, "You got a strike!", true, true);
            }
            else
            {
                await MuteWatcher.UnmuteUser(user.Id, Context.Client.GetGuild(DiscordSettings.GuildId).CurrentUser.Id);
            }

            return(state);
        }
示例#2
0
        private async Task RemoveWarningInternalAsync(IUser user, long id, string reason, bool force)
        {
            var warning = await Database.UNSAFE_GetWarningAsync(id);

            if (warning == null)
            {
                throw new Exception("Invalid warning ID.");
            }

            if (warning.UserId != user.Id) // this check exists to catch typos in warning IDs
            {
                throw new Exception("Warning ID does not match with user!");
            }

            if (warning.IssuerId != Context.User.Id && !force)
            {
                throw new Exception("Warning can only be deleted by its issuer, " +
                                    MentionUtils.MentionUser(warning.IssuerId) + ".");
            }

            await Database.UNSAFE_RemoveWarningAsync(id, Context.Message, reason);

            var state = WarningState.FromDatabase(await Database.UNSAFE_GetWarningsAsync(user.Id));
            var embed = AddWarningsToEmbed(GetWarningEmbed(user, warning), state)
                        .WithDescription("**A warning was deleted.**")
                        .Build();

            await AnnounceWarningEverywhereAsync(user, embed);
        }
示例#3
0
        public async Task UnmuteUser(IUser user, bool force)
        {
            var mute = await Database.UNSAFE_GetMute(user.Id);

            if (mute == null)
            {
                throw new Exception("User is currently not muted.");
            }

            if (mute.IssuerId != Context.User.Id && !force)
            {
                throw new Exception("Mute can only be removed by its issuer, " +
                                    MentionUtils.MentionUser(mute.IssuerId) + ".");
            }

            var state = WarningState.FromDatabase(await Database.UNSAFE_GetWarningsAsync(user.Id));

            if (!state.MutedUntil.HasValue)
            {
                await MuteWatcher.UnmuteUser(user.Id, null);
                await ReplyAsync($"{MentionUtils.MentionUser(user.Id)} unmuted.");
            }
            else if (state.MutedUntil.Value < mute.ExpiryDate)
            {
                var res = await MuteUser(Context.Client.CurrentUser, user, state.MutedUntil.Value, "Mute shortened.",
                                         true, false);
                await ReplyAsync($"{MentionUtils.MentionUser(user.Id)} muted until {res.ExpiryDate}. " +
                                 "A reduction of the mute duration beyond this point is not possible due to an active auto-mute from the warnings system.");
            }
            else
            {
                await ReplyAsync($"{MentionUtils.MentionUser(user.Id)} muted until {mute.ExpiryDate}. " +
                                 "A reduction of the mute duration beyond this point is not possible due to an active auto-mute from the warnings system.");
            }
        }
示例#4
0
        public async Task WarnStats(IUser user = null)
        {
            if (user == null)
            {
                user = Context.User;
            }

            var state = WarningState.FromDatabase(await Database.UNSAFE_GetWarningsAsync(user.Id));
            var embed = AddWarningsToEmbed(new EmbedBuilder().WithAuthor(user), state).Build();

            await ReplyAsync(embed : embed);
        }