koishi-plugin-cocoyyy-console 1.0.9-beta.3 → 1.0.10-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.
Files changed (2) hide show
  1. package/lib/index.js +32 -23
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1189,23 +1189,19 @@ __name(create_content, "create_content");
1189
1189
  async function get_content_list(guild_id, tar_uid) {
1190
1190
  try {
1191
1191
  const RbqContent = getRbqContentModel();
1192
+ const whereBase = { guild_id };
1192
1193
  const existed = await RbqContent.findAll({
1193
- where: {
1194
- guild_id,
1195
- tag_uid: null
1196
- }
1194
+ where: { ...whereBase, tag_uid: null }
1197
1195
  });
1198
- let result_list = [];
1196
+ let result_list = existed.map((item) => item.get("content")).filter(Boolean);
1199
1197
  result_list.push(...existed.map((item) => item.get("content")).filter(Boolean));
1200
1198
  if (tar_uid) {
1201
1199
  const tar_existed = await RbqContent.findAll({
1202
- where: {
1203
- guild_id,
1204
- tag_uid: tar_uid
1205
- }
1200
+ where: { ...whereBase, tag_uid: tar_uid }
1206
1201
  });
1207
1202
  result_list.push(...tar_existed.map((item) => item.get("content")).filter(Boolean));
1208
1203
  }
1204
+ result_list = Array.from(new Set(result_list.map((s) => s.trim()).filter((s) => s.length > 0)));
1209
1205
  return result_list;
1210
1206
  } catch (e) {
1211
1207
  logger.error("[get_content_list Error]: " + e?.message || String(e));
@@ -1222,9 +1218,14 @@ function registerRbqCommands(ctx, connected) {
1222
1218
  if (!connected) return;
1223
1219
  if (!is_at_bot(session)) return;
1224
1220
  }
1225
- const list = await get_person_list(session.guildId);
1221
+ const guildId = session.guildId;
1222
+ if (!guildId) return "无法获取群号";
1223
+ const list = await get_person_list(guildId);
1224
+ if (!list || list.length === 0) {
1225
+ return "当前群聊还没有设置任何rbq";
1226
+ }
1226
1227
  return `当前群聊rbq列表:
1227
- ${list.join(",")}`;
1228
+ ${list.map((item) => (0, import_koishi8.h)("at", { id: item })).join(",")}`;
1228
1229
  });
1229
1230
  ctx.command("rbqadd <参数>", "添加rbq").action(async ({ session }, ...args) => {
1230
1231
  if (!dev_mode) {
@@ -1233,9 +1234,12 @@ ${list.join(",")}`;
1233
1234
  }
1234
1235
  const uid = args?.[0];
1235
1236
  if (!uid) return "请提供正确格式,如:@bot rbqadd [QQ号]";
1236
- let exec = await check_in_group(ctx, session, uid);
1237
- if (!exec.result)
1238
- return `${uid}不在当前群聊中`;
1237
+ let exec = null;
1238
+ if (!dev_mode) {
1239
+ exec = await check_in_group(ctx, session, uid);
1240
+ if (!exec.result)
1241
+ return `${uid}不在当前群聊中`;
1242
+ }
1239
1243
  exec = await create_person(session.guildId, uid);
1240
1244
  if (!exec.result)
1241
1245
  return `添加rbq失败:${exec.error}`;
@@ -1249,9 +1253,12 @@ ${list.join(",")}`;
1249
1253
  const source_uid = args?.[0];
1250
1254
  const target_uid = args?.[1];
1251
1255
  if (!source_uid || !target_uid) return "请提供正确格式,如:@bot rbqinstead [已存在QQ号] [替换QQ号]";
1252
- let exec = await check_in_group(ctx, session, target_uid);
1253
- if (!exec.result)
1254
- return `${target_uid}不在当前群聊中`;
1256
+ let exec = null;
1257
+ if (!dev_mode) {
1258
+ exec = await check_in_group(ctx, session, target_uid);
1259
+ if (!exec.result)
1260
+ return `${target_uid}不在当前群聊中`;
1261
+ }
1255
1262
  exec = await instead_person(session.guildId, source_uid, target_uid);
1256
1263
  if (!exec.result)
1257
1264
  return `替换rbq失败:${exec.error}`;
@@ -1265,10 +1272,12 @@ ${list.join(",")}`;
1265
1272
  const content = args?.[0];
1266
1273
  const target_uid = args?.[1] ?? null;
1267
1274
  if (!content) return "请提供正确格式,如:@bot rbqadd_txt [文本] [目标QQ号(可选)]";
1268
- if (target_uid) {
1269
- let exec2 = await check_in_group(ctx, session, target_uid);
1270
- if (!exec2.result)
1271
- return `${target_uid}不在当前群聊中`;
1275
+ if (!dev_mode) {
1276
+ if (target_uid) {
1277
+ let exec2 = await check_in_group(ctx, session, target_uid);
1278
+ if (!exec2.result)
1279
+ return `${target_uid}不在当前群聊中`;
1280
+ }
1272
1281
  }
1273
1282
  let exec = await create_content(session.guildId, content, target_uid);
1274
1283
  if (!exec.result)
@@ -1293,9 +1302,9 @@ ${list.join(",")}`;
1293
1302
  let content = "*死你";
1294
1303
  if (contents && contents.length > 0) {
1295
1304
  const random = new import_koishi8.Random(() => Math.random());
1296
- content = contents[random.int(0, contents.length - 1)];
1305
+ content = contents[random.int(0, contents.length)];
1297
1306
  }
1298
- return session.send((0, import_koishi8.h)("at", { id: matchedUid }) + " " + content);
1307
+ return (0, import_koishi8.h)("at", { id: matchedUid }) + " " + content;
1299
1308
  } catch (error) {
1300
1309
  logger.error("[rbq middleware] Error:", error);
1301
1310
  return next();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cocoyyy-console",
3
3
  "description": "自用koishi插件,功能包含复读,记录黑历史,*人等",
4
- "version": "1.0.9-beta.3",
4
+ "version": "1.0.10-beta.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [