public bool ShouldResponse(Sisters.WudiLib.Posts.Message message) { if (!Verifier.IsAdminAsync(message.UserId).GetAwaiter().GetResult()) { return(false); } _operator = message.UserId; var content = message.Content; var contentList = content.Sections; if (contentList.Count < 3) { return(false); } if (contentList[0].TryGetText(out string p1) && "绑定".Equals(p1?.Trim(), StringComparison.InvariantCultureIgnoreCase) && contentList[1].TryGetAtMember(out _qq) && contentList[2].TryGetText(out string rebindInfo)) { rebindInfo = rebindInfo.Trim(); var match = Regex.Match( input: rebindInfo, pattern: "^(" + OsuHelper.UsernamePattern + @")\s*[::]\s*(.+?)$" ); if (!match.Success) { return(false); } _username = match.Groups[1].Value; _reason = match.Groups[2].Value; return(true); } return(false); }
public async Task OnMessageAsync(MessageContext message, HttpApiClient api) { if (!s_baicaiCommands.Any(c => message.Content.Text.Contains(c))) { return; } var uid = await _dataProvider.GetOsuIdAsync(message.UserId).ConfigureAwait(false); Mode?mode = null; // TODO: Use binding from mothership database first. if (uid != null) { if (mode != null) { await _dataMaintainer.UpdateAsync(uid.Value, mode.Value).ConfigureAwait(false); } else { foreach (Mode m in Enum.GetValues(typeof(Mode))) { await _dataMaintainer.UpdateAsync(uid.Value, m).ConfigureAwait(false); } } } }
public bool ShouldResponse(MessageContext context) { if (context.Content.TryGetPlainText(out string text)) { if (RegexCommand(s_selfRegex, text)) { QQId = context.UserId; return(true); } return(RegexCommand(s_whereRegex, text) || RegexCommand(s_whereQQRegex, text)); } else if (context.Content.Sections.Select(f => f.Type).SequenceEqual(s_cqCodeSeq) && RegexCommand(s_queryPrefixRegex, context.Content.Sections[0].Data["text"])) { QQId = long.Parse(context.Content.Sections[1].Data["qq"]); return(true); } else if (context.Content.Sections.Select(f => f.Type).SequenceEqual(s_cqCodeSeq2) && RegexCommand(s_queryPrefixRegex, context.Content.Sections[0].Data["text"]) && RegexCommand(s_querySuffixRegex, context.Content.Sections[2].Data["text"])) { QQId = long.Parse(context.Content.Sections[1].Data["qq"]); return(true); } return(false); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { _newbieContext.RemoveRange(_newbieContext.Recommendations); await _newbieContext.SaveChangesAsync().ConfigureAwait(false); await api.SendMessageAsync(context.Endpoint, "清除完成。"); }
private async Task Init(MessageContext context, HttpApiClient api) { var sb = new StringBuilder(); if (s_cache.TryGetValue(context.UserId, out ExecuteInfo exec)) { sb.AppendLine("当前游戏正在进行。"); } else { exec = s_cache.Set(context.UserId, new ExecuteInfo(), new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(10) }); } sb.Append("你有").Append(Max).Append("枚重量各不相同的金币,编号为1-").Append(Max).Append(@",和一个天平。你可以用天平比较两枚金币的重量。 你的目标是:称最少的次数(").Append(Max).Append(" 枚金币 ").Append(Best).Append(@" 次),将这些金币按从轻到重排序 你可以使用指令“称xy”来比较两枚金币的重量,其中x、y都是金币编号。 例如:称12 你无须提交排序结果,消防栓会自动检测你能否排出来。 ------ "); string info = GetInfo(exec.GetKnown(out _)); sb.Append(info); string message = sb.ToString(); await api.SendMessageAsync(context.Endpoint, message).ConfigureAwait(false); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { using var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false); await page.SetViewportAsync(new ViewPortOptions { DeviceScaleFactor = 3, Width = 360, Height = 8000, }).ConfigureAwait(false); await page.GoToAsync("https://toyokeizai.net/sp/visual/tko/covid19/en.html").ConfigureAwait(false); await page.WaitForSelectorAsync("#main-block > div:nth-child(2) > div:nth-child(1) > div > div.charts-wrapper > div.main-chart-wrapper > div > canvas").ConfigureAwait(false); var element = await page.QuerySelectorAsync("#main-block > div:nth-child(2)").ConfigureAwait(false); await page.SetViewportAsync(new ViewPortOptions { DeviceScaleFactor = 2, Width = 1024, Height = 4000, }).ConfigureAwait(false); var data2 = await element.ScreenshotDataAsync(new ScreenshotOptions { Type = ScreenshotType.Jpeg, Quality = 100, }).ConfigureAwait(false); await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data2)).ConfigureAwait(false); }
public async Task ProcessAsync(Sisters.WudiLib.Posts.Message message, HttpApiClient api) { // TODO 验证用户名是否合法 var(success, userInfo) = await OsuApi.GetUserInfoAsync(_userName, OsuMixedApi.Mode.Standard); if (!success) { await api.SendMessageAsync(message.Endpoint, "网络错误。"); return; } if (userInfo == null) { await api.SendMessageAsync(message.Endpoint, "没有此用户。"); return; } var dbResult = await Database.AddNewBindAsync(message.UserId, userInfo.Id, userInfo.Name, "自己绑定", message.UserId, userInfo.Name); if (dbResult.Success) { await api.SendMessageAsync(message.Endpoint, $"成功绑定为{userInfo.Name}。"); } else if (dbResult.Exception is DbUpdateException && dbResult.Exception.InnerException?.Message.Contains("Duplicate", StringComparison.Ordinal) == true) { await api.SendMessageAsync(message.Endpoint, "在已绑定的情况下不允许修改,如需修改请联系 bleatingsheep。"); } else { await api.SendMessageAsync(message.Endpoint, "数据库访问错误。"); FLogger.LogException(dbResult.Exception); } }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { string url = "https://rsshub.app/pixiv/ranking/day"; var xmlReader = XmlReader.Create(url); var feed = SyndicationFeed.Load(xmlReader); var tuple = feed.Items.Select(i => { var doc = new HtmlDocument(); doc.LoadHtml(i.Summary.Text); return(item: i, nodes: doc.DocumentNode.SelectNodes("//p/img")); }).Randomize().FirstOrDefault(t => t.nodes.Count == 1); var(item, imgNode) = (tuple.item, tuple.nodes?.First()); if (imgNode != null) { var imgUrl = imgNode.Attributes["src"].Value; if (await api.SendMessageAsync( endpoint: context.Endpoint, message: new Message(item.Title.Text + "\r\n") + Message.NetImage(imgUrl) + new Message("\r\n" + item.Links.FirstOrDefault().Uri) ) == null) { await api.SendMessageAsync(context.Endpoint, "图片发送失败。"); } } else { await api.SendMessageAsync(context.Endpoint, "没有符合要求的图片。"); } }
public async Task OnMessageAsync(MessageContext message, HttpApiClient api) { if (s_stopwatch == null) { s_stopwatch = Stopwatch.StartNew(); } if (s_nextCheck < s_stopwatch.ElapsedMilliseconds) { const int IntervalMilliseconds = 10 * 60_000; s_nextCheck = s_stopwatch.ElapsedMilliseconds + IntervalMilliseconds; var cmbc = await HttpApi.Resolve <ICmbcCreditRate>().GetRates().ConfigureAwait(false); var cmbcJson = JsonSerializer.Serialize(cmbc); if (cmbcJson != s_cmbcJson) { s_cmbcJson = cmbcJson; _logger.LogInformation($"CMBC Changed: {cmbcJson}"); } var cib = await HttpApi.Resolve <ICibRate>().GetRates().ConfigureAwait(false); var cibJson = JsonSerializer.Serialize(cib); if (cibJson != s_cibJson) { s_cibJson = cibJson; _logger.LogInformation($"CIB Changed: {cibJson}"); } } }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { using var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false); await page.SetViewportAsync(new ViewPortOptions { DeviceScaleFactor = 3.5, Width = 800, Height = 1000, }).ConfigureAwait(false); await page.GoToAsync("https://www.investing.com/indices/us-spx-500-futures").ConfigureAwait(false); const string selector = "#quotes_summary_current_data"; var element = await page.QuerySelectorAsync(selector).ConfigureAwait(false); var data = await element.ScreenshotDataAsync(new ScreenshotOptions { Type = ScreenshotType.Png, }).ConfigureAwait(false); bool inLoop = true; int retry = 3; do { var mesResponse = await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false); inLoop = mesResponse == null; } while (inLoop && --retry > 0); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { var bi = await _newbieContext.Bindings.Where(b => b.UserId == context.UserId).FirstOrDefaultAsync().ConfigureAwait(false); if (bi == null) { return; } var osuId = bi.OsuId; var best = await _osuApiClient.GetUserBest(osuId).ConfigureAwait(false); var sb = new StringBuilder(); foreach (var b in best.Take(4)) { sb.Append("根据您的 BP b/").Append(b.BeatmapId).Append(" + ").Append(b.EnabledMods.Display()).AppendLine(" 推荐:"); var id = RecommendationBeatmapId.Create(b, Mode.Standard); var rec = await _newbieContext.Recommendations .Where(r => r.Left == id) .OrderByDescending(r => r.RecommendationDegree) .Take(4) .ToListAsync().ConfigureAwait(false); _ = rec.Aggregate(sb, (sb, r) => sb.Append("b/").Append(r.Recommendation.BeatmapId).Append(" + ").AppendLine(r.Recommendation.ValidMods.Display())); } await api.SendMessageAsync(context.Endpoint, sb.ToString()).ConfigureAwait(false); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { await api.SendMessageAsync( context.Endpoint, "请去 https://help.b11p.com/" + " 查看 osu! 相关帮助。页面右侧可以查看其他相关帮助。" ).ConfigureAwait(false); }
private async Task Weigh(MessageContext context, HttpApiClient api) { if (!s_cache.TryGetValue <ExecuteInfo>(context.UserId, out var exec)) { await api.SendMessageAsync(context.Endpoint, "你未开始游戏!").ConfigureAwait(false); return; } if (_left <= 0 || _left > Max || _right <= 0 || _right > Max) { await api.SendMessageAsync(context.Endpoint, "称量金币错误。").ConfigureAwait(false); return; } if (_left == _right) { await api.SendMessageAsync(context.Endpoint, "你怎么把一枚金币放到天平两边?").ConfigureAwait(false); return; } var sb = new StringBuilder(); var cp = exec.Weigh(_left, _right, out bool isClear, out bool isKnown, out IList <int>?result); if (isKnown) { sb.AppendLine("你已经知道哪边更重了,不是吗?"); } sb.Append(GetInfo(cp)); if (isClear) { s_cache.Remove(context.UserId); sb.Append("\r\n恭喜排序完成,共称了").Append(exec.WeighingCount).Append("次。"); if (exec.WeighingCount <= Best) { await api.SendMessageAsync(context.Endpoint, "恭喜达到最优次数!").ConfigureAwait(false); if (Max > 8) #pragma warning disable CS0162 // Unreachable code detected { await api.SendPrivateMessageAsync(962549599, $"{context.UserId} 达到最优 {Best} 次!").ConfigureAwait(false); } #pragma warning restore CS0162 // Unreachable code detected await api.SendPrivateMessageAsync(962549599, GetInfo(cp)).ConfigureAwait(false); } if (result != null) { sb.AppendLine().AppendLine("从轻到重分别为:").AppendJoin(", ", result); } } string message = sb.ToString(); await api.SendMessageAsync(context.Endpoint, message).ConfigureAwait(false); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { var result = await IPLocation.IPLocator.Default.GetLocationAsync(_address).ConfigureAwait(false); await api.SendMessageAsync(context.Endpoint, result switch { (false, _) => "查询失败。", (true, null) => "未找到结果。", (true, var l) => l.ToString(), }).ConfigureAwait(false);
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { using var db = _newbieContext.Value; var bindingInfo = await db.Bindings.FirstOrDefaultAsync(b => b.UserId == context.UserId).ConfigureAwait(false); if (bindingInfo is null) { return; } var url = $"https://www.mothership.top/api/v1/stat/{bindingInfo.OsuId}"; await api.SendMessageAsync(context.Endpoint, Message.NetImage(url, true)).ConfigureAwait(false); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { string url = "https://rss.bleatingsheep.org/zhihu/daily"; var xmlReader = XmlReader.Create(url); var feed = SyndicationFeed.Load(xmlReader); xmlReader.Close(); var item = feed.Items.LastOrDefault(); if (item != default) { bool modified = false; var doc = new HtmlDocument(); var htmlText = item.Summary.Text; doc.LoadHtml(htmlText); foreach (var imgNode in doc.DocumentNode.SelectNodes("//div/div/div/div/div/p/img")?.Where(n => n.GetClasses().FirstOrDefault() == "content-image") ?? Enumerable.Empty <HtmlNode>()) { imgNode.SetAttributeValue("width", "100%"); modified = true; } if (modified) { htmlText = doc.DocumentNode.InnerHtml; } using (var page = await Chrome.OpenNewPageAsync()) { await page.SetContentAsync(htmlText); await page.SetViewportAsync(new ViewPortOptions { DeviceScaleFactor = 1.5, Width = 360, Height = 640, }); var data = await page.ScreenshotDataAsync(new ScreenshotOptions { FullPage = true, }); await Task.Delay(100); var sendCode = await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)); if (sendCode == null) { Logger.Info("知乎日报发送失败。"); } } } }
public bool ShouldResponse(Sisters.WudiLib.Posts.Message message) { if (message.Content.IsPlaintext) { _trimed = message.Content.Text.TrimStart(); if (_trimed.StartsWith(StartCommand, StringComparison.InvariantCultureIgnoreCase)) { _userName = _trimed.Substring(StartCommand.Length).Trim(); return(Bleatingsheep.Osu.Helper.UserNameHelper.IsUserName(_userName)); } } return(false); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { Logger.Debug($"开始读取 URL {Url} "); using (var httpClient = new HttpClient()) { var data = await httpClient.GetByteArrayAsync(Url); Logger.Debug($"取到 {data.Length} 字节数据。"); var sendResponse = await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)); Logger.Debug($"发送结果:消息 ID {sendResponse?.MessageId.ToString(CultureInfo.InvariantCulture) ?? "null"}"); } }
public async Task ProcessAsync(Message message, HttpApiClient api) { var k = new Api("https://konachan.net"); var recent = await k.PopularRecentAsync(); if (recent == null) { return; } recent = recent.Where(p => !p.tags.Split().Intersect(DissTags).Any()).Take(1); foreach (var post in recent) { await api.SendMessageAsync(message.Endpoint, SendingMessage.NetImage(post.JpegUrl)); } }
public bool ShouldResponse(MessageContext context) { if (context.Content.TryGetPlainText(out string text)) { if (string.Equals(text, "称金币", StringComparison.Ordinal)) { _isInit = true; return(true); } else if (Regex.IsMatch(text.Trim(), @"^称\d\d$", RegexOptions.Compiled)) { _left = int.Parse(text.Trim().Substring(1, 1)); _right = int.Parse(text.Trim().Substring(2, 1)); return(true); } } return(false); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { int uid; Mode mode; try { mode = ModeExtensions.Parse(ModeString); } catch { mode = default; } if (string.IsNullOrEmpty(Name)) { uid = await EnsureGetBindingIdAsync(context.UserId).ConfigureAwait(false); } else { var user = await EnsureGetUserInfo(Name, Mode.Standard).ConfigureAwait(false); uid = user.Id; } string url = $"https://info.osustuff.ri.mk/cn/users/{uid}/{s_modes.GetValueOrDefault(mode)}"; using var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false); await page.SetViewportAsync(new ViewPortOptions { DeviceScaleFactor = Math.Sqrt(0.5), Width = 1058, Height = 80, }).ConfigureAwait(false); _ = await page.GoToAsync(url, WaitUntilNavigation.Networkidle0).ConfigureAwait(false); await page.WaitForTimeoutAsync(500).ConfigureAwait(false); var data = await page.ScreenshotDataAsync(new ScreenshotOptions { FullPage = true, Type = ScreenshotType.Jpeg, Quality = 100, }).ConfigureAwait(false); _ = await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false); }
public async Task OnMessageAsync(MessageContext message, HttpApiClient api) { if (s_cache.TryGetValue(message.UserId, out _)) { return; } s_cache.Set(message.UserId, DateTimeOffset.Now, TimeSpan.FromHours(1)); var uid = await _dataProvider.GetOsuIdAsync(message.UserId).ConfigureAwait(false); if (uid is null) { return; } var tasks = new[] { _dataMaintainer.UpdateAsync(uid.Value, Mode.Standard), _dataMaintainer.UpdateAsync(uid.Value, Mode.Taiko), _dataMaintainer.UpdateAsync(uid.Value, Mode.Catch), _dataMaintainer.UpdateAsync(uid.Value, Mode.Mania), }; await Task.WhenAll(tasks).ConfigureAwait(false); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { Mode?mode = default(Mode); try { if (!string.IsNullOrWhiteSpace(ModeString)) { mode = ModeExtensions.Parse(ModeString); } } catch { // Ignore when the mode string is invalid. return; } Message message; if (QQId != default) { var bindingInfo = await NewbieContext.Bindings.Where(b => b.UserId == QQId).FirstOrDefaultAsync().ConfigureAwait(false); if (bindingInfo is null) { await api.SendMessageAsync(context.Endpoint, "未绑定 osu! 账号。").ConfigureAwait(false); return; } var osuId = bindingInfo.OsuId; message = await QueryHelper.QueryByUserId(osuId, mode).ConfigureAwait(false); } else if (!string.IsNullOrEmpty(Name)) { message = await QueryHelper.QueryByUserName(Name, mode).ConfigureAwait(false); } else { return; } object sendResponse = null; if (!_memoryCache.TryGetValue(SendingFailureCacheKey, out int t) || t < Threshold) { sendResponse = await api.SendMessageAsync(context.Endpoint, message).ConfigureAwait(false); } if (sendResponse is null) { // 可能会假失败,即消息发出去了,但检测到失败。 //await api.SendMessageAsync(context.Endpoint, $"检测到发送失败,消息长度为{message.Raw.Length},[调试]将转换成 base64 发送。").ConfigureAwait(false); //await api.SendMessageAsync(context.Endpoint, Convert.ToBase64String(Encoding.UTF8.GetBytes(message.Raw))).ConfigureAwait(false); // 记录发送失败次数。72小时内失败2次即转图。 // 不是完全线程安全。 t = _memoryCache.Set(SendingFailureCacheKey, t + 1, new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(3), Priority = CacheItemPriority.NeverRemove, SlidingExpiration = TimeSpan.FromDays(1), }); var text = message.Sections[0].Data["text"]; using var sr = new System.IO.StringReader(text); var lines = new List <string>(); while (sr.ReadLine() is string line) { // 分行发送发送失败的消息 //await api.SendMessageAsync(context.Endpoint, line).ConfigureAwait(false); lines.Add(line); } //lines.Add(string.Empty); //lines.Add("// 有会 html/css 的帮我弄好看点吗? 斜杠可怜"); using var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false); await page.SetViewportAsync(new ViewPortOptions { DeviceScaleFactor = 3, Width = 360, Height = 202, }).ConfigureAwait(false); var style = "font-family: 'Source Han Sans CN', sans-serif;"; await page.SetContentAsync($@"<div lang=""zh-CN"" style=""{style}"">{string.Join("<br>", lines.Select(HttpUtility.HtmlEncode))}</div>").ConfigureAwait(false); var data = await page.ScreenshotDataAsync(new ScreenshotOptions { FullPage = true, }).ConfigureAwait(false); await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false); } }
public bool ShouldResponse(Message message) { return(message.Content.Text.StartsWith("健康konachan", StringComparison.InvariantCultureIgnoreCase)); }
public bool ShouldResponse(MessageContext context) => context.Content.TryGetPlainText(out string text) && text == "标普500";
public bool ShouldResponse(MessageContext context) => context.UserId == 962549599 && RegexCommand(s_regex, context.Content);
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { var uid = await EnsureGetBindingIdAsync(context.UserId).ConfigureAwait(false); var apiTask = OsuApi.GetUserInfoAsync(uid, Bleatingsheep.Osu.Mode.Standard).ConfigureAwait(false); using (var page = await Chrome.OpenNewPageAsync().ConfigureAwait(false)) { await page.SetViewportAsync(new ViewPortOptions { DeviceScaleFactor = 2.75, Width = 1440, Height = 900, }).ConfigureAwait(false); await page.GoToAsync($"https://osu.ppy.sh/users/{uid}/osu").ConfigureAwait(false); // wait for load complete const string waitSelector = @"body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2)"; await page.WaitForSelectorAsync(waitSelector).ConfigureAwait(false); const string bestSelector = "body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2) > div > div.play-detail-list"; //ElementHandle bpsElement = await page.QuerySelectorAsync(bestSelector).ConfigureAwait(false); const string buttonSelector = "body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2) > div > div.profile-extra-entries__item > button"; ElementHandle button = await page.QuerySelectorAsync(buttonSelector).ConfigureAwait(false); ElementHandle[]? bpList = default; int maxTryTimes = 4; while (button != null && maxTryTimes-- != 0) { //check bp counts. bpList = await page.QuerySelectorAllAsync(bestSelector + " > div").ConfigureAwait(false); await button.ClickAsync().ConfigureAwait(false); // wait for click complete await page.WaitForSelectorAsync(bestSelector + $" > div:nth-child({bpList.Length})", new WaitForSelectorOptions { Timeout = 8000 /*ms*/ }).ConfigureAwait(false); // seems that bp div adding and button availability changing is NOT synchronized // wait for button availability change await page.WaitForTimeoutAsync(500).ConfigureAwait(false); // requery button button = await page.QuerySelectorAsync(buttonSelector).ConfigureAwait(false); } if (bpList == null) { await api.SendMessageAsync(context.Endpoint, "查询失败。").ConfigureAwait(false); return; } // filter /* * bpList = document.querySelectorAll("body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2) > div > div.play-detail-list > div"); * * bpList.forEach((element) => { var dateTime = element.querySelector("div.play-detail__group.play-detail__group--top > div.play-detail__detail > div > span.play-detail__time > time").getAttribute("datetime"); if (new Date() - Date.parse(dateTime) > 86400000) element.remove(); }) */ await page.EvaluateExpressionAsync(@"bpList = document.querySelectorAll(""body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.osu-layout__section.osu-layout__section--users-extra > div > div > div > div:nth-child(2) > div > div.play-detail-list > div"");").ConfigureAwait(false); await page.EvaluateExpressionAsync(@"bpList.forEach((element) => { var dateTime = element.querySelector(""div.play-detail__group.play-detail__group--top > div.play-detail__detail > div > span.play-detail__time > time"").getAttribute(""datetime""); if (new Date() - Date.parse(dateTime) > 86400000) element.remove(); })").ConfigureAwait(false); // check bpList = await page.QuerySelectorAllAsync(bestSelector + " > div").ConfigureAwait(false); if (bpList.Length == 0) { await api.SendMessageAsync(context.Endpoint, "最近 24 小时没有更新 bp。").ConfigureAwait(false); return; } //screenshot //delete pinned elements await(await page.QuerySelectorAsync("body > div.js-pinned-header.hidden-xs.no-print.nav2-header > div.nav2-header__body").ConfigureAwait(false)).EvaluateFunctionAsync(@"(element) => element.remove()").ConfigureAwait(false); await(await page.QuerySelectorAsync("body > div.osu-layout__section.osu-layout__section--full.js-content.community_profile > div > div > div > div.hidden-xs.page-extra-tabs.page-extra-tabs--profile-page.js-switchable-mode-page--scrollspy-offset").ConfigureAwait(false)).EvaluateFunctionAsync(@"(element) => element.remove()").ConfigureAwait(false); // add extra information await page.EvaluateExpressionAsync($@"document.querySelector(""{bestSelector}"").parentElement.parentElement.querySelector(""h3"").textContent += "" (用户名:"" + {JsonConvert.SerializeObject((await apiTask).Item2?.Name ?? "获取失败")} + "" 查询时间:"" + {JsonConvert.SerializeObject(DateTime.Now.ToString("yyyy-MM-dd H:mm)"))}").ConfigureAwait(false); //ElementHandle printElement = await page.QuerySelectorAsync(bestSelector).ConfigureAwait(false); var printElement = await(await page.QuerySelectorAsync(bestSelector).ConfigureAwait(false)) .EvaluateFunctionHandleAsync("(element) => element.parentNode.parentNode").ConfigureAwait(false) as ElementHandle; printElement ??= await page.QuerySelectorAsync(bestSelector).ConfigureAwait(false); var data = await printElement.ScreenshotDataAsync(new ScreenshotOptions()).ConfigureAwait(false); await api.SendMessageAsync(context.Endpoint, Message.ByteArrayImage(data)).ConfigureAwait(false); } }
public bool ShouldResponse(MessageContext context) => context.Content.TryGetPlainText(out var text) &&
public bool ShouldResponse(MessageContext context) { return(context.UserId == 962549599 && context.Content.TryGetPlainText(out string text) && text == "重启浏览器"); }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { await Chrome.RefreashBrowserAsync().ConfigureAwait(false); await api.SendMessageAsync(context.Endpoint, "重启完毕。").ConfigureAwait(false); }