コード例 #1
0
        public async Task ProcessMessage(MessageCreateEventArgs e, GuildSettings guildSettings, ServerReplayLoader replayLoader)
        {
            try
            {
                replayLoader.ErrorMessage ??= await replayLoader.Load(Api, ReplayDb, BeatmapDb);

                if (replayLoader.Loaded)
                {
                    DiscordMessage message      = null;
                    MissAnalyzer   missAnalyzer = new MissAnalyzer(replayLoader);
                    if (missAnalyzer.MissCount == 0)
                    {
                        replayLoader.ErrorMessage = "No misses found.";
                    }
                    else if (replayLoader.Source == Source.BOT && guildSettings.Compact)
                    {
                        message = e.Message;
                        await SendReactions(message, missAnalyzer.MissCount);
                    }
                    else if (missAnalyzer.MissCount == 1)
                    {
                        string miss = await SendMissMessage(missAnalyzer, 0);

                        Logger.Log(Logging.MessageCreated);
                        await e.Message.RespondAsync(miss);
                    }
                    else if (missAnalyzer.MissCount > 1)
                    {
                        Logger.Log(Logging.MessageCreated);
                        message = await e.Message.RespondAsync($"Found **{missAnalyzer.MissCount}** misses");
                        await SendReactions(message, missAnalyzer.MissCount);
                    }
                    if (message != null)
                    {
                        CachedMisses[message] = new SavedMiss(missAnalyzer);
                        Logger.LogAbsolute(Logging.CachedMessages, CachedMisses.Count);
                    }
                }
            }
            catch (ArgumentException ex)
            {
                replayLoader.ErrorMessage = ex.Message;
            }

            if (replayLoader.ErrorMessage != null && (replayLoader.Source == Source.USER || replayLoader.Source == Source.ATTACHMENT))
            {
                Logger.Log(Logging.MessageCreated);
                Logger.Log(Logging.ErrorHandled);
                Logger.WriteLine($"Error handled: {replayLoader.ErrorMessage}");
                await e.Message.RespondAsync(replayLoader.ErrorMessage);
            }
        }
コード例 #2
0
        public async Task CreateResponse(DiscordClient discord, Response res, ServerReplayLoader replayLoader)
        {
            try
            {
                replayLoader.ErrorMessage ??= await replayLoader.Load(res.GuildSettings, Api, ReplayDb, BeatmapDb);

                if (replayLoader.Loaded)
                {
                    MissAnalyzer missAnalyzer = new MissAnalyzer(replayLoader);
                    res.Miss = new SavedMiss(discord, missAnalyzer);
                    if (missAnalyzer.MissCount == 0)
                    {
                        replayLoader.ErrorMessage = "No misses found.";
                    }
                    else
                    {
                        UpdateCache(res, await res.CreateResponse());
                    }
                }
            }
            catch (ArgumentException ex)
            {
                replayLoader.ErrorMessage = ex.Message;
            }
            catch (Exception exc)
            {
                await Logger.LogException(exc, Logger.LogLevel.NORMAL);
            }

            if (replayLoader.ErrorMessage != null && (replayLoader.Source == Source.USER || replayLoader.Source == Source.ATTACHMENT))
            {
                Logger.Log(Logging.MessageCreated);
                Logger.Log(Logging.ErrorHandled);
                await Logger.WriteLine($"Error handled: {replayLoader.ErrorMessage}");

                await res.CreateErrorResponse(replayLoader.ErrorMessage);
            }
        }