koishi-plugin-ccb-plus 0.2.8 → 0.2.9-beta.1
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 +12 -32
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -217,45 +217,25 @@ var CcbState = class _CcbState {
|
|
|
217
217
|
}
|
|
218
218
|
async findTargetUser(session, input) {
|
|
219
219
|
if (!input) return null;
|
|
220
|
+
const trimmed = input.trim();
|
|
220
221
|
try {
|
|
221
|
-
const elements = import_koishi2.h.parse(
|
|
222
|
+
const elements = import_koishi2.h.parse(trimmed);
|
|
222
223
|
const atEl = elements.find((el) => el.type === "at");
|
|
223
224
|
if (atEl?.attrs?.id) {
|
|
224
225
|
return String(atEl.attrs.id);
|
|
225
226
|
}
|
|
226
227
|
} catch (e) {
|
|
227
|
-
const atMatch = input.match(/<at\s+(?:.*?\s+)?id=(["'])(.*?)\1/i);
|
|
228
|
-
if (atMatch) return atMatch[2];
|
|
229
228
|
}
|
|
230
|
-
const
|
|
231
|
-
if (
|
|
232
|
-
|
|
229
|
+
const atMatch = trimmed.match(/<at\s+(?:[^>]*?\s+)?id=(["']?)([^"'\s>]+)\1/i);
|
|
230
|
+
if (atMatch) return atMatch[2];
|
|
231
|
+
const rawAtMatch = trimmed.match(/<at[^>]*?id=([^>\s]+)/i);
|
|
232
|
+
if (rawAtMatch) return rawAtMatch[1].replace(/['"]/g, "");
|
|
233
|
+
const colonIndex = trimmed.indexOf(":");
|
|
234
|
+
if (colonIndex > 0 && colonIndex < trimmed.length - 1) {
|
|
235
|
+
return trimmed.slice(colonIndex + 1);
|
|
233
236
|
}
|
|
234
|
-
if (/^\d+$/.test(
|
|
235
|
-
return
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
const list = await session.bot.getGuildMemberList(session.guildId);
|
|
239
|
-
const members = list?.data;
|
|
240
|
-
if (!members?.length) return null;
|
|
241
|
-
const targetName = input.replace(/\s/g, "").toLowerCase();
|
|
242
|
-
let exactMatchId;
|
|
243
|
-
let partialMatchId;
|
|
244
|
-
for (const m of members) {
|
|
245
|
-
const nick = m.nick || m.user?.name || m.name || "";
|
|
246
|
-
if (!nick) continue;
|
|
247
|
-
const cleanNick = nick.replace(/\s/g, "").toLowerCase();
|
|
248
|
-
if (cleanNick === targetName) {
|
|
249
|
-
exactMatchId = m.user?.id;
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
if (!partialMatchId && cleanNick.includes(targetName)) {
|
|
253
|
-
partialMatchId = m.user?.id;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
const finalMatch = exactMatchId || partialMatchId;
|
|
257
|
-
if (finalMatch) return finalMatch;
|
|
258
|
-
} catch (e) {
|
|
237
|
+
if (/^\d+$/.test(trimmed)) {
|
|
238
|
+
return trimmed;
|
|
259
239
|
}
|
|
260
240
|
return null;
|
|
261
241
|
}
|
|
@@ -351,7 +331,7 @@ __name(updateCCBRecord, "updateCCBRecord");
|
|
|
351
331
|
|
|
352
332
|
// src/commands/ccb.ts
|
|
353
333
|
function applyCcbCommand(ctx, config, state) {
|
|
354
|
-
ctx.command("ccb [target:user]", "给群友注入生命因子").option("off", "--off [user
|
|
334
|
+
ctx.command("ccb [target:user]", "给群友注入生命因子").option("off", "--off [target:user] 将自己加入白名单(禁止被人ccb),可指定用户").option("on", "--on [target:user] 将自己移出白名单(允许被人ccb),可指定用户").action(async ({ session, options }, target) => {
|
|
355
335
|
const checkResult = state.checkGroupCommand(session);
|
|
356
336
|
if (checkResult) return checkResult;
|
|
357
337
|
const senderId = session.userId;
|