Example #1
0
        private void Updater_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (osuInfo == null && owInfo == null)
            {
                updater.Interval = 60000;
                osuInfo          = new Data.Osu_Data();
                owInfo           = new Data.Overwatch_Data();
                return;
            }

            foreach (Data.osuUser OUser in osuInfo.osuUsers)
            {
                try
                {
                    if (OUser.channels[0].GetUser(OUser.discordID).Status.Value.Equals(UserStatus.Online.Value) || OUser.channels[0].Id.Equals(226499471683485697))
                    {
                        dynamic dict = Data.osuUser.userStats(OUser.ident.ToString(), OUser.mainMode);
                        if (OUser.pp + 1 <= double.Parse(dict["pp_raw"], CultureInfo.InvariantCulture))
                        {
                            string query = Information.readURL($"https://osu.ppy.sh/api/get_user_recent?u={OUser.ident}&{OUser.mainMode}&limit=1&k={apiKey}");
                            query = query.Remove(0, 1);
                            query = query.Remove(query.Length - 1, 1);

                            var jss   = new JavaScriptSerializer();
                            var dict2 = jss.Deserialize <dynamic>(query);

                            string beatmap_ID = dict2["beatmap_id"];
                            query = Information.readURL($@"https://osu.ppy.sh/api/get_scores?b={beatmap_ID}&{OUser.mainMode}&u={OUser.username}&limit=1&k={apiKey}");
                            query = query.Remove(0, 1);
                            query = query.Remove(query.Length - 1, 1);

                            var dict3 = jss.Deserialize <dynamic>(query);

                            string output = $"Recieved pp change of `+{Math.Round(double.Parse(dict["pp_raw"], CultureInfo.InvariantCulture) - OUser.pp, 2)}` by **{OUser.username}**  ({Math.Round(double.Parse(dict["pp_raw"], CultureInfo.InvariantCulture), 2)}pp)\n\nOn https://osu.ppy.sh/b/{dict2["beatmap_id"]}&{OUser.mainMode}\nScore: {string.Format("{0:n0}", int.Parse(dict2["score"]))}  ({calcAcc(dict3, OUser.mainMode)}% , {dict2["maxcombo"]}x)\n{dict2["rank"]}, `{dict3["pp"]}pp`";

                            foreach (Channel ch in OUser.channels)
                            {
                                ch.SendMessage(output);
                            }

                            OUser.updateStats(dict);
                        }
                        else if (OUser.pp < double.Parse(dict["pp_raw"], CultureInfo.InvariantCulture))
                        {
                            OUser.updateStats(dict);
                        }
                    }
                }
                catch { }
            }

            //foreach (Data.OW_User user in owInfo.OW_Users)
            //{
            //    if (!user.channels[0].GetUser(user.discordID).Status.Value.Equals(UserStatus.Offline.Value)
            //        && user.channels[0].GetUser(user.discordID).CurrentGame.Value.Equals("Overwatch"))
            //    {
            //        string tracker = user.trackChange();

            //        if (!tracker.Equals(""))
            //            foreach (Channel ch in user.channels)
            //                ch.SendMessage(tracker);
            //    }
            //}
        }
Example #2
0
        void IModule.Install(ModuleManager manager)
        {
            info             = new Data.TextInformation();
            osuInfo          = new Data.Osu_Data();
            updater          = new Timer(60000);
            updater.Elapsed += Updater_Elapsed;
            updater.Start();

            _manager = manager;
            _client  = manager.Client;

            _client.MessageReceived += _client_MessageReceived;

            manager.CreateCommands("quote", group =>
            {
                group.PublicOnly();

                group.CreateCommand("get")
                .Description("Gets the Quote at Index or Random if no Index is given")
                .Parameter("Index", ParameterType.Optional)
                .Do(async e =>
                {
                    if (e.Args[0] == "")
                    {
                        await e.Channel.SendMessage($"Quote[{new Random().Next(0, info.quotes.Count)}]:\n{info.quotes[new Random().Next(0, info.quotes.Count)]}");
                    }
                    else
                    {
                        await e.Channel.SendMessage($"Quote[{e.Args[0]}]:\n{info.quotes[int.Parse(e.Args[0])]}");
                    }
                });

                group.CreateCommand("search")
                .Description("Searches all Quote containing the keyword")
                .Parameter("keyword", ParameterType.Unparsed)
                .Do(async e =>
                {
                    string output = "";

                    for (int i = 0; i < info.quotes.Count; i++)
                    {
                        if (info.quotes[i].ToString().ToLower().Contains(e.Args[0].ToLower()))
                        {
                            output += $"Quote[{i}]:\n{info.quotes[i]}\n\n";
                        }
                    }

                    await e.Channel.SendMessage(output);
                });

                group.CreateCommand("add")
                .Description("Adds a Quote at the end of the List")
                .Parameter("Quote", ParameterType.Unparsed)
                .Do(async e =>
                {
                    info.quotes.Add($"{e.Args[0]}");
                    info.writeInformation();
                    await e.Channel.SendMessage($"Added Quote[{info.quotes.Count - 1}]");
                });

                group.CreateCommand("de")
                .Description("Removes Quote at Index")
                .Parameter("Index")
                .Do(async e =>
                {
                    info.quotes.RemoveAt(int.Parse(e.Args[0]));
                    info.writeInformation();
                    await e.Channel.SendMessage($"Removed Quote[{e.Args[0]}]");
                });
            });

            manager.CreateCommands("", group =>
            {
                group.CreateCommand("giveCookie")
                .Description("You make me survive for a few minutes longer!")
                .Do(async e =>
                {
                    info.cookies++;
                    info.writeInformation();
                    await e.Channel.SendMessage($"Up to now, I have been fed {info.cookies} cookies!");
                });
            });

            manager.CreateCommands("osu", group =>
            {
                group.CreateCommand("user")
                .Description("test")
                .Parameter("name")
                .Do(async e =>
                {
                    var dict = Module.Data.osuUser.userStats(e.GetArg("name"));

                    try { await e.Channel.SendMessage($"User: {dict["username"]} \nPP: {dict["pp_raw"]}\n\nhttps://osu.ppy.sh/u/{dict["user_id"]}"); } catch (Exception ex) { await e.Channel.SendMessage(ex.Message); }
                });

                group.CreateCommand("signup")
                .Description("Signs you up into the Osu! Database")
                .Parameter("name")
                .Do(async e =>
                {
                    if (osuInfo.osuUsers.Find(x => x.discordID == e.User.Id) != null)
                    {
                        return;
                    }

                    var dict = Module.Data.osuUser.userStats(e.GetArg("name"));

                    osuInfo.osuUsers.Add(new Data.osuUser(e.User.Id, dict["user_id"]));

                    osuInfo.writeInformation();

                    await e.Channel.SendMessage("Signed you up, " + dict["username"] + ".");
                });

                group.CreateCommand("setMainMode")
                .Description("0 = Standard, 1 = Taiko, 2 = CtB, 3 = Mania")
                .Parameter("Mode")
                .Do(async e =>
                {
                    if (osuInfo.osuUsers.Find(x => x.discordID == e.User.Id) == null)
                    {
                        return;
                    }

                    osuInfo.osuUsers.Find(x => x.discordID == e.User.Id).mainMode = "m=" + e.GetArg("Mode");
                    osuInfo.osuUsers.Find(x => x.discordID == e.User.Id).updateStats();

                    osuInfo.writeInformation();

                    await e.Channel.SendMessage("Set mode to " + e.GetArg("Mode"));
                });

                group.CreateCommand("getStats")
                .Description("Fetches and updates your Data from the DataBase")
                .Do(async e =>
                {
                    Data.osuUser OUser = osuInfo.osuUsers.Find(x => x.discordID == e.User.Id);
                    OUser.updateStats();

                    await e.Channel.SendMessage($"Name: {OUser.username}\nScore: {OUser.score} ({Math.Round(OUser.accuracy, 2)}%)\nPP: {OUser.pp}  {OUser.mainMode}\n\nhttps://osu.ppy.sh/u/{OUser.ident}");
                });

                group.CreateGroup("ranking", RankingGroup =>
                {
                    RankingGroup.CreateCommand("pp")
                    .Do(async e =>
                    {
                        osuInfo.osuUsers.Sort((y, x) => x.pp.CompareTo(y.pp));
                        string output = "";

                        int count = 0;

                        foreach (Data.osuUser curUser in osuInfo.osuUsers)
                        {
                            count++;
                            try
                            {
                                output += $"#{count} ``PP: {curUser.pp}`` by **{e.Server.GetUser(curUser.discordID).Name}** ({curUser.username})\n";
                            }
                            catch (NullReferenceException ex)
                            {
                                count--;
                            }
                        }

                        await e.Channel.SendMessage(output);
                    });

                    RankingGroup.CreateCommand("acc")
                    .Do(async e =>
                    {
                        osuInfo.osuUsers.Sort((y, x) => x.accuracy.CompareTo(y.accuracy));
                        string output = "";

                        int count = 0;

                        foreach (Data.osuUser curUser in osuInfo.osuUsers)
                        {
                            count++;
                            try
                            {
                                output += $"#{count} ``{Math.Round(curUser.accuracy, 2)}%`` by **{e.Server.GetUser(curUser.discordID).Name}** ({curUser.username})\n";
                            }
                            catch (NullReferenceException ex)
                            {
                                count--;
                            }
                        }

                        await e.Channel.SendMessage(output);
                    });

                    RankingGroup.CreateCommand("score")
                    .Do(async e =>
                    {
                        osuInfo.osuUsers.Sort((y, x) => x.score.CompareTo(y.score));
                        string output = "";

                        int count = 0;

                        foreach (Data.osuUser curUser in osuInfo.osuUsers)
                        {
                            count++;
                            try
                            {
                                output += $"#{count} ``{curUser.score}`` by **{e.Server.GetUser(curUser.discordID).Name}** ({curUser.username})\n";
                            }
                            catch (NullReferenceException ex)
                            {
                                count--;
                            }
                        }

                        await e.Channel.SendMessage(output);
                    });

                    RankingGroup.CreateCommand("playcount")
                    .Do(async e =>
                    {
                        osuInfo.osuUsers.Sort((y, x) => x.playcount.CompareTo(y.playcount));
                        string output = "";

                        int count = 0;

                        foreach (Data.osuUser curUser in osuInfo.osuUsers)
                        {
                            count++;
                            try
                            {
                                output += $"#{count} ``{curUser.playcount}`` by **{e.Server.GetUser(curUser.discordID).Name}** ({curUser.username})\n";
                            }
                            catch (NullReferenceException ex)
                            {
                                count--;
                            }
                        }

                        await e.Channel.SendMessage(output);
                    });
                });
            });
        }