예제 #1
0
        public async Task ProcessReaction(MessageReactionAddEventArgs e, GuildSettings guildSettings, SavedMiss savedMiss, int index)
        {
            var analyzer = savedMiss.MissAnalyzer;

            Logger.Log(Logging.ReactionCalls);
            if (savedMiss.MissUrls[index] == null)
            {
                savedMiss.MissUrls[index] = await SendMissMessage(analyzer, index);
            }
            var message = e.Message;

            if (!message.Author.IsCurrent)
            {
                message = savedMiss.Response;
                if (message == null)
                {
                    var response = await e.Message.RespondAsync(savedMiss.MissUrls[index]);

                    Logger.Log(Logging.MessageCreated);
                    savedMiss.Response = response;
                    if (!guildSettings.Compact)
                    {
                        CachedMisses[response] = savedMiss;
                        await SendReactions(response, analyzer.MissCount);
                    }
                }
            }
            if (message != null)
            {
                Logger.Log(Logging.MessageEdited);
                await message.ModifyAsync(savedMiss.MissUrls[index]);
            }
        }
예제 #2
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);
            }
        }