From 360c75fa6c9c937508c8702c6fb95cbbe04a60d9 Mon Sep 17 00:00:00 2001 From: yiyun Date: Tue, 19 Apr 2022 01:26:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(qqstatplugin):=20=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=90=91=20ChartGroups=20=E5=8F=91=E9=80=81=E6=8A=98=E7=BA=BF?= =?UTF-8?q?=E5=9B=BE=20=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/QQStatPlugin/QQStatPlugin.cs | 58 +++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/plugins/QQStatPlugin/QQStatPlugin.cs b/plugins/QQStatPlugin/QQStatPlugin.cs index 4cf4de88c..a2273a825 100644 --- a/plugins/QQStatPlugin/QQStatPlugin.cs +++ b/plugins/QQStatPlugin/QQStatPlugin.cs @@ -11,11 +11,19 @@ using Konata.Core.Message.Model; using Konata.Core.Common; using System.Text; +using QQBotHub.Sdk; +using Konata.Core.Message; +using System.Collections.Generic; namespace QQStatPlugin { - public class QQStatPlugin : BasePlugin, IQQBotPlugin + public class QQStatPlugin : BasePlugin, IQQBotPlugin, ITimeJobPlugin { + /// + /// 43200 = 12 小时 + /// + public long SecondsPeriod => 43200; + public override (bool IsSuccess, string Message) AfterEnable() { Console.WriteLine($"{nameof(QQStatPlugin)}: {nameof(AfterEnable)}"); @@ -99,7 +107,7 @@ public void OnGroupMessage((Bot s, GroupMessageEvent e) obj, string message, str else if (message.Contains("#折线")) { #region 折线 - SendStackedArea(obj, message, groupUin, memberUin, settingsModel); + SendStackedArea(obj: obj, message: message, groupUin: groupUin, settingsModel: settingsModel, memberUin: memberUin); #endregion } } @@ -179,6 +187,42 @@ public void OnBotOffline((Bot s, BotOfflineEvent e) obj, string botName, uint bo #endregion + #region 定时任务 + public async Task ExecuteAsync() + { + try + { + SettingsModel settingsModel = PluginCore.PluginSettingsModelFactory.Create(nameof(QQStatPlugin)); + if (QQBotStore.Bot != null && QQBotStore.Bot.IsOnline()) + { + var groupList = await QQBotStore.Bot.GetGroupList(forceUpdate: true); + foreach (var group in groupList) + { + if (settingsModel.ChartGroups.Contains(group.Uin.ToString())) + { + SendStackedArea((QQBotStore.Bot, null), message: "#折线", groupUin: group.Uin, settingsModel: settingsModel); + + List baseChains = new List() + { + TextChain.Create("发送 #帮助 获取更多信息") + }; + + await QQBotStore.Bot.SendGroupMessage(groupUin: group.Uin, baseChains.ToArray()); + } + } + + } + } + catch (Exception ex) + { + Console.WriteLine($"执行定时任务失败: {ex.ToString()}"); + } + + await Task.CompletedTask; + } + #endregion + + public void SendCalendar((Bot s, GroupMessageEvent e) obj, string message, uint groupUin, uint memberUin, SettingsModel settingsModel) { string token = Guid.NewGuid().ToString(); @@ -216,7 +260,7 @@ public void SendCalendar((Bot s, GroupMessageEvent e) obj, string message, uint } } - public void SendStackedArea((Bot s, GroupMessageEvent e) obj, string message, uint groupUin, uint memberUin, SettingsModel settingsModel) + public void SendStackedArea((Bot s, GroupMessageEvent e) obj, string message, uint groupUin, SettingsModel settingsModel, uint memberUin = 0) { string token = Guid.NewGuid().ToString(); Controllers.StackedAreaController.CreateTime = DateTime.Now; @@ -240,8 +284,11 @@ public void SendStackedArea((Bot s, GroupMessageEvent e) obj, string message, ui { var image = ImageChain.CreateFromUrl(imageUrl); obj.s.SendGroupMessage(groupUin, image); - obj.s.SendGroupPoke(groupUin: groupUin, memberUin: memberUin); - obj.s.SendGroupMessage(groupUin, AtChain.Create(memberUin)); + if (memberUin > 0) + { + obj.s.SendGroupPoke(groupUin: groupUin, memberUin: memberUin); + obj.s.SendGroupMessage(groupUin, AtChain.Create(memberUin)); + } } catch (Exception ex) { @@ -253,5 +300,6 @@ public void SendStackedArea((Bot s, GroupMessageEvent e) obj, string message, ui } } + } }