koishi-plugin-chat-analyse 0.4.6 → 0.4.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/lib/Debug.d.ts +22 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +82 -3
- package/package.json +1 -1
package/lib/Debug.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Context, Command } from 'koishi';
|
|
2
|
+
/**
|
|
3
|
+
* @class Debug
|
|
4
|
+
* @description
|
|
5
|
+
* 提供一系列调试工具,用于数据维护和状态检查。
|
|
6
|
+
* 包括手动补全用户信息、列出数据库中的频道和命令等功能。
|
|
7
|
+
*/
|
|
8
|
+
export declare class Debug {
|
|
9
|
+
private ctx;
|
|
10
|
+
/**
|
|
11
|
+
* @constructor
|
|
12
|
+
* @param {Context} ctx - Koishi 的插件上下文。
|
|
13
|
+
*/
|
|
14
|
+
constructor(ctx: Context);
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
* @method registerCommands
|
|
18
|
+
* @description 在 'analyse' 命令下注册所有调试相关的子命令。
|
|
19
|
+
* @param {Command} analyse - 主 'analyse' 命令实例。
|
|
20
|
+
*/
|
|
21
|
+
registerCommands(analyse: Command): void;
|
|
22
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1081,6 +1081,81 @@ var Data = class {
|
|
|
1081
1081
|
}
|
|
1082
1082
|
};
|
|
1083
1083
|
|
|
1084
|
+
// src/Debug.ts
|
|
1085
|
+
var Debug = class {
|
|
1086
|
+
/**
|
|
1087
|
+
* @constructor
|
|
1088
|
+
* @param {Context} ctx - Koishi 的插件上下文。
|
|
1089
|
+
*/
|
|
1090
|
+
constructor(ctx) {
|
|
1091
|
+
this.ctx = ctx;
|
|
1092
|
+
}
|
|
1093
|
+
static {
|
|
1094
|
+
__name(this, "Debug");
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* @public
|
|
1098
|
+
* @method registerCommands
|
|
1099
|
+
* @description 在 'analyse' 命令下注册所有调试相关的子命令。
|
|
1100
|
+
* @param {Command} analyse - 主 'analyse' 命令实例。
|
|
1101
|
+
*/
|
|
1102
|
+
registerCommands(analyse) {
|
|
1103
|
+
analyse.subcommand(".fill", "手动补全用户信息", { authority: 4 }).action(async ({ session }) => {
|
|
1104
|
+
const bots = this.ctx.bots;
|
|
1105
|
+
if (bots.length === 0) return "暂无可用机器人";
|
|
1106
|
+
const usersToUpdate = await this.ctx.database.get("analyse_user", {
|
|
1107
|
+
$or: [{ userName: "" }, { channelName: "" }]
|
|
1108
|
+
});
|
|
1109
|
+
if (usersToUpdate.length === 0) return "暂无用户信息需要补全";
|
|
1110
|
+
const usersByChannel = usersToUpdate.reduce((acc, user) => {
|
|
1111
|
+
(acc[user.channelId] = acc[user.channelId] || []).push(user);
|
|
1112
|
+
return acc;
|
|
1113
|
+
}, {});
|
|
1114
|
+
let updatedCount = 0;
|
|
1115
|
+
const bot = bots.find((b) => b.platform === session.platform) || bots[0];
|
|
1116
|
+
for (const channelId in usersByChannel) {
|
|
1117
|
+
const usersInChannel = usersByChannel[channelId];
|
|
1118
|
+
let channelName = usersInChannel.find((u) => u.channelName)?.channelName || "";
|
|
1119
|
+
if (!channelName && channelId) {
|
|
1120
|
+
try {
|
|
1121
|
+
channelName = (await bot.getGuild(channelId))?.name || "";
|
|
1122
|
+
} catch (e) {
|
|
1123
|
+
this.ctx.logger.warn(`获取频道 ${channelId} 信息失败:`, e);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
for (const user of usersInChannel) {
|
|
1127
|
+
if (user.userName && user.channelName) continue;
|
|
1128
|
+
let userName = user.userName;
|
|
1129
|
+
if (!userName && user.userId && channelId) {
|
|
1130
|
+
try {
|
|
1131
|
+
const member = await bot.getGuildMember(channelId, user.userId);
|
|
1132
|
+
userName = member?.nick || member?.name || "";
|
|
1133
|
+
if (!userName) userName = (await bot.getUser(user.userId))?.name || "";
|
|
1134
|
+
} catch (e) {
|
|
1135
|
+
this.ctx.logger.warn(`获取频道 ${channelId} 的用户 ${user.userId} 信息失败:`, e);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
await this.ctx.database.set("analyse_user", { uid: user.uid }, {
|
|
1139
|
+
userName: userName || user.userName,
|
|
1140
|
+
channelName: channelName || user.channelName
|
|
1141
|
+
});
|
|
1142
|
+
updatedCount++;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
return `已补全 ${updatedCount} 条用户信息`;
|
|
1146
|
+
});
|
|
1147
|
+
analyse.subcommand(".list", "列出频道及命令", { authority: 4 }).action(async () => {
|
|
1148
|
+
const allChannelInfo = await this.ctx.database.get("analyse_user", {}, ["channelId", "channelName"]);
|
|
1149
|
+
const uniqueChannels = [...new Map(allChannelInfo.map((item) => [item.channelId, item])).values()];
|
|
1150
|
+
const channelOutput = uniqueChannels.length > 0 ? "频道列表:\n" + uniqueChannels.map((c) => `[${c.channelId}] ${c.channelName}`).join("\n") : "暂无频道记录";
|
|
1151
|
+
const commands = await this.ctx.database.select("analyse_cmd").distinct("command").execute();
|
|
1152
|
+
const commandOutput = commands.length > 0 ? "命令列表:\n" + commands.map((c) => c.command).join(", ") : "暂无命令记录";
|
|
1153
|
+
return `${channelOutput}
|
|
1154
|
+
${commandOutput}`;
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1084
1159
|
// src/index.ts
|
|
1085
1160
|
var usage = `
|
|
1086
1161
|
<div style="border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);">
|
|
@@ -1103,8 +1178,7 @@ var Config = import_koishi6.Schema.intersect([
|
|
|
1103
1178
|
}).description("监听配置"),
|
|
1104
1179
|
import_koishi6.Schema.object({
|
|
1105
1180
|
enableCmdStat: import_koishi6.Schema.boolean().default(true).description("启用命令统计"),
|
|
1106
|
-
enableMsgStat: import_koishi6.Schema.boolean().default(true).description("启用消息统计")
|
|
1107
|
-
enableData: import_koishi6.Schema.boolean().default(false).description("启用数据管理")
|
|
1181
|
+
enableMsgStat: import_koishi6.Schema.boolean().default(true).description("启用消息统计")
|
|
1108
1182
|
}).description("功能配置"),
|
|
1109
1183
|
import_koishi6.Schema.object({
|
|
1110
1184
|
enableRankStat: import_koishi6.Schema.boolean().default(true).description("启用发言排行"),
|
|
@@ -1113,7 +1187,11 @@ var Config = import_koishi6.Schema.intersect([
|
|
|
1113
1187
|
import_koishi6.Schema.object({
|
|
1114
1188
|
enableWhoAt: import_koishi6.Schema.boolean().default(true).description("启用 @ 记录"),
|
|
1115
1189
|
atRetentionDays: import_koishi6.Schema.number().min(0).default(7).description("记录保留天数")
|
|
1116
|
-
}).description("@ 记录配置")
|
|
1190
|
+
}).description("@ 记录配置"),
|
|
1191
|
+
import_koishi6.Schema.object({
|
|
1192
|
+
enableData: import_koishi6.Schema.boolean().default(false).description("启用数据管理"),
|
|
1193
|
+
enableDebug: import_koishi6.Schema.boolean().default(false).description("启用调试工具")
|
|
1194
|
+
}).description("高级功能")
|
|
1117
1195
|
]);
|
|
1118
1196
|
function apply(ctx, config) {
|
|
1119
1197
|
if (config.enableListener) new Collector(ctx, config);
|
|
@@ -1121,6 +1199,7 @@ function apply(ctx, config) {
|
|
|
1121
1199
|
new Stat(ctx, config).registerCommands(analyse);
|
|
1122
1200
|
if (config.enableWhoAt) new WhoAt(ctx, config).registerCommand(analyse);
|
|
1123
1201
|
if (config.enableData) new Data(ctx).registerCommands(analyse);
|
|
1202
|
+
if (config.enableDebug) new Debug(ctx).registerCommands(analyse);
|
|
1124
1203
|
}
|
|
1125
1204
|
__name(apply, "apply");
|
|
1126
1205
|
// Annotate the CommonJS export names for ESM import in node:
|