Skip to content

Commit

Permalink
feat(plugins/qqstatplugin/): #排行榜
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Jan 24, 2023
1 parent b4f4ed0 commit fde90ae
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
19 changes: 19 additions & 0 deletions plugins/QQStatPlugin/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,24 @@ public async static Task<long> Count()
}
}

public async static Task<IEnumerable<(string QQUin, long TotalContentLen)>> 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
});
}
}

}
}
37 changes: 37 additions & 0 deletions plugins/QQStatPlugin/QQStatPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Konata.Core.Message;
using System.Collections.Generic;
using KonataPlugin;
using System.Linq;

namespace QQStatPlugin
{
Expand Down Expand Up @@ -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("折线为 计算消息字数");
Expand All @@ -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<BaseChain> baseChains = new List<BaseChain>();
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
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions plugins/QQStatPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

## 聊天功能

### `#帮助`

### `#日历`

> 需要设置 `BaseUrl`, `ScreenshotUrl`, `ScreenshotUrl` 保持默认即可
Expand All @@ -21,7 +23,11 @@

### `#折线`

> 本群折线图
### `#排行榜`

> 查询在本群的发言字数排行榜

## 其它
Expand All @@ -30,3 +36,6 @@
- [下载数据库 (QQStatPlugin.sqlite)](/Plugins/QQStatPlugin/Download)

<!-- Matomo Image Tracker-->
<img referrerpolicy="no-referrer-when-downgrade" src="https://matomo.moeci.com/matomo.php?idsite=2&amp;rec=1&amp;action_name=Plugins.QQStatPlugin.README" style="border:0" alt="" />
<!-- End Matomo -->
2 changes: 1 addition & 1 deletion plugins/QQStatPlugin/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"DisplayName": "QQ消息统计分析",
"Description": "QQ消息等数据收集, 分析",
"Author": "yiyun",
"Version": "1.0.1",
"Version": "1.1.0",
"SupportedVersions": [ "0.0.1" ]
}

0 comments on commit fde90ae

Please sign in to comment.