示例#1
0
        public static CommandResult Run(CommandArguments args)
        {
            if (args.Arguments.Length == 0)
            {
                return new CommandResult
                       {
                           Type   = CommandResultType.MESSAGE,
                           Result = $"Usuage: !with [Mods] (Mods) (Mods)... or !with reset to reset."
                       }
            }
            ;
            Mod[] mods = null;


            BanchoUserHistory history = HistoryCache.Get(args.Username);

            if (history == null)
            {
                HistoryCache.Init(args.Username);
            }
            history = HistoryCache.Get(args.Username);


            if (args.Arguments[0] == "reset")
            {
                history.RecentMod = new Mod[] { };
                return(new CommandResult
                {
                    Type = CommandResultType.MESSAGE,
                    Result = $"Reseted mods."
                });
            }
            try
            {
                mods = Common.GetMods(args.Arguments, new OsuRuleset()).ToArray();
            }
            catch (Exception ex)
            {
                return(new CommandResult
                {
                    Type = CommandResultType.MESSAGE,
                    Result = ex.Message
                });
            }
            history.RecentMod = mods;
            StringBuilder sb = new StringBuilder();

            foreach (Mod mod in mods)
            {
                sb.Append(mod.Acronym);
            }


            OsuCalculator calc = new OsuCalculator(history.RecentBeatmapId);

            calc.Mod = mods;
            CalculateMessage msg = new CalculateMessage(calc);
            CommandResult    rs  = new CommandResult
            {
                Type   = CommandResultType.MESSAGE,
                Result = msg.ToString().Split("\n")[1]
            };

            return(rs);
        }
    }
示例#2
0
        public void OnQueryAction(object sender, IrcEventArgs e)
        {
            Console.WriteLine($"[PM-ACTION] {e.Data.Nick} : {e.Data.Message}");

            // Check NowPlaying
            if (NowPlayingParser.IsNowPlaying(e.Data.Message))
            {
                NowPlaying np = NowPlayingParser.Parse(e.Data.Message);
                if (np.IsMapSet == true)
                {
                    new CommandResult()
                    {
                        Type   = CommandResultType.MESSAGE,
                        Result = "Sorry. We cannot calculate the mapset."
                    }.Send(irc, e.Data.Nick);
                    return;
                }
                try
                {
                    BanchoUserHistory c = HistoryCache.Get(e.Data.Nick);
                    if (c == null)
                    {
                        c = new BanchoUserHistory(np.Id);
                        HistoryCache.cache[e.Data.Nick] = c;
                    }
                    short _mode = np.Mode == 0 && c.RecentMode == 0 ? (short)0 : np.Mode;
                    if (np.NpType == NowPlayingType.LISTENING)
                    {
                        _mode = c.RecentMode;                         // There is no mode in text.
                    }

                    Calculator calc = LegacyUtil.GetCalculator(_mode, np.Id);
                    string[]   mods = np.Mods;
                    if (!calc.IsConvertable())
                    {
                        // Fallback Calculator
                        calc = LegacyUtil.GetCalculator((short)calc.Beatmap.BeatmapInfo.RulesetID, np.Id);
                    }

                    calc.Mod = Common.GetMods(mods, calc.Ruleset).ToArray();
                    CalculateMessage msg = new CalculateMessage(calc);
                    new CommandResult()
                    {
                        Type   = CommandResultType.MESSAGE,
                        Result = msg.ToString()
                    }.Send(irc, e.Data.Nick);

                    c.RecentBeatmapId = np.Id;
                    c.RecentMode      = np.Mode;
                    c.RecentMod       = new Mod[] { };
                }
                catch (Exception err)
                {
                    new CommandResult()
                    {
                        Type   = CommandResultType.MESSAGE,
                        Result = $"A Error found: {err.Message}"
                    }.Send(irc, e.Data.Nick);
                }
            }
            else if (e.Data.Message.StartsWith("\u0001ACTION is listening to "))
            {
                new CommandResult()
                {
                    Type   = CommandResultType.MESSAGE,
                    Result = "I'm sorry. We can't check/download the un-submitted map."
                }.Send(irc, e.Data.Nick);
            }
        }
示例#3
0
        public static CommandResult Run(CommandArguments args)
        {
            if (args.Arguments.Length == 0)
            {
                return new CommandResult
                       {
                           Type   = CommandResultType.MESSAGE,
                           Result = $"Usuage: !acc [Accuracy] (Miss) (Max Combo)"
                       }
            }
            ;
            double acc       = -1;
            int    miss      = 0;
            int    max_combo = -1;

            try
            {
                var accraw = double.Parse(args.Arguments[0]);

                acc       = accraw > 1 ? accraw : accraw / 100;
                miss      = args.Arguments.Length > 1 ? int.Parse(args.Arguments[1]) : 0;
                max_combo = args.Arguments.Length > 2 ? int.Parse(args.Arguments[2]) : -1;
            }
            catch
            {
                return(new CommandResult
                {
                    Type = CommandResultType.MESSAGE,
                    Result = $"Wrong Argument. (Not a number.)"
                });
            }
            BanchoUserHistory history = HistoryCache.Get(args.Username);

            if (history.RecentBeatmapId == 0)
            {
                return(new CommandResult
                {
                    Type = CommandResultType.MESSAGE,
                    Result = $"Oops! we dont have history! plase /np and do it again!"
                });
            }
            OsuCalculator calc = new OsuCalculator(history.RecentBeatmapId);

            if (history.RecentMod.Length > 0)
            {
                calc.Mod = history.RecentMod;
            }
            calc.Misses = miss;
            CalculateMessage msg = new CalculateMessage(calc);

            msg.Acc = acc;
            if (max_combo != -1)
            {
                calc.Combo = max_combo;
            }
            CommandResult rs = new CommandResult()
            {
                Type   = CommandResultType.MESSAGE,
                Result = msg.ToString()
            };


            return(rs);
        }
    }