Skip to content

Commit 04d0e07

Browse files
committed
fix: 修正 #7 部分信息统计
1 parent 33bd81d commit 04d0e07

28 files changed

+770
-150
lines changed

.github/workflows/pr.yml

Lines changed: 0 additions & 64 deletions
This file was deleted.

config/comment/config.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"status": true,
3+
"forward": true,
4+
"restartMode": true,
5+
"restart": true
6+
}

config/config/config.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

dist/apps/exit.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as node_karin from 'node-karin';
2+
3+
declare const exit: node_karin.Command<keyof node_karin.MessageEventMap>;
4+
5+
export { exit };

dist/apps/exit.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// src/apps/exit.ts
2+
import { common, karin } from "node-karin";
3+
var exit = karin.command(/^#$/, async (e) => {
4+
await e.reply(`\u5F00\u59CB\u5173\u673A \u672C\u6B21\u8FD0\u884C\u65F6\u95F4: ${common.uptime()}`, { at: true });
5+
process.emit("SIGINT");
6+
return true;
7+
}, { name: "\u5173\u673A", perm: "admin" });
8+
export {
9+
exit
10+
};

dist/apps/restart.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as node_karin from 'node-karin';
2+
3+
declare const restarts: node_karin.Command<keyof node_karin.MessageEventMap>;
4+
5+
export { restarts };

dist/apps/restart.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {
2+
config
3+
} from "../chunk-647Y5KXD.js";
4+
import "../chunk-DZWGT2BP.js";
5+
6+
// src/apps/restart.ts
7+
import { common, karin, logger, restart } from "node-karin";
8+
var restarts = karin.command(/^#$/, async (e) => {
9+
try {
10+
await e.reply(`\u5F00\u59CB\u91CD\u542F \u672C\u6B21\u8FD0\u884C\u65F6\u95F4: ${common.uptime()}`, { at: true });
11+
const { status, data } = await restart(e.selfId, e.contact, e.messageId, config().restartMode);
12+
if (status === "failed") throw data;
13+
return true;
14+
} catch (error) {
15+
logger.error(error);
16+
await e.reply(`\u91CD\u542F\u5931\u8D25: ${error.message || "\u672A\u77E5\u539F\u56E0"}`, { at: true });
17+
return true;
18+
}
19+
}, { name: "\u91CD\u542F", perm: "admin" });
20+
export {
21+
restarts
22+
};

dist/apps/status.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as node_karin from 'node-karin';
2+
3+
declare const status: node_karin.Command<keyof node_karin.MessageEventMap>;
4+
5+
export { status };

dist/apps/status.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import {
2+
config
3+
} from "../chunk-647Y5KXD.js";
4+
import "../chunk-DZWGT2BP.js";
5+
6+
// src/apps/status.ts
7+
import moment from "node-karin/moment";
8+
import { EVENT_COUNT, hooks, karin, RECV_MSG, redis, SEND_MSG } from "node-karin";
9+
var status = karin.command(/^#$/, async (e) => {
10+
const today = moment().format("YYYY-MM-DD");
11+
const month = moment().format("YYYY-MM");
12+
const [
13+
send,
14+
recv,
15+
event,
16+
sendMonth,
17+
recvMonth,
18+
eventMonth
19+
] = await Promise.all([
20+
getStat(`${SEND_MSG}:${today}*`),
21+
getStat(`${RECV_MSG}:${today}*`),
22+
getStat(`${EVENT_COUNT}:${today}*`),
23+
getStat(`${SEND_MSG}:${month}*`),
24+
getStat(`${RECV_MSG}:${month}*`),
25+
getStat(`${EVENT_COUNT}:${month}*`)
26+
]);
27+
await e.reply([
28+
"------\u673A\u5668\u4EBA\u72B6\u6001------",
29+
`\u5F53\u524D\u7248\u672C\uFF1Av${process.env.KARIN_VERSION}`,
30+
`\u5185\u5B58\u5360\u7528\uFF1A${MB()}MB`,
31+
`\u8FD0\u884C\u65F6\u95F4\uFF1A${uptime()}`,
32+
"------\u4ECA\u65E5\u7EDF\u8BA1------",
33+
`\u53D1\u9001\u6D88\u606F\uFF1A${send}\u6B21`,
34+
`\u63D2\u4EF6\u89E6\u53D1\uFF1A${event}\u6B21`,
35+
`\u6536\u5230\u6D88\u606F\uFF1A${recv}\u6B21`,
36+
"------\u672C\u6708\u7EDF\u8BA1------",
37+
`\u53D1\u9001\u6D88\u606F\uFF1A${sendMonth}\u6B21`,
38+
`\u63D2\u4EF6\u89E6\u53D1\uFF1A${eventMonth}\u6B21`,
39+
`\u6536\u5230\u6D88\u606F\uFF1A${recvMonth}\u6B21`
40+
].join("\n"));
41+
return true;
42+
}, { name: "\u72B6\u6001\u7EDF\u8BA1" });
43+
var createKey = (contact) => {
44+
const { scene, peer, subPeer } = contact;
45+
return `${moment().format("YYYY-MM-DD")}:${scene}:${peer}${subPeer ? `:${subPeer}` : ""}`;
46+
};
47+
var getStat = async (pattern) => {
48+
const keys = await redis.keys(pattern);
49+
const values = await Promise.all(keys.map((key) => redis.get(key).then(Number)));
50+
return values.reduce((total, value) => total + (value || 0), 0);
51+
};
52+
var MB = () => (process.memoryUsage().rss / 1024 / 1024).toFixed(2);
53+
var uptime = () => {
54+
const uptime2 = process.uptime();
55+
const hour = Math.floor(uptime2 / 3600);
56+
const minute = Math.floor(uptime2 % 3600 / 60);
57+
return `${hour}\u5C0F\u65F6${minute}\u5206\u949F`;
58+
};
59+
(() => {
60+
if (!config().status) return;
61+
hooks.message((event, next) => {
62+
try {
63+
redis.incr(`${RECV_MSG}:${createKey(event.contact)}`);
64+
} finally {
65+
next();
66+
}
67+
});
68+
hooks.sendMsg.message((contact, _, __, next) => {
69+
try {
70+
redis.incr(`${SEND_MSG}:${createKey(contact)}`);
71+
} finally {
72+
next();
73+
}
74+
});
75+
})();
76+
export {
77+
status
78+
};

0 commit comments

Comments
 (0)