Пример #1
0
        public async Task OsuTrack(string gameModeStr)
        {
            OsuBoundUserDB boundUser = await OsuDB.GetBoundUserBy_DiscordID(Context.Message.Author.ID);

            if (boundUser == null)
            {
                await Context.Channel.SendMessageAsync($"You need to bind your osu account first with `{Context.Discord.PREFIX}OsuBind [player_name]`.");
            }
            else
            {
                OsuGameModes gameMode = OsuGameModesConverter.FromOfficialName(gameModeStr, true);

                OsuGameModeUserDB gameModeUser = await OsuDB.GetGameModeUserBy_OsuID(boundUser.UserID, gameMode);

                if (!boundUser.GameModes.HasFlag(gameMode))
                {
                    OsuUser osuUser = await OsuNetwork.DownloadUser(boundUser.UserID, gameMode);

                    await OsuDB.WriteOsuGameModeUser(osuUser, gameMode);

                    boundUser.GameModes |= gameMode;

                    await OsuDB.UpdateBoundOsuUser(osuUser, boundUser);

                    await Context.Channel.SendMessageAsync($"You are now being tracked for {Enum.GetName(typeof(OsuGameModes), gameMode)} gameplay.");
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"You are already being tracked for {Enum.GetName(typeof(OsuGameModes), gameMode)} gameplay.");
                }
            }
        }
Пример #2
0
        public async Task Osu_UnTrack(string gameModeStr)
        {
            OsuBoundUserDB boundUser = await OsuDB.GetBoundUserBy_DiscordID(Context.Message.Author.ID);

            if (boundUser == null)
            {
                await Context.Channel.SendMessageAsync($"You need to bind your osu account first with `{Context.Discord.PREFIX}OsuBind [player_name]`.");
            }
            else
            {
                OsuGameModes gameMode = OsuGameModesConverter.FromOfficialName(gameModeStr, true);

                if (boundUser.GameModes.HasFlag(gameMode))
                {
                    await OsuDB.RemoveOsuGameModeUser(boundUser.UserID, gameMode);

                    boundUser.GameModes ^= gameMode;

                    await OsuDB.UpdateBoundOsuUser(boundUser);

                    await Context.Channel.SendMessageAsync($"You have been successfully removed from {Enum.GetName(typeof(OsuGameModes), gameMode)} gameplay database!");
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"You are not in {Enum.GetName(typeof(OsuGameModes), gameMode)} gameplay tracked database.");
                }
            }
        }
Пример #3
0
        public async Task OsuBindUser([Remainder] string input)
        {
            OsuBoundUserDB bound = await OsuDB.GetBoundUserBy_DiscordID(Context.Message.Author.ID);

            string[] args = input.Split(' ');

            if (args[0].ToLower() == "mainmode")
            {
                if (bound == null)
                {
                    await Context.Channel.SendMessageAsync("You need to bind your osu user first. `OsuBind [username]`");
                }
                else
                {
                    if (args.Length == 1)
                    {
                        await Context.Channel.SendMessageAsync("You need to specify a Game Mode type. It defaults to `standard`.");
                    }
                    else
                    {
                        OsuGameModes gameMode = OsuGameModesConverter.FromOfficialName(input.Substring(args[0].Length + 1), true);
                        bound.MainMode = gameMode;
                        await OsuDB.UpdateBoundOsuUser(bound);

                        await Context.Channel.SendMessageAsync($"Main mode has been successfully changed to **{OsuGameModesConverter.GameModeName(gameMode)}**!");
                    }
                }
            }
            else
            {
                OsuUser osuUser = await OsuNetwork.DownloadUser(input, OsuGameModes.STD);

                if (bound == null)
                {
                    await OsuDB.RegisterBoundOsuUser(osuUser, Context.Message.Author.ID);

                    await Context.Channel.SendMessageAsync($"Binded {input} to `{OsuSQL.table_name}`");
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"{input} is already binded.");
                }
            }
        }
Пример #4
0
        private void Network_DiscordMessageReceived(object sender, EventArgModels.DiscordMessageReceivedEventArgs e)
        {
            bool newDesign = false;

            //Detect singular beatmaps
            {
                Match match = Regex.Match(e.Message.Content, @"osu.ppy.sh\/b\/\d+(&m=\d)?");

                if (!match.Success)
                {
                    match = Regex.Match(e.Message.Content, @"osu.ppy.sh\/p\/beatmap\?b=\d+(&m=\d)?");
                }
                if (!match.Success)
                {
                    match     = Regex.Match(e.Message.Content, @"osu.ppy.sh\/beatmapsets\/\d+#(osu|taiko|fruits|mania)\/\d+");
                    newDesign = true;
                }

                if (match.Success)
                {
                    MatchCollection parameters = Regex.Matches(e.Message.Content, @"\d+");

                    string ID = newDesign ? parameters[1].Value : parameters[0].Value;

                    string gameMode = newDesign ?
                                      " " + OsuGameModesConverter.ToOfficialNumeration(OsuGameModesConverter.FromOfficialName(Regex.Match(e.Message.Content, @"#(osu|taiko|fruits|mania)").Value.Remove(0, 1), false)).ToString() :
                                      (parameters.Count == 2 ? " " + parameters[1].Value : string.Empty);

                    Console.WriteLine($"Beatmap detected, ID:{ID}");

                    discord.cService.ExecuteAsync("Beatmap", ID + gameMode, e.Message, internally: true);
                    return;
                }
            }
            //Detect beatmap packs
            {
                Match match = Regex.Match(e.Message.Content, @"osu.ppy.sh\/s\/\d+");

                if (!match.Success)
                {
                    match = Regex.Match(e.Message.Content, @"osu.ppy.sh\/beatmapsets\/\d+");
                }

                if (match.Success)
                {
                    MatchCollection parameters = Regex.Matches(e.Message.Content, @"\d+");

                    string ID = parameters[0].Value;

                    Console.WriteLine($"Beatmap pack detected, ID:{ID}");

                    discord.cService.ExecuteAsync("BeatmapPack", ID, e.Message, internally: true);
                    return;
                }
            }
        }