@zhin.js/plugin-group-suite 3.0.5 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/checkin.js +11 -0
- package/commands/forget.js +10 -0
- package/commands/keyword-add/[keyword:string].js +15 -0
- package/commands/keyword-list.js +14 -0
- package/commands/keyword-remove/[keyword:string].js +15 -0
- package/commands/mypoints.js +10 -0
- package/commands/mystats.js +10 -0
- package/commands/rank.js +11 -0
- package/commands/stats-rank.js +13 -0
- package/commands/stats-week.js +13 -0
- package/commands/stats.js +14 -0
- package/commands/teach-list/[page:number=1].js +12 -0
- package/commands/teach-regex.js +11 -0
- package/commands/teach.js +11 -0
- package/middlewares/keyword-reply.js +36 -0
- package/middlewares/stats-count.js +20 -0
- package/middlewares/teach-reply.js +21 -0
- package/package.json +9 -9
- package/plugin.js +37 -0
- package/tools/checkin-query/handler.js +22 -0
- package/tools/checkin-rank/handler.js +15 -0
- package/tools/stats-query/handler.js +28 -0
- package/tools/stats-user/handler.js +29 -0
- package/plugin.ts +0 -39
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { doCheckin } from "../lib/checkin-lib.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
description: '每日签到获得积分',
|
|
8
|
+
execute({ config, input, owner, use }) {
|
|
9
|
+
return doCheckin(input ?? {}, resolveGroupSuiteConfig(config), resolveGroupSuiteRuntime({ owner, use }));
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { teachForget } from "../lib/teach-lib.js";
|
|
4
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
description: '忘记问答(删除问答对)',
|
|
7
|
+
execute({ input, args, owner, use }) {
|
|
8
|
+
return teachForget(input ?? {}, args.join(' '), resolveGroupSuiteRuntime({ owner, use }));
|
|
9
|
+
},
|
|
10
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { addKeyword } from "../../lib/keyword-store.js";
|
|
4
|
+
import { resolveGroupSuiteRuntime } from "../../lib/runtime-state.js";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
description: '添加关键词自动回复',
|
|
7
|
+
execute({ params, args, owner, use }) {
|
|
8
|
+
const keyword = String(params.keyword ?? '');
|
|
9
|
+
const reply = args.join(' ').trim();
|
|
10
|
+
if (!keyword || !reply)
|
|
11
|
+
return '请提供关键词和回复内容';
|
|
12
|
+
addKeyword(keyword, reply, resolveGroupSuiteRuntime({ owner, use })?.keywords);
|
|
13
|
+
return `已添加关键词「${keyword}」→「${reply}」`;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { listKeywords } from "../lib/keyword-store.js";
|
|
4
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
description: '查看所有关键词回复对',
|
|
7
|
+
execute({ owner, use }) {
|
|
8
|
+
const entries = listKeywords(resolveGroupSuiteRuntime({ owner, use })?.keywords);
|
|
9
|
+
if (entries.length === 0)
|
|
10
|
+
return '当前没有设置任何关键词';
|
|
11
|
+
const lines = entries.map(([k, v], i) => `${i + 1}. 「${k}」→「${v}」`);
|
|
12
|
+
return `关键词列表(共 ${entries.length} 条):\n${lines.join('\n')}`;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { removeKeyword } from "../../lib/keyword-store.js";
|
|
4
|
+
import { resolveGroupSuiteRuntime } from "../../lib/runtime-state.js";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
description: '删除关键词自动回复',
|
|
7
|
+
execute({ params, owner, use }) {
|
|
8
|
+
const keyword = String(params.keyword ?? '');
|
|
9
|
+
if (!keyword)
|
|
10
|
+
return '请提供要删除的关键词';
|
|
11
|
+
if (!removeKeyword(keyword, resolveGroupSuiteRuntime({ owner, use })?.keywords))
|
|
12
|
+
return `关键词「${keyword}」不存在`;
|
|
13
|
+
return `已删除关键词「${keyword}」`;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { myPoints } from "../lib/checkin-lib.js";
|
|
4
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
description: '查看个人积分与签到信息',
|
|
7
|
+
execute({ input, owner, use }) {
|
|
8
|
+
return myPoints(input ?? {}, resolveGroupSuiteRuntime({ owner, use }));
|
|
9
|
+
},
|
|
10
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { myStatsText } from "../lib/stats-lib.js";
|
|
4
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
description: '查看个人消息统计',
|
|
7
|
+
execute({ input, owner, use }) {
|
|
8
|
+
return myStatsText(input ?? {}, resolveGroupSuiteRuntime({ owner, use }));
|
|
9
|
+
},
|
|
10
|
+
});
|
package/commands/rank.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { pointsRank } from "../lib/checkin-lib.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
description: '查看积分排行榜',
|
|
8
|
+
execute({ config, input, owner, use }) {
|
|
9
|
+
return pointsRank(input ?? {}, resolveGroupSuiteConfig(config), resolveGroupSuiteRuntime({ owner, use }));
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { monthStartStr, resolveGroupId, statsRankText } from "../lib/stats-lib.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
description: '查看本月话唠排行',
|
|
8
|
+
execute({ config, input, owner, use }) {
|
|
9
|
+
const groupId = resolveGroupId(input ?? {});
|
|
10
|
+
const title = groupId ? '本月话唠排行' : '全局话唠排行';
|
|
11
|
+
return statsRankText(input ?? {}, resolveGroupSuiteConfig(config), monthStartStr(), title, resolveGroupSuiteRuntime({ owner, use }));
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { resolveGroupId, statsRankText, weekStartStr } from "../lib/stats-lib.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
description: '查看本周消息统计',
|
|
8
|
+
execute({ config, input, owner, use }) {
|
|
9
|
+
const groupId = resolveGroupId(input ?? {});
|
|
10
|
+
const title = groupId ? '本周本群消息统计' : '本周全局消息统计';
|
|
11
|
+
return statsRankText(input ?? {}, resolveGroupSuiteConfig(config), weekStartStr(), title, resolveGroupSuiteRuntime({ owner, use }));
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { todayStr } from "../lib/shared-runtime.js";
|
|
5
|
+
import { resolveGroupId, statsRankText } from "../lib/stats-lib.js";
|
|
6
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
7
|
+
export default defineCommand({
|
|
8
|
+
description: '查看今日消息统计',
|
|
9
|
+
execute({ config, input, owner, use }) {
|
|
10
|
+
const groupId = resolveGroupId(input ?? {});
|
|
11
|
+
const title = groupId ? '今日本群消息统计' : '今日全局消息统计';
|
|
12
|
+
return statsRankText(input ?? {}, resolveGroupSuiteConfig(config), todayStr(), title, resolveGroupSuiteRuntime({ owner, use }));
|
|
13
|
+
},
|
|
14
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../../lib/config.js";
|
|
4
|
+
import { teachList } from "../../lib/teach-lib.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../../lib/runtime-state.js";
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
description: '查看问答列表',
|
|
8
|
+
execute({ config, input, params, owner, use }) {
|
|
9
|
+
const page = Number(params.page ?? 1);
|
|
10
|
+
return teachList(input ?? {}, resolveGroupSuiteConfig(config), page, resolveGroupSuiteRuntime({ owner, use }));
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { teachAdd } from "../lib/teach-lib.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
description: '教我正则问答',
|
|
8
|
+
execute({ config, input, args, owner, use }) {
|
|
9
|
+
return teachAdd(input ?? {}, resolveGroupSuiteConfig(config), args.join(' '), true, resolveGroupSuiteRuntime({ owner, use }));
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { teachAdd } from "../lib/teach-lib.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
description: '教我问答(teach 问题 回答 或 问题|答案)',
|
|
8
|
+
execute({ config, input, args, owner, use }) {
|
|
9
|
+
return teachAdd(input ?? {}, resolveGroupSuiteConfig(config), args.join(' '), false, resolveGroupSuiteRuntime({ owner, use }));
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineMiddleware } from '@zhin.js/middleware';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { matchKeyword } from "../lib/keyword-store.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
6
|
+
/**
|
|
7
|
+
* Keyword auto-reply (enabled via config.keywordReply).
|
|
8
|
+
* Uses Runtime Message.content / metadata (legacy used $raw / $channel).
|
|
9
|
+
*/
|
|
10
|
+
export default defineMiddleware({
|
|
11
|
+
target: 'inbound',
|
|
12
|
+
async handle(context, next) {
|
|
13
|
+
const config = resolveGroupSuiteConfig(context.config);
|
|
14
|
+
if (!config.keywordReply) {
|
|
15
|
+
await next();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const meta = context.input.metadata ?? {};
|
|
19
|
+
const channelType = String(meta.type ?? meta.channelType ?? '');
|
|
20
|
+
if (channelType === 'private') {
|
|
21
|
+
await next();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const text = typeof context.input.content === 'string' ? context.input.content.trim() : '';
|
|
25
|
+
if (!text) {
|
|
26
|
+
await next();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const reply = matchKeyword(text, resolveGroupSuiteRuntime(context)?.keywords);
|
|
30
|
+
if (reply) {
|
|
31
|
+
await context.input.$reply(reply);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await next();
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineMiddleware } from '@zhin.js/middleware';
|
|
3
|
+
import { recordMessage } from "../lib/stats-lib.js";
|
|
4
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
5
|
+
/**
|
|
6
|
+
* Buffer inbound messages into in-memory message_stats (flushed on query).
|
|
7
|
+
* Skips command messages (legacy used `isActionMessage` to skip interactive
|
|
8
|
+
* action/command messages; the Runtime pipeline represents commands as
|
|
9
|
+
* text starting with the dispatcher prefix '/').
|
|
10
|
+
*/
|
|
11
|
+
export default defineMiddleware({
|
|
12
|
+
target: 'inbound',
|
|
13
|
+
async handle(context, next) {
|
|
14
|
+
const content = typeof context.input.content === 'string' ? context.input.content : '';
|
|
15
|
+
if (!content.startsWith('/')) {
|
|
16
|
+
recordMessage(context.input, resolveGroupSuiteRuntime(context));
|
|
17
|
+
}
|
|
18
|
+
await next();
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineMiddleware } from '@zhin.js/middleware';
|
|
3
|
+
import { resolveGroupSuiteConfig } from "../lib/config.js";
|
|
4
|
+
import { tryTeachReply } from "../lib/teach-lib.js";
|
|
5
|
+
import { resolveGroupSuiteRuntime } from "../lib/runtime-state.js";
|
|
6
|
+
/**
|
|
7
|
+
* Teach Q&A auto-reply (exact / optional regex).
|
|
8
|
+
* Uses Runtime Message.content / metadata.
|
|
9
|
+
*/
|
|
10
|
+
export default defineMiddleware({
|
|
11
|
+
target: 'inbound',
|
|
12
|
+
async handle(context, next) {
|
|
13
|
+
const config = resolveGroupSuiteConfig(context.config);
|
|
14
|
+
const reply = await tryTeachReply(context.input, config, resolveGroupSuiteRuntime(context));
|
|
15
|
+
if (reply) {
|
|
16
|
+
await context.input.$reply(reply);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
await next();
|
|
20
|
+
},
|
|
21
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-group-suite",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "Zhin.js 群运营套件 — slice-2 checkin/teach/stats + keywords (Plugin Runtime, in-memory)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"./package.json": "./package.json"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
|
-
"plugin.
|
|
17
|
+
"plugin.js",
|
|
18
18
|
"schema.json",
|
|
19
19
|
"commands",
|
|
20
20
|
"middlewares",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@zhin.js/command": "1.0.
|
|
45
|
-
"@zhin.js/core": "1.4.
|
|
46
|
-
"@zhin.js/middleware": "1.0.
|
|
44
|
+
"@zhin.js/command": "1.0.4",
|
|
45
|
+
"@zhin.js/core": "1.4.2",
|
|
46
|
+
"@zhin.js/middleware": "1.0.4",
|
|
47
47
|
"@zhin.js/plugin-runtime": "1.1.1",
|
|
48
48
|
"@zhin.js/satori": "1.0.17"
|
|
49
49
|
},
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"typescript": "^6.0.3",
|
|
52
52
|
"vitest": "^4.1.10",
|
|
53
53
|
"zod": "^4.4.3",
|
|
54
|
-
"@zhin.js/agent": "1.0.
|
|
55
|
-
"zhin.js": "5.0.
|
|
54
|
+
"@zhin.js/agent": "1.0.8",
|
|
55
|
+
"zhin.js": "5.0.2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"zod": "^4.0.0",
|
|
59
|
-
"@zhin.js/agent": "1.0.
|
|
59
|
+
"@zhin.js/agent": "1.0.8"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
|
62
62
|
"@zhin.js/agent": {
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"zhin": {
|
|
82
82
|
"protocol": 1,
|
|
83
83
|
"type": "plugin",
|
|
84
|
-
"entry": "./plugin.
|
|
84
|
+
"entry": "./plugin.js",
|
|
85
85
|
"engine": "^1.0.0",
|
|
86
86
|
"runtime": "trusted",
|
|
87
87
|
"features": [
|
package/plugin.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { definePlugin, databaseHostToken } from '@zhin.js/plugin-runtime';
|
|
3
|
+
import { registerGroupSuiteDb } from "./lib/db-store.js";
|
|
4
|
+
import { createInMemoryGroupSuiteDb } from "./lib/memory-store.js";
|
|
5
|
+
import { createGroupSuiteRuntime, groupSuiteRuntimeToken } from "./lib/runtime-state.js";
|
|
6
|
+
import { flushStatsBuffer } from "./lib/stats-lib.js";
|
|
7
|
+
import { defineGroupSuiteTables } from "./lib/tables.js";
|
|
8
|
+
/**
|
|
9
|
+
* Plugin Runtime:
|
|
10
|
+
* - checkin / teach / stats commands + keyword middleware
|
|
11
|
+
* - DB: prefer `databaseHostToken`; else in-memory fallback
|
|
12
|
+
* - Stats buffer: periodic flush every 10s + final flush on dispose
|
|
13
|
+
*/
|
|
14
|
+
export default definePlugin({
|
|
15
|
+
name: 'group-suite',
|
|
16
|
+
metadata: {
|
|
17
|
+
displayName: 'Group Suite',
|
|
18
|
+
},
|
|
19
|
+
setup(context) {
|
|
20
|
+
const db = context.resources.has(databaseHostToken)
|
|
21
|
+
? context.resources.use(databaseHostToken)
|
|
22
|
+
: createInMemoryGroupSuiteDb();
|
|
23
|
+
if (context.resources.has(databaseHostToken)) {
|
|
24
|
+
defineGroupSuiteTables(db);
|
|
25
|
+
}
|
|
26
|
+
const runtime = createGroupSuiteRuntime(db);
|
|
27
|
+
context.resources.provide(groupSuiteRuntimeToken, runtime);
|
|
28
|
+
context.lifecycle.add(registerGroupSuiteDb(db));
|
|
29
|
+
const flushTimer = setInterval(() => {
|
|
30
|
+
void flushStatsBuffer(runtime);
|
|
31
|
+
}, 10_000);
|
|
32
|
+
context.lifecycle.add(async () => {
|
|
33
|
+
clearInterval(flushTimer);
|
|
34
|
+
await flushStatsBuffer(runtime);
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { getCheckinModel } from "../../lib/db-store.js";
|
|
3
|
+
import { todayStr } from "../../lib/shared-runtime.js";
|
|
4
|
+
export default async function (args) {
|
|
5
|
+
const M = getCheckinModel();
|
|
6
|
+
if (!M)
|
|
7
|
+
return '签到数据库尚未就绪';
|
|
8
|
+
const userId = args.user_id;
|
|
9
|
+
if (userId) {
|
|
10
|
+
const rows = await M.select().where({ user_id: userId });
|
|
11
|
+
if (rows.length === 0)
|
|
12
|
+
return `用户 ${userId} 没有签到记录`;
|
|
13
|
+
const u = rows[0];
|
|
14
|
+
return `${u.user_name}: 积分=${u.points}, 累计=${u.total_checkins}天, 连续=${u.streak}天, 最长=${u.max_streak}天, 上次=${u.last_checkin}`;
|
|
15
|
+
}
|
|
16
|
+
const all = await M.select();
|
|
17
|
+
const totalUsers = all.length;
|
|
18
|
+
const totalPoints = all.reduce((s, u) => s + (u.points || 0), 0);
|
|
19
|
+
const today = todayStr();
|
|
20
|
+
const todayCount = all.filter((u) => u.last_checkin === today).length;
|
|
21
|
+
return `签到系统统计\n总用户: ${totalUsers}\n总积分: ${totalPoints}\n今日签到: ${todayCount}人`;
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { getCheckinModel } from "../../lib/db-store.js";
|
|
3
|
+
export default async function (args) {
|
|
4
|
+
const M = getCheckinModel();
|
|
5
|
+
if (!M)
|
|
6
|
+
return '签到数据库尚未就绪';
|
|
7
|
+
const limit = Math.min(Math.max(Number(args.limit) || 10, 1), 50);
|
|
8
|
+
const all = await M.select();
|
|
9
|
+
const sorted = all.sort((a, b) => (b.points || 0) - (a.points || 0)).slice(0, limit);
|
|
10
|
+
if (sorted.length === 0)
|
|
11
|
+
return '暂无排行数据';
|
|
12
|
+
return sorted
|
|
13
|
+
.map((u, i) => `${i + 1}. ${u.user_name || u.user_id} — ${u.points}分 (连续${u.streak}天)`)
|
|
14
|
+
.join('\n');
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { flushStatsBuffer, queryStats, weekStartStr, monthStartStr, } from "../../lib/stats-lib.js";
|
|
3
|
+
import { todayStr } from "../../lib/shared-runtime.js";
|
|
4
|
+
export default async function (args) {
|
|
5
|
+
await flushStatsBuffer();
|
|
6
|
+
const groupId = args.group_id || '';
|
|
7
|
+
const period = args.period || 'today';
|
|
8
|
+
let fromDate;
|
|
9
|
+
switch (period) {
|
|
10
|
+
case 'week':
|
|
11
|
+
fromDate = weekStartStr();
|
|
12
|
+
break;
|
|
13
|
+
case 'month':
|
|
14
|
+
fromDate = monthStartStr();
|
|
15
|
+
break;
|
|
16
|
+
default:
|
|
17
|
+
fromDate = todayStr();
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
const stats = await queryStats(groupId, fromDate);
|
|
21
|
+
if (stats.size === 0)
|
|
22
|
+
return `${period} 暂无消息统计数据`;
|
|
23
|
+
const sorted = [...stats.entries()].sort((a, b) => b[1].count - a[1].count);
|
|
24
|
+
const total = sorted.reduce((s, [, v]) => s + v.count, 0);
|
|
25
|
+
const top10 = sorted.slice(0, 10);
|
|
26
|
+
const lines = top10.map(([, v], i) => `${i + 1}. ${v.name} — ${v.count}条`);
|
|
27
|
+
return `消息统计 (${period})\n总消息: ${total}条, 活跃用户: ${stats.size}人\n${lines.join('\n')}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { flushStatsBuffer, weekStartStr } from "../../lib/stats-lib.js";
|
|
3
|
+
import { getStatsModel } from "../../lib/db-store.js";
|
|
4
|
+
import { todayStr } from "../../lib/shared-runtime.js";
|
|
5
|
+
export default async function (args) {
|
|
6
|
+
await flushStatsBuffer();
|
|
7
|
+
const M = getStatsModel();
|
|
8
|
+
if (!M)
|
|
9
|
+
return '统计数据库尚未就绪';
|
|
10
|
+
const userId = args.user_id;
|
|
11
|
+
if (!userId)
|
|
12
|
+
return '请提供用户ID';
|
|
13
|
+
const rows = await M.select().where({ user_id: userId });
|
|
14
|
+
if (rows.length === 0)
|
|
15
|
+
return `用户 ${userId} 暂无消息记录`;
|
|
16
|
+
const today = todayStr();
|
|
17
|
+
const weekStart = weekStartStr();
|
|
18
|
+
let todayCount = 0, weekCount = 0, totalCount = 0;
|
|
19
|
+
for (const row of rows) {
|
|
20
|
+
const c = row.count || 0;
|
|
21
|
+
totalCount += c;
|
|
22
|
+
if (row.date >= weekStart)
|
|
23
|
+
weekCount += c;
|
|
24
|
+
if (row.date === today)
|
|
25
|
+
todayCount += c;
|
|
26
|
+
}
|
|
27
|
+
const name = rows[0].user_name || userId;
|
|
28
|
+
return `${name} 的统计\n今日: ${todayCount}条\n本周: ${weekCount}条\n总计: ${totalCount}条\n活跃天数: ${rows.length}天`;
|
|
29
|
+
}
|
package/plugin.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { definePlugin, databaseHostToken } from '@zhin.js/plugin-runtime';
|
|
2
|
-
import type { GroupSuiteConfig } from './src/config.js';
|
|
3
|
-
import { registerGroupSuiteDb } from './src/db-store.js';
|
|
4
|
-
import { createInMemoryGroupSuiteDb } from './src/memory-store.js';
|
|
5
|
-
import { createGroupSuiteRuntime, groupSuiteRuntimeToken } from './src/runtime-state.js';
|
|
6
|
-
import { flushStatsBuffer } from './src/stats-lib.js';
|
|
7
|
-
import { defineGroupSuiteTables } from './src/tables.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Plugin Runtime:
|
|
11
|
-
* - checkin / teach / stats commands + keyword middleware
|
|
12
|
-
* - DB: prefer `databaseHostToken`; else in-memory fallback
|
|
13
|
-
* - Stats buffer: periodic flush every 10s + final flush on dispose
|
|
14
|
-
*/
|
|
15
|
-
export default definePlugin<GroupSuiteConfig>({
|
|
16
|
-
name: 'group-suite',
|
|
17
|
-
metadata: {
|
|
18
|
-
displayName: 'Group Suite',
|
|
19
|
-
},
|
|
20
|
-
setup(context) {
|
|
21
|
-
const db = context.resources.has(databaseHostToken)
|
|
22
|
-
? context.resources.use(databaseHostToken)
|
|
23
|
-
: createInMemoryGroupSuiteDb();
|
|
24
|
-
if (context.resources.has(databaseHostToken)) {
|
|
25
|
-
defineGroupSuiteTables(db);
|
|
26
|
-
}
|
|
27
|
-
const runtime = createGroupSuiteRuntime(db);
|
|
28
|
-
context.resources.provide(groupSuiteRuntimeToken, runtime);
|
|
29
|
-
context.lifecycle.add(registerGroupSuiteDb(db));
|
|
30
|
-
|
|
31
|
-
const flushTimer = setInterval(() => {
|
|
32
|
-
void flushStatsBuffer(runtime);
|
|
33
|
-
}, 10_000);
|
|
34
|
-
context.lifecycle.add(async () => {
|
|
35
|
-
clearInterval(flushTimer);
|
|
36
|
-
await flushStatsBuffer(runtime);
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
});
|