Beispiel #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);
        }
Beispiel #2
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.");
            }
        }