private async Task <ICommandAnswer> GetRebalanceProfile(Message msg) { if (!string.IsNullOrEmpty(msg.Text)) { await using var db = new DatabaseOsu(); string player; if (msg.Text.Length > 11) { player = ProfileLinkParser.Parse(msg.Text)?.Id; } else { player = (await db.Players.FirstOrDefaultAsync(x => x.TelegramID == msg.From.Id))?.ToString(); } if (!string.IsNullOrEmpty(player)) { var result = await FormatRebalanceProfile(player); if (!string.IsNullOrEmpty(result)) { return(new TextCommandAnswer(result)); } } } return(Localization.GetAnswer("generic_badrequest", msg.Chat.Id)); }
public async Task ReceiveMessage(Message message) { if (!string.IsNullOrEmpty(message.Text)) { string playerId = ProfileLinkParser.Parse(message.Text)?.Id; if (!string.IsNullOrEmpty(playerId)) { await API.SendMessage(await FormatPlayerInfo(playerId), message.Chat.Id, ParseMode.Html, message.MessageId, disablePreview : false); } } }
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)); }