/// <summary> /// 确保。 /// </summary> /// <exception cref="ExecutingException"></exception> protected async Task <int> EnsureGetBindingIdAsync(long qq) { var(success, result) = await DataProvider.GetBindingIdAsync(qq); ExecutingException.Ensure(success, "哎,获取绑定信息失败了。"); ExecutingException.Ensure(result != null, "没有绑定 osu! 账号。见https://github.com/bltsheep/OsuQqBotForNewbieGroup/wiki/%E5%B0%86-QQ-%E5%8F%B7%E4%B8%8E-osu!-%E8%B4%A6%E5%8F%B7%E7%BB%91%E5%AE%9A"); return(result.Value); }
protected async Task <UserInfo> EnsureGetUserInfo(string name, Bleatingsheep.Osu.Mode mode) { var(success, result) = await OsuApi.GetUserInfoAsync(name, mode); ExecutingException.Ensure(success, "网络错误。"); ExecutingException.Ensure(result != null, "无此用户!"); return(result); }
public static async Task <UserInfo> EnsureGetUserInfo(this OsuApiClient osuApi, string name, Bleatingsheep.Osu.Mode mode) { var(success, result) = await osuApi.GetUserInfoAsync(name, mode); ExecutingException.Ensure(success, "网络错误。"); ExecutingException.Ensure(result != null, "无此用户!"); return(result); }
public async Task ProcessAsync(Message message, Sisters.WudiLib.HttpApiClient api) { long id = message.UserId; var(networkSuccess, osuResult) = await DataProvider.GetBindingIdAsync(id); ExecutingException.Ensure(networkSuccess, "无法查询绑定账号。"); ExecutingException.Ensure(osuResult != null, "未绑定 osu! 游戏账号。"); var osuId = osuResult.Value; var recent = (await OsuApi.GetRecentlyAsync(osuId, OsuMixedApi.Mode.Standard, 1)).FirstOrDefault(); if (recent == null) { await api.SendMessageAsync(message.Endpoint, "没打图!"); return; } var reply = new List <string> { "/np 给 bleatingsheep,查询更方便!" }; try { var ppBeatmap = await s_spider.GetBeatmapPlusAsync(recent.BeatmapId); if (ppBeatmap == null) { reply.Add("很抱歉,无法查询 Loved 图。也有可能是 PP+ 没有这张图的数据。"); return; } reply.Add($"https://syrin.me/pp+/b/{ppBeatmap.Id}/"); reply.Add("Stars: " + ppBeatmap.Stars); reply.Add("Aim (Jump): " + ppBeatmap.AimJump); reply.Add("Aim (Flow): " + ppBeatmap.AimFlow); reply.Add("Precision: " + ppBeatmap.Precision); reply.Add("Speed: " + ppBeatmap.Speed); reply.Add("Stamina: " + ppBeatmap.Stamina); reply.Add("Accuracy: " + ppBeatmap.Accuracy); reply.Add("数据来自 PP+。"); } catch (ExceptionPlus) { reply.Add("访问 PP+ 网站失败。"); } finally { await api.SendMessageAsync(message.Endpoint, string.Join("\r\n", reply)); } }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { //await api.SendMessageAsync(context.Endpoint, $"[DEBUG] 比较:{_other};模式:{_mode}"); var id = await DataProvider.EnsureGetBindingIdAsync(context.UserId).ConfigureAwait(false); //var browser = GetBrowser(); byte[] data = null; var mode = Bleatingsheep.Osu.Mode.Standard; try { if (!string.IsNullOrEmpty(_mode)) { mode = Bleatingsheep.Osu.ModeExtensions.Parse(_mode); } } catch { await api.SendMessageAsync(context.Endpoint, "模式识别失败,fallback 到 Standard。").ConfigureAwait(false); } var url = $"http://hydrantweb/pptth/mini/{id}?height=350&mode={(int)mode}"; if (!string.IsNullOrEmpty(_other)) { var(_, user) = await OsuApi.GetUserInfoAsync(_other, mode); if (user == null) { ExecutingException.Ensure(false, "对比玩家错误"); } url += $"&compared={user.Id}"; } using (var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false)) { await page.SetViewportAsync(new ViewPortOptions { DeviceScaleFactor = 1.15, Width = 640, Height = 350, }).ConfigureAwait(false); await page.GoToAsync(url).ConfigureAwait(false); await Task.Delay(0).ConfigureAwait(false); data = await page.ScreenshotDataAsync(new ScreenshotOptions { FullPage = true, //Type = ScreenshotType.Jpeg, //Quality = 100, }).ConfigureAwait(false); } var stopwatch = Stopwatch.StartNew(); var sendResponse = await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false); var elapsedTime = stopwatch.ElapsedMilliseconds; var failed = sendResponse is null; if (failed) { await api.SendMessageAsync(context.Endpoint, "图片发送失败(确定)").ConfigureAwait(false); } (failed ? FailedElapsed : SuccessfulElapsed).Add(elapsedTime); }