From fde90ae0cc697f520f64e126436f4072aebe44ab Mon Sep 17 00:00:00 2001 From: yiyun Date: Tue, 24 Jan 2023 15:27:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugins/qqstatplugin/):=20#=E6=8E=92?= =?UTF-8?q?=E8=A1=8C=E6=A6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/QQStatPlugin/DbContext.cs | 19 ++++++++++++++ plugins/QQStatPlugin/QQStatPlugin.cs | 37 ++++++++++++++++++++++++++++ plugins/QQStatPlugin/README.md | 9 +++++++ plugins/QQStatPlugin/info.json | 2 +- 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/plugins/QQStatPlugin/DbContext.cs b/plugins/QQStatPlugin/DbContext.cs index c84abbb9c..126addac9 100644 --- a/plugins/QQStatPlugin/DbContext.cs +++ b/plugins/QQStatPlugin/DbContext.cs @@ -69,5 +69,24 @@ public async static Task Count() } } + public async static Task> TopByGroup(string groupUin) + { + using (IDbConnection con = new SQLiteConnection(ConnStr)) + { + con.Open(); + + string sql = @"SELECT QQUin, SUM(ContentLen) AS TotalContentLen + FROM(SELECT Id, QQUin, LENGTH(Content) AS ContentLen FROM Message WHERE GroupUin = @GroupUin) + GROUP BY QQUin + ORDER BY TotalContentLen DESC + LIMIT 10;"; + + return await con.QueryAsync<(string QQUin, long TotalContentLen)>(sql, new + { + GroupUin = groupUin + }); + } + } + } } diff --git a/plugins/QQStatPlugin/QQStatPlugin.cs b/plugins/QQStatPlugin/QQStatPlugin.cs index a89aab953..73691e3d5 100644 --- a/plugins/QQStatPlugin/QQStatPlugin.cs +++ b/plugins/QQStatPlugin/QQStatPlugin.cs @@ -13,6 +13,7 @@ using Konata.Core.Message; using System.Collections.Generic; using KonataPlugin; +using System.Linq; namespace QQStatPlugin { @@ -92,6 +93,7 @@ public void OnGroupMessage((Bot s, GroupMessageEvent e) obj, string message, str stringBuilder.AppendLine("#日历 指定某人QQ"); stringBuilder.AppendLine("#折线"); stringBuilder.AppendLine("#折线 指定某人QQ"); + stringBuilder.AppendLine("#排行榜"); stringBuilder.AppendLine("补充:"); stringBuilder.AppendLine("日历为 计算消息字数"); stringBuilder.AppendLine("折线为 计算消息字数"); @@ -117,6 +119,41 @@ public void OnGroupMessage((Bot s, GroupMessageEvent e) obj, string message, str } #endregion } + else if (message.Contains("#排行榜")) + { + #region 排行榜 + try + { + var memeberList = obj.s.GetGroupMemberList(groupUin: groupUin, forceUpdate: true).Result.ToList() + .Select(m => (m.Name, m.Uin)).ToList(); + var memeberUinList = memeberList.Select(m => m.Uin).ToList(); + + var topByGroupList = DbContext.TopByGroup(groupUin: groupUin.ToString()).Result.ToList(); + List baseChains = new List(); + baseChains.Add(TextChain.Create("本群发言排行榜 (总字数)")); + for (int i = 0; i < topByGroupList.Count; i++) + { + baseChains.Add(TextChain.Create($"{(i + 1)}: ")); + baseChains.Add(TextChain.Create($"总字数: {topByGroupList[i].TotalContentLen} ")); + if (memeberUinList.Contains(uint.Parse(topByGroupList[i].QQUin))) + { + baseChains.Add(AtChain.Create(uint.Parse(topByGroupList[i].QQUin))); + } + else + { + baseChains.Add(TextChain.Create($"@{topByGroupList[i].QQUin}")); + } + baseChains.Add(TextChain.Create("\r\n")); + } + obj.s.SendGroupMessage(groupUin, baseChains.ToArray()); + } + catch (Exception ex) + { + Console.WriteLine("发送 排行榜 失败:"); + Console.WriteLine(ex.ToString()); + } + #endregion + } } } } diff --git a/plugins/QQStatPlugin/README.md b/plugins/QQStatPlugin/README.md index b69564795..ec137aeb5 100644 --- a/plugins/QQStatPlugin/README.md +++ b/plugins/QQStatPlugin/README.md @@ -10,6 +10,8 @@ ## 聊天功能 +### `#帮助` + ### `#日历` > 需要设置 `BaseUrl`, `ScreenshotUrl`, `ScreenshotUrl` 保持默认即可 @@ -21,7 +23,11 @@ ### `#折线` +> 本群折线图 + +### `#排行榜` +> 查询在本群的发言字数排行榜 ## 其它 @@ -30,3 +36,6 @@ - [下载数据库 (QQStatPlugin.sqlite)](/Plugins/QQStatPlugin/Download) + + + diff --git a/plugins/QQStatPlugin/info.json b/plugins/QQStatPlugin/info.json index da2c46e7c..587e9855f 100644 --- a/plugins/QQStatPlugin/info.json +++ b/plugins/QQStatPlugin/info.json @@ -3,6 +3,6 @@ "DisplayName": "QQ消息统计分析", "Description": "QQ消息等数据收集, 分析", "Author": "yiyun", - "Version": "1.0.1", + "Version": "1.1.0", "SupportedVersions": [ "0.0.1" ] } \ No newline at end of file