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 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); }