public SavedMiss(DiscordClient discord, MissAnalyzer analyzer)
 {
     this.discord = discord;
     MissAnalyzer = analyzer;
     MissUrls     = new string[analyzer.MissCount];
     CurrentMiss  = null;
 }
        public async Task <string> SendMissMessage(DiscordClient discord, MissAnalyzer analyzer, int index)
        {
            analyzer.CurrentObject = index;
            DiscordMessageBuilder message = new DiscordMessageBuilder().WithFile("miss.png", await GetStream(analyzer.DrawSelectedHitObject(area)));

            return((await(await discord.GetChannelAsync(Settings.DumpChannel)).SendMessageAsync(message)).Attachments[0].Url);
        }
        public void TestStacking(string replayFile)
        {
            Replay       r        = new Replay(replayFile);
            var          db       = new OsuDbAPI.OsuDbFile("/home/will/osu!/osu!.db", byHash: true);
            Beatmap      b        = db.BeatmapsByHash[r.MapHash].Load("/home/will/A/osu!/Songs");
            MissAnalyzer analyzer = new MissAnalyzer(r, b);

            Assert.AreEqual(0, analyzer.MissCount);
            // foreach(var m in analyzer.DrawAllMisses(new System.Drawing.Rectangle(0, 0, 320, 320)))
            //     m.Save($"miss{Path.GetFileName(replayFile)}{i++}.png", ImageFormat.Png);
        }
예제 #4
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);
            }
        }
        public void TestSlider()
        {
            var          db       = new OsuDbAPI.OsuDbFile("/home/will/osu!/osu!.db", byId: true);
            Beatmap      b        = db.BeatmapsById[539697].Load("/home/will/A/osu!/Songs");
            Replay       r        = new Replay("/home/will/osu!/Data/r/20b064985202e1a5219432c774476b8b-132562134499563000.osr");
            MissAnalyzer analyzer = new MissAnalyzer(r, b);
            SliderObject s        = (SliderObject)b.HitObjects[465];

            Console.WriteLine(s);
            Console.WriteLine(string.Join(", ", s.Curves));
            Console.WriteLine(string.Join(", ", s.Points));
            Console.WriteLine(string.Join(", ", s.Curves.SelectMany(curve => curve.CurveSnapshots)));
        }
예제 #6
0
        private async Task TestAnalyzer(ServerReplayLoader replayLoader)
        {
            Assert.IsNull(await replayLoader.Load(GuildSettings.Default, api, replays, beatmaps));
            Assert.True(replayLoader.Loaded);
            var analyzer = new MissAnalyzer(replayLoader);
            var images   = analyzer.DrawAllMisses(new SixLabors.ImageSharp.Rectangle(0, 0, 480, 480));
            int i        = 0;

            foreach (var image in images)
            {
                string filename = Path.Combine(root, "out", $"{replayLoader.ToString()}.{i++}.png");
                await image.SaveAsPngAsync(filename);
            }
        }
        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);
            }
        }
 public MissWindowController(MissAnalyzer model, UIReplayLoader loader)
 {
     Model  = model;
     Loader = loader;
 }
예제 #9
0
        public static void Main(string[] args)
        {
            MissAnalyzer         missAnalyzer;
            MissWindowController controller;
            MissWindow           window;

            Debug.Print("Starting MissAnalyser... ");
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            string        replay = null, beatmap = null;
            List <string> extras;
            Dictionary <string, string> optList = new Dictionary <string, string>();
            bool   help        = false;
            int    getMiss     = -1;
            string optionsFile = "options.cfg";

            var opts = new OptionSet()
            {
                { "o|osudir=", "Set osu! directory", o => optList["osudir"] = o },
                { "c|config=", "Set options.cfg", f => optionsFile = f },
                { "s|songsdir=", "Set songs directory", s => optList["songsdir"] = s },
                { "d|daemon", "Run without dialogs", d => headless = d != null },
                { "h|help", "Displays help", h => help = h != null },
                { "m|miss=", "Export miss #", (int m) => getMiss = m }
            };

            extras = opts.Parse(args);
            foreach (var arg in extras)
            {
                if (arg.EndsWith(".osu") && File.Exists(arg))
                {
                    beatmap = arg;
                }
                if (arg.EndsWith(".osr") && File.Exists(arg))
                {
                    replay = arg;
                }
            }
            if (!File.Exists(optionsFile))
            {
                File.Create(optionsFile).Close();
                Debug.Print("\nCreating options.cfg... ");
                Debug.Print("- In options.cfg, you can define various settings that impact the program. ");
                Debug.Print("- To add these to options.cfg, add a new line formatted <Setting Name>=<Value> ");
                Debug.Print("- Available settings : SongsDir | Value = Specify osu!'s songs dir.");
                Debug.Print("-                       APIKey  | Value = Your osu! API key (https://osu.ppy.sh/api/");
                Debug.Print("-                       OsuDir  | Value = Your osu! directory");
            }
            if (help)
            {
                Console.WriteLine("osu! Miss Analyzer");
                opts.WriteOptionDescriptions(Console.Out);
                return;
            }

            try
            {
                Options        options      = new Options("options.cfg", optList);
                UIReplayLoader replayLoader = new UIReplayLoader(options);
                if (!replayLoader.Load(replay, beatmap))
                {
                    return;
                }
                if (replayLoader.Replay == null || replayLoader.Beatmap == null)
                {
                    ShowErrorDialog("Couldn't find " + (replayLoader.Replay == null ? "replay" : "beatmap"));
                    return;
                }

                missAnalyzer = new MissAnalyzer(replayLoader);
                controller   = new MissWindowController(missAnalyzer, replayLoader);
                window       = new MissWindow(controller);
                Application.Run(window);
            } catch (Exception e)
            {
                ShowErrorDialog(e.Message);
                File.WriteAllText("exception.log", e.ToString());
            }
        }
예제 #10
0
 public SavedMiss(MissAnalyzer analyzer)
 {
     MissAnalyzer = analyzer;
     MissUrls     = new string[analyzer.MissCount];
     Response     = null;
 }
예제 #11
0
 private async Task <string> SendMissMessage(MissAnalyzer analyzer, int index)
 {
     analyzer.CurrentObject = index;
     return((await(await Discord.GetChannelAsync(Settings.DumpChannel))
             .SendFileAsync("miss.png", GetStream(analyzer.DrawSelectedHitObject(area)), "")).Attachments[0].Url);
 }