Esempio n. 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);
        }
Esempio n. 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.");
            }
        }
Esempio n. 3
0
        private static async Task Main()
        {
            var client = await DiscordSettings.GetClient();

            var services = DiscordSettings.ConfigureServices(client);
            await DiscordSettings.InstallCommands(client, services);

            SocialScoreWatcher.Bind(client);
            CoronaWatcher.Bind(client);
            MuteWatcher.Bind(client);
            VoiceChat.Bind(client);
            GovernanceVoteWatcher.Bind(client);
            EditWatcher.Bind(client);
            QuickReportWatcher.Bind(client);
            StarboardWatcher.Bind(client);
            QuickChatWatcher.Bind(client);
            SlurWatcher.Bind(client);

            await Task.Delay(10000);

            var crawler = new Crawler(client);

            await Task.WhenAny(Task.Delay(TimeSpan.FromDays(2)), crawler.StartAsync());

            throw new Exception("Restart me!");
        }
Esempio n. 4
0
 public static Task <Mute> MuteUser(IUser issuer, IUser user, DateTimeOffset expiry, string reason, bool shorten,
                                    bool sameAuthorShorten)
 {
     return(MuteWatcher.MuteUser(
                new Mute
     {
         UserId = user.Id,
         IssuerId = issuer.Id,
         ExpiryDate = expiry.UtcDateTime,
         IssueDate = DateTime.UtcNow
     }, reason, shorten, sameAuthorShorten));
 }