private async Task <ICommandAnswer> AddMe(Telegram.Bot.Types.Message message) { if (message.Text.Length > 6) { await using var db = new DatabaseOsu(); string player = ProfileLinkParser.Parse(message.Text)?.Id; if (string.IsNullOrEmpty(player)) { player = message.Text.Substring(7); } if (!string.IsNullOrEmpty(player)) { if (db.Players.Any(x => x.TelegramID == message.From.Id)) { return(Localization.GetAnswer($"annoy_{RNG.NextNoMemory(1, 10)}", message.Chat.Id)); } if (!uint.TryParse(player, out var osuID)) { // if they used /u/cookiezi instead of /u/124493 we ask osu API for an ID var info = await WebApiHandler.MakeApiRequest(new GetUser(player)); if (info == null) { return(Localization.GetAnswer("recentscores_player_add_failed", message.Chat.Id)); } else { osuID = info.Id; } } if (osuID != 0) { await db.Players.AddAsync(new DatabaseOsu.Player { OsuID = osuID, TelegramID = message.From.Id }); await db.SaveChangesAsync(); return(Localization.GetAnswer("recentscores_player_add_success", message.Chat.Id)); } } } return(Localization.GetAnswer("recentscores_player_add_failed", message.Chat.Id)); }
private async Task <ICommandAnswer> GetPass(Telegram.Bot.Types.Message message) { uint playerId = 0; List <string> msgSplit = message.Text.Split(' ').ToList(); msgSplit.RemoveAt(0); if (msgSplit.Count > 0) { var playerName = string.Join(" ", msgSplit); var player = await WebApiHandler.MakeApiRequest(new GetUser(playerName)); if (player != null) { playerId = player.Id; } } else { await using var db = new DatabaseOsu(); var id = db.Players.FirstOrDefault(x => x.TelegramID == message.From.Id)?.OsuID; if (id == null || id == 0) { return(Localization.GetAnswer("recentscores_unknown_player", message.Chat.Id)); } playerId = id.Value; } if (playerId == 0) { return(Localization.GetAnswer("generic_fail", message.Chat.Id)); } var lastScores = await WebApiHandler.MakeApiRequest(new GetUserScores(playerId, ScoreType.Recent, false)); if (lastScores.Count > 0) { var score = lastScores[0]; ChatBeatmapCache.StoreLastMap(message.Chat.Id, new ChatBeatmapCache.CachedBeatmap { BeatmapId = score.BeatmapShort.Id, BeatmapSetId = score.BeatmapShort.BeatmapSetId }); score.Beatmap = await WebApiHandler.MakeApiRequest(new GetBeatmap(score.BeatmapShort.Id)); return(new TextCommandAnswer(FormatScore(score, true))); } return(Localization.GetAnswer("generic_fail", message.Chat.Id)); }
private async Task <string> FormatPlayerInfo(string playerID) { Types.V2.User info = await WebApiHandler.MakeApiRequest(new GetUser(playerID)); if (info == null) { return(string.Empty); } var topscores = await WebApiHandler.MakeApiRequest(new GetUserScores(info.Id, ScoreType.Best, limit : topscores_to_show)); if (topscores == null || topscores.Count <= 0) { return(string.Empty); } string formatedTopscores = string.Empty; for (int i = 0; i < topscores.Count; i++) { Score score = topscores[i]; string mods = string.Empty; if (score.Mods.Length > 0) { mods = $" +{string.Join("", score.Mods)}"; } // 1. 123pp | Artist - Title [Diffname] +Mods (Rank, Accuracy%) string mapName = $"{score.BeatmapSet.Artist} - {score.BeatmapSet.Title} [{score.Beatmap.Version}]".FilterToHTML(); formatedTopscores += $"<b>{(i + 1)}</b>. <code>{score.Pp:F1}pp</code> | (<b>{score.Grade.GetDescription()}</b>) {mapName}{mods} ({score.Accuracy:N2}%)\n"; } var title = string.Empty; if (!string.IsNullOrEmpty(info.Title)) { title = $"<i>{info.Title}</i>\n"; } return($"<b>{info.Username}</b> <a href=\"{info.AvatarUrl}\">-</a> <code>{info.Statistics.Pp}pp</code> - #{info.Statistics.GlobalRank} (#{info.Statistics.Rank.Country} {info.Country.Code})\n" + $"{title}\n" + $"<b>Playcount</b>: {info.Statistics.Playcount} ({info.Statistics.PlaytimeSeconds / 60.0 / 60.0:F2} hours)\n" + $"<b>Joined on</b>: {info.JoinDate}\n" + $"__________\n" + $"{formatedTopscores}"); }
private async Task <ICommandAnswer> GetLastScores(Telegram.Bot.Types.Message message) { uint playerId = 0; int amount = 1; List <string> msgSplit = message.Text.Split(' ').ToList(); msgSplit.RemoveAt(0); if (msgSplit.Count > 0 && int.TryParse(msgSplit.Last(), out amount)) { msgSplit.Remove(msgSplit.Last()); } if (amount > recent_amount) { amount = recent_amount; } else if (amount <= 0) { amount = 1; } if (msgSplit.Count > 0) { var playerName = string.Join(" ", msgSplit); var player = await WebApiHandler.MakeApiRequest(new GetUser(playerName)); if (player != null) { playerId = player.Id; } } else { await using var db = new DatabaseOsu(); var id = db.Players.FirstOrDefault(x => x.TelegramID == message.From.Id)?.OsuID; if (id == null || id == 0) { return(Localization.GetAnswer("recentscores_unknown_player", message.Chat.Id)); } playerId = id.Value; } if (playerId == 0) { return(Localization.GetAnswer("generic_fail", message.Chat.Id)); } List <Score> lastScores = await WebApiHandler.MakeApiRequest(new GetUserScores(playerId, ScoreType.Recent, true)); if (lastScores != null) { if (lastScores.Count == 0) { return(Localization.GetAnswer("recentscores_no_scores", message.Chat.Id)); } string result = string.Empty; foreach (var score in lastScores.Take(amount)) { if (amount == 1) { ChatBeatmapCache.StoreLastMap(message.Chat.Id, new ChatBeatmapCache.CachedBeatmap { BeatmapId = score.BeatmapShort.Id, BeatmapSetId = score.BeatmapShort.BeatmapSetId }); } score.Beatmap = await WebApiHandler.MakeApiRequest(new GetBeatmap(score.BeatmapShort.Id)); result += FormatScore(score, true); } return(new TextCommandAnswer(result)); } return(Localization.GetAnswer("generic_fail", message.Chat.Id)); }
private async Task <ICommandAnswer> GetMapScores(Telegram.Bot.Types.Message message) { uint mapId = 0; // beatmap id regex can parse link as part of a complex message so we dont need to clean it up beforehand var msgText = message.Text; if (message.ReplyToMessage != null) { var sentMap = ChatBeatmapCache.GetSentMap(message.ReplyToMessage.MessageId); if (sentMap?.BeatmapId is not null) { mapId = sentMap.BeatmapId; } else if (message.ReplyToMessage.Text.Contains(".ppy.sh")) { msgText = message.ReplyToMessage.Text; } } var msgSplit = msgText.Split(' ').ToList(); var mods = LegacyMods.NM; if (msgSplit.Count > 1) { var data = BeatmapLinkParser.Parse(msgText); if (data != null) { mapId = data.ID; mods = data.Mods; if (data.IsBeatmapset) { BeatmapSet set = await WebApiHandler.MakeApiRequest(new GetBeatmapSet(data.ID)); if (set?.Beatmaps?.Count > 0) { mapId = set.Beatmaps.OrderBy(x => x.StarRating).Last().Id; } } } } else if (mapId == 0) { mapId = ChatBeatmapCache.GetLastMap(message.Chat.Id)?.BeatmapId ?? 0; } if (mapId == 0) { return(Localization.GetAnswer("generic_fail", message.Chat.Id)); } await using var db = new DatabaseOsu(); var playerId = db.Players.FirstOrDefault(x => x.TelegramID == message.From.Id)?.OsuID; if (playerId == null || playerId == 0) { return(Localization.GetAnswer("recentscores_unknown_player", message.Chat.Id)); } var result = string.Empty; if (mods == 0) { // no mods specified - use apiv1 to get all scores on a map and then get score data from apiv2 var scores = await WebApiHandler.MakeApiRequest(new WebAPI.Requests.V1.GetScores(playerId.Value.ToString(), mapId, mods, score_amount)); if (scores == null || scores.Count <= 0) { return(Localization.GetAnswer("recentscores_no_scores", message.Chat.Id)); } var map = await WebApiHandler.MakeApiRequest(new GetBeatmap(mapId)); foreach (var v1Score in scores) { var score = await WebApiHandler.MakeApiRequest(new GetUserBeatmapScore(mapId, playerId.Value, v1Score.LegacyMods)); if (score != null) { score.Beatmap = map; result += FormatScore(score, false); } } } else { // mods specified - get data straight from apiv2 var score = await WebApiHandler.MakeApiRequest(new GetUserBeatmapScore(mapId, playerId.Value, mods)); if (score == null) { return(Localization.GetAnswer("recentscores_no_scores", message.Chat.Id)); } score.Beatmap = await WebApiHandler.MakeApiRequest(new GetBeatmap(mapId)); result += FormatScore(score, false); } if (!string.IsNullOrEmpty(result)) { ChatBeatmapCache.StoreLastMap(message.Chat.Id, new ChatBeatmapCache.CachedBeatmap { BeatmapId = mapId }); return(new TextCommandAnswer(result)); } return(Localization.GetAnswer("generic_fail", message.Chat.Id)); }
public ProjectBuilderController() { _webApi = new WebApiHandler(); }