Example #1
0
 public MapInfo(string map_id)
 {
     try
     {
         var client  = new RestClient("https://osu.ppy.sh/api/");
         var request = new RestRequest($"get_beatmaps?b={map_id}&k={Data.ApiKey}");
         request.Timeout = 5000;
         client.Timeout  = 5000;
         var    response = client.Execute(request);
         string result   = response.Content;
         if (result.Length > 2)
         {
             var btm = JsonConvert.DeserializeObject <Beatmaps>(result.Substring(1, result.Length - 2));
             od      = Convert.ToDouble(btm.diff_overall.Replace('.', ','));
             obj     = Convert.ToDouble(Osu.Combo(map_id));
             stars   = Convert.ToDouble(btm.difficultyrating.Replace('.', ','));
             mode    = btm.mode;
             artist  = btm.artist;
             title   = btm.title;
             version = btm.version;
             keys    = Convert.ToInt16(btm.diff_approach);
         }
         else
         {
             mode = "-1";
         }
     }
     catch (Exception ex)
     {
         Log.Write($"ERROR: {ex}");
     }
 }
Example #2
0
        public static void OnQueryMessage(object sender, IrcEventArgs e)
        {
            Console.WriteLine(e.Data.Nick + ":" + e.Data.Message);
            Log.Write(e.Data.RawMessage);
            if (!users.Contains(e.Data.Nick))
            {
                users.Add(e.Data.Nick);
                last_map.Add("1023965");
                if (_announce != null)
                {
                    irc.SendReply(e.Data, _announce);
                }
            }
            if (e.Data.Message.StartsWith("!"))
            {
                var command = e.Data.Message.ToLower().Split(' ');

                if (command[0] == "!r")
                {
                    if (command.Length > 1 && command[1] == "4")
                    {
                        var list = Osu.GetPP(e.Data.Nick);
                        Log.Write($"{list[0]} | {list[1]}");
                        if (list[0] == -1)
                        {
                            irc.SendReply(e.Data, "Request failed. Time for a break, maybe? :) Possible problems: You don't have enough scores in mania mode; Connection failed for some reason.");
                        }
                        else
                        {
                            var get_map = Data.GetMap(e.Data.Nick, list, "4");
                            Log.Write(get_map);
                            irc.SendReply(e.Data, get_map);
                            Console.WriteLine("~Reply sent.");
                        }
                    }
                    else if (command.Length > 1 && command[1] == "7")
                    {
                        var pp = Osu.GetPP(e.Data.Nick);
                        Log.Write($"{pp[0]}");
                        if (pp[0] == -1)
                        {
                            irc.SendReply(e.Data, "Request failed. Time for a break, maybe? :) Possible problems: You don't have enough scores in mania mode; Connection failed for some reason.");
                        }
                        else
                        {
                            var get_map = Data.GetMap(e.Data.Nick, pp, "7");
                            Log.Write(get_map);
                            irc.SendReply(e.Data, get_map);
                            Console.WriteLine("~Reply sent.");
                        }
                    }
                    else if (command.Length == 1)
                    {
                        Console.WriteLine("Too few arguments.");
                        Log.Write("Too few arguments.");
                        irc.SendReply(e.Data, "Too few aruments. Command usage: !r [keys]. Example: !r 4");
                    }
                    else
                    {
                        Log.Write("4 or 7 keys required.");
                        irc.SendReply(e.Data, "Due to lack of maps I can only work with 4 and 7 keys right now.");
                    }
                }
                else if (command[0] == "!acc")
                {
                    if (command.Length == 3)
                    {
                        string map_id = null;
                        for (int i = 0; i < users.Count; i++)
                        {
                            if (users[i] == e.Data.Nick)
                            {
                                try
                                {
                                    map_id = last_map[i];
                                }
                                catch (ArgumentOutOfRangeException ex)
                                {
                                    Log.Write("" + ex);
                                    Console.WriteLine("Error (ArgumentOutOfRangeException)");
                                    irc.SendReply(e.Data, "Send /np first. (map must be ranked)");
                                }
                            }
                        }
                        Double acc;
                        Double score;
                        try
                        {
                            acc = Convert.ToDouble(command[1].Replace('.', ','));
                            Log.Write($"{acc}");
                            score = Convert.ToDouble(command[2]);
                            Log.Write($"{score}");
                            if (acc < 0 || acc > 100)
                            {
                                acc = -1;
                            }
                            if (score < 0 || score > 1000000)
                            {
                                acc = -1;
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Write("Error: " + ex);
                            Console.WriteLine(ex);
                            acc   = -1;
                            score = -1;
                        }

                        if (acc == -1 || score == -1)
                        {
                            Log.Write("Wrong input.");
                            irc.SendReply(e.Data, "Wrong input. Usage: !acc [acc] [score]");
                        }
                        else
                        {
                            MapInfo m = new MapInfo(map_id);
                            if (m.mode == "3")
                            {
                                string output = $"{m.artist} - {m.title} [{m.version}] | {Data.Calculate(m.od, m.stars, m.obj, acc, score)}pp for {acc}%";
                                Log.Write(output);
                                irc.SendReply(e.Data, output);
                            }
                            else if (m.mode == "0" || m.mode == "1" || m.mode == "2")
                            {
                                irc.SendReply(e.Data, "Mania mode required.");
                                Log.Write("Error: (166) Wrong mode.");
                            }
                            else
                            {
                                irc.SendReply(e.Data, "Please, listen to mania song then do /np.");
                                Log.Write("Error: 171 m.mode is \"" + m.mode + "\"");
                                Console.WriteLine("Please, listen to mania song then do /np.");
                            }
                        }
                    }
                    else
                    {
                        Log.Write("Too few arguments.");
                        Console.WriteLine("Too few arguments.");
                        irc.SendReply(e.Data, "Too few arguments. Usage: !acc [accuracy] [score]. Example: !acc 96.04 842098");
                    }
                }
                else if (command[0] == "!dif" || command[0] == "!diff")
                {
                    if (command.Length < 3)
                    {
                        Log.Write(e.Data.Nick + "// Too few arguments.");
                        Console.WriteLine("Too few arguments.");
                        irc.SendReply(e.Data, "Too few arguments. Usage: !diff [keys] [difficulty]. Example: !diff 4 3.55");
                    }
                    else if (command.Length >= 3)
                    {
                        try
                        {
                            var diff = Convert.ToDouble(command[2].Replace('.', ','));
                            var keys = command[1];
                            if (command[1] == "4" || command[1] == "7")
                            {
                                string get_map;
                                if (command.Length == 3)
                                {
                                    get_map = Data.GetMapDiff(e.Data.Nick, diff, keys);
                                }
                                else
                                {
                                    var diff2 = Convert.ToDouble(command[3].Replace('.', ','));
                                    get_map = Data.GetMapMinMaxDiff(e.Data.Nick, diff, diff2, command[1]);
                                }
                                Log.Write(get_map);
                                irc.SendReply(e.Data, get_map);
                                Console.WriteLine("~Reply sent.");
                            }
                            else
                            {
                                irc.SendReply(e.Data, "Works for 4 and 7 keys for now.");
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Write($"ex");
                            Console.WriteLine(ex);
                            irc.SendReply(e.Data, "Error occuried. Wrong input?");
                        }
                    }
                }
                else if (command[0] == "!help" || command[0] == "!info")
                {
                    irc.SendReply(e.Data, "Hello, I'm Amatsu! And I can do some cute things for you. Forum thread can be found [https://osu.ppy.sh/forum/t/637171 here], commands are listed [https://github.com/Alexmal007/AmatsuBot/wiki here]");
                }
                else if (command[0] == "!coffee")
                {
                    irc.SendReply(e.Data, "[https://youtu.be/SpiPD_Ti_Bg Держи^^]");
                }
                else if (command[0] == "!dt")
                {
                    if (command.Length < 2)
                    {
                    }
                    else if (command[1] == "4" || command[1] == "7")
                    {
                        var pp = Osu.GetPP(e.Data.Nick)[0];
                        Log.Write($"{pp}");
                        if (pp == -1)
                        {
                            irc.SendReply(e.Data, "Request failed. Time for a break, maybe? :) Possible problems: You don't have enough scores in mania mode; Connection failed for some reason.");
                        }
                        else
                        {
                            string get_map;
                            if (command[1] == "4")
                            {
                                get_map = Data.GetDoubleTimeMap(e.Data.Nick, pp, "4");
                            }
                            else
                            {
                                get_map = Data.GetDoubleTimeMap(e.Data.Nick, pp, "7");
                            }
                            Log.Write(get_map);
                            irc.SendReply(e.Data, get_map);
                            Console.WriteLine("~Reply sent.");
                        }
                    }
                }
                else if (command[0] == "!sendreport")
                {
                    if (command.Length > 1)
                    {
                        irc.SendMessage(SendType.Message, username, $"(REPORT) {e.Data.Nick}: {command[1]}");
                        Log.Report($"{e.Data.Nick}: {command[1]}");
                        irc.SendReply(e.Data, "Report sent!");
                    }
                    else
                    {
                        irc.SendReply(e.Data, "Too few arguments. Usage: !report [report message].");
                    }
                }
                else
                {
                    irc.SendReply(e.Data, "Unknown command. All available commands are listed [https://github.com/Alexmal007/AmatsuBot/wiki here].");
                }
            }
        }