koishi-plugin-ccb-plus 0.2.9-beta.1 → 0.2.9
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/index.js +37 -11
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -217,25 +217,51 @@ var CcbState = class _CcbState {
|
|
|
217
217
|
}
|
|
218
218
|
async findTargetUser(session, input) {
|
|
219
219
|
if (!input) return null;
|
|
220
|
-
const trimmed = input.trim();
|
|
221
220
|
try {
|
|
222
|
-
const elements = import_koishi2.h.parse(
|
|
221
|
+
const elements = import_koishi2.h.parse(input);
|
|
223
222
|
const atEl = elements.find((el) => el.type === "at");
|
|
224
223
|
if (atEl?.attrs?.id) {
|
|
225
224
|
return String(atEl.attrs.id);
|
|
226
225
|
}
|
|
227
226
|
} catch (e) {
|
|
228
227
|
}
|
|
229
|
-
const atMatch =
|
|
228
|
+
const atMatch = input.match(/<at\s+[^<]*?id=(["'])(.*?)\1/i);
|
|
230
229
|
if (atMatch) return atMatch[2];
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
if (/<at\b/i.test(input)) {
|
|
231
|
+
const atEl = session.elements?.find((el) => el.type === "at");
|
|
232
|
+
if (atEl?.attrs?.id) {
|
|
233
|
+
return String(atEl.attrs.id);
|
|
234
|
+
}
|
|
236
235
|
}
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
const colonIndex = input.indexOf(":");
|
|
237
|
+
if (colonIndex > 0 && colonIndex < input.length - 1) {
|
|
238
|
+
return input.slice(colonIndex + 1);
|
|
239
|
+
}
|
|
240
|
+
if (/^\d+$/.test(input)) {
|
|
241
|
+
return input;
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const list = await session.bot.getGuildMemberList(session.guildId);
|
|
245
|
+
const members = list?.data;
|
|
246
|
+
if (!members?.length) return null;
|
|
247
|
+
const targetName = input.replace(/\s/g, "").toLowerCase();
|
|
248
|
+
let exactMatchId;
|
|
249
|
+
let partialMatchId;
|
|
250
|
+
for (const m of members) {
|
|
251
|
+
const nick = m.nick || m.user?.name || m.name || "";
|
|
252
|
+
if (!nick) continue;
|
|
253
|
+
const cleanNick = nick.replace(/\s/g, "").toLowerCase();
|
|
254
|
+
if (cleanNick === targetName) {
|
|
255
|
+
exactMatchId = m.user?.id;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
if (!partialMatchId && cleanNick.includes(targetName)) {
|
|
259
|
+
partialMatchId = m.user?.id;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const finalMatch = exactMatchId || partialMatchId;
|
|
263
|
+
if (finalMatch) return finalMatch;
|
|
264
|
+
} catch (e) {
|
|
239
265
|
}
|
|
240
266
|
return null;
|
|
241
267
|
}
|
|
@@ -331,7 +357,7 @@ __name(updateCCBRecord, "updateCCBRecord");
|
|
|
331
357
|
|
|
332
358
|
// src/commands/ccb.ts
|
|
333
359
|
function applyCcbCommand(ctx, config, state) {
|
|
334
|
-
ctx.command("ccb [target:user]", "给群友注入生命因子").option("off", "--off [
|
|
360
|
+
ctx.command("ccb [target:user]", "给群友注入生命因子").option("off", "--off [user:string] 将自己加入白名单(禁止被人ccb),可指定用户").option("on", "--on [user:string] 将自己移出白名单(允许被人ccb),可指定用户").action(async ({ session, options }, target) => {
|
|
335
361
|
const checkResult = state.checkGroupCommand(session);
|
|
336
362
|
if (checkResult) return checkResult;
|
|
337
363
|
const senderId = session.userId;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-ccb-plus",
|
|
3
3
|
"description": "Koishi 插件,与群友发生 ccb 行为。(移植自 astrbot_plugin_ccb_plus )",
|
|
4
|
-
"version": "0.2.9
|
|
4
|
+
"version": "0.2.9",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
"group"
|
|
19
19
|
],
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"koishi": "^4.18.
|
|
21
|
+
"koishi": "^4.18.10"
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
}
|