koishi-plugin-wordle-game 2.4.7 → 2.4.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.d.ts CHANGED
@@ -28,6 +28,7 @@ export interface Config {
28
28
  customTemplateId: string;
29
29
  key: string;
30
30
  numberOfMessageButtonsPerRow: number;
31
+ isUsingUnifiedKoishiBuiltInUsername: boolean;
31
32
  }
32
33
  export declare const Config: Schema<Config>;
33
34
  declare module 'koishi' {
package/lib/index.js CHANGED
@@ -24,7 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  return result;
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.apply = exports.Config = exports.usage = exports.name = exports.inject = void 0;
27
+ exports.Config = exports.usage = exports.name = exports.inject = void 0;
28
+ exports.apply = apply;
28
29
  const koishi_1 = require("koishi");
29
30
  const cheerio_1 = require("cheerio");
30
31
  const path = __importStar(require("path"));
@@ -156,6 +157,7 @@ exports.Config = koishi_1.Schema.intersect([
156
157
  customTemplateId: koishi_1.Schema.string().default('').description(`自定义模板 ID。`),
157
158
  key: koishi_1.Schema.string().default('').description(`文本内容中特定插值的 key,用于存放文本。如果你的插值为 {{.info}},那么请在这里填 info。`),
158
159
  numberOfMessageButtonsPerRow: koishi_1.Schema.number().min(4).max(5).default(4).description(`每行消息按钮的数量。`),
160
+ isUsingUnifiedKoishiBuiltInUsername: koishi_1.Schema.boolean().default(true).description(`是否使用统一的 Koishi 内置用户名。`),
159
161
  }),
160
162
  koishi_1.Schema.object({}),
161
163
  ]),
@@ -2278,32 +2280,55 @@ ${rankType3.map((type, index) => `${index + 1}. ${type}`).join('\n')}`}
2278
2280
  // gm*
2279
2281
  ctx.command('wordleGame.改名 [newPlayerName:text]', '更改玩家名字')
2280
2282
  .action(async ({ session }, newPlayerName) => {
2281
- let { channelId, userId, username } = session;
2282
- username = await getSessionUserName(session);
2283
+ const { userId, user } = session;
2284
+ const username = await getSessionUserName(session);
2283
2285
  await updateNameInPlayerRecord(session, userId, username);
2284
- // 修剪玩家名字
2285
2286
  newPlayerName = newPlayerName?.trim();
2286
2287
  if (!newPlayerName) {
2287
- return await sendMessage(session, `【@${username}】\n请输入新的玩家名字。`, `改名`);
2288
+ return sendMessage(session, `请输入新的玩家名字。`, `改名`);
2288
2289
  }
2289
- if (!(config.isEnableQQOfficialRobotMarkdownTemplate && session.platform === 'qq' && config.key !== '' && config.customTemplateId !== '')) {
2290
- return await sendMessage(session, `【@${username}】\n不是 QQ 官方机器人的话,不用改名哦~`, `改名`);
2290
+ if (!(config.isEnableQQOfficialRobotMarkdownTemplate && session.platform === 'qq' && config.key && config.customTemplateId)) {
2291
+ return sendMessage(session, `不是 QQ 官方机器人的话,不用改名哦~`, `改名`);
2291
2292
  }
2292
- // 判断新的玩家名字是否过长
2293
2293
  if (newPlayerName.length > 20) {
2294
- return await sendMessage(session, `【@${username}】\n新的玩家名字过长,请重新输入。`, `改名`);
2294
+ return sendMessage(session, `新的玩家名字过长,请重新输入。`, `改名`);
2295
2295
  }
2296
- const players = await ctx.database.get('wordle_player_records', {});
2297
- // 判断新的玩家名字是否已经存在
2298
- for (const player of players) {
2299
- if (player.username === newPlayerName) {
2300
- return await sendMessage(session, `【@${username}】\n新的玩家名字已经存在,请重新输入。`, `改名`);
2296
+ if (newPlayerName.includes("@everyone")) {
2297
+ return sendMessage(session, `新的玩家名字不合法,请重新输入。`, `改名`);
2298
+ }
2299
+ if (config.isUsingUnifiedKoishiBuiltInUsername) {
2300
+ return handleUnifiedKoishiUsername(session, user, newPlayerName);
2301
+ }
2302
+ else {
2303
+ return handleCustomUsername(ctx, session, userId, newPlayerName);
2304
+ }
2305
+ });
2306
+ // hs*
2307
+ async function handleUnifiedKoishiUsername(session, user, newPlayerName) {
2308
+ const name = koishi_1.h.transform(newPlayerName, { text: true, default: false }).trim();
2309
+ if (name === user.name) {
2310
+ return sendMessage(session, `新的玩家名字已经存在,请重新输入。`, `改名`);
2311
+ }
2312
+ try {
2313
+ user.name = name;
2314
+ await user.$update();
2315
+ return sendMessage(session, `玩家名字已更改为:【${newPlayerName}】`, `查询玩家记录 开始游戏 改名`, 2);
2316
+ }
2317
+ catch (error) {
2318
+ if (koishi_1.RuntimeError.check(error, 'duplicate-entry')) {
2319
+ return sendMessage(session, `新的玩家名字已经存在,请重新输入。`, `改名`);
2320
+ }
2321
+ else {
2322
+ logger.warn(error);
2323
+ return sendMessage(session, `玩家名字更改失败。`, `改名`);
2301
2324
  }
2302
2325
  }
2303
- if (newPlayerName.includes("@everyone")) {
2304
- return await sendMessage(session, `【@${username}】\n新的玩家名字不合法,请重新输入。`, `改名`);
2326
+ }
2327
+ async function handleCustomUsername(ctx, session, userId, newPlayerName) {
2328
+ const players = await ctx.database.get('wordle_player_records', {});
2329
+ if (players.some(player => player.username === newPlayerName)) {
2330
+ return sendMessage(session, `新的玩家名字已经存在,请重新输入。`, `改名`);
2305
2331
  }
2306
- // 玩家记录表操作
2307
2332
  const userRecord = await ctx.database.get('wordle_player_records', { userId });
2308
2333
  if (userRecord.length === 0) {
2309
2334
  await ctx.database.create('wordle_player_records', {
@@ -2314,10 +2339,8 @@ ${rankType3.map((type, index) => `${index + 1}. ${type}`).join('\n')}`}
2314
2339
  else {
2315
2340
  await ctx.database.set('wordle_player_records', { userId }, { username: newPlayerName });
2316
2341
  }
2317
- // 返回
2318
- return await sendMessage(session, `【@${username}】\n玩家名字已更改为:【${newPlayerName}】`, `查询玩家记录 开始游戏 改名`, 2);
2319
- });
2320
- // hs*
2342
+ return await sendMessage(session, `玩家名字已更改为:【${newPlayerName}】`, `查询玩家记录 开始游戏 改名`, 2);
2343
+ }
2321
2344
  function replaceSymbols(message) {
2322
2345
  let firstLessThan = true;
2323
2346
  let firstGreaterThan = true;
@@ -2347,15 +2370,20 @@ ${rankType3.map((type, index) => `${index + 1}. ${type}`).join('\n')}`}
2347
2370
  async function getSessionUserName(session) {
2348
2371
  let sessionUserName = session.username;
2349
2372
  if (isQQOfficialRobotMarkdownTemplateEnabled && session.platform === 'qq') {
2350
- let userRecord = await ctx.database.get('wordle_player_records', { userId: session.userId });
2351
- if (userRecord.length === 0) {
2352
- await ctx.database.create('wordle_player_records', {
2353
- userId: session.userId,
2354
- username: sessionUserName,
2355
- });
2356
- userRecord = await ctx.database.get('wordle_player_records', { userId: session.userId });
2373
+ if (config.isUsingUnifiedKoishiBuiltInUsername && session.user.name) {
2374
+ sessionUserName = session.user.name;
2375
+ }
2376
+ else {
2377
+ let userRecord = await ctx.database.get('', { userId: session.userId });
2378
+ if (userRecord.length === 0) {
2379
+ await ctx.database.create('wordle_player_records', {
2380
+ userId: session.userId,
2381
+ username: sessionUserName,
2382
+ });
2383
+ userRecord = await ctx.database.get('wordle_player_records', { userId: session.userId });
2384
+ }
2385
+ sessionUserName = userRecord[0].username;
2357
2386
  }
2358
- sessionUserName = userRecord[0].username;
2359
2387
  }
2360
2388
  return sessionUserName;
2361
2389
  }
@@ -3327,8 +3355,10 @@ ${gridHtml}
3327
3355
  }
3328
3356
  })
3329
3357
  .join('\n');
3330
- const imageBuffer = await ctx.markdownToImage.convertToImage(modifiedMessage);
3331
- [messageId] = await session.send(koishi_1.h.image(imageBuffer, `image/${config.imageType}`));
3358
+ ctx.inject(['markdownToImage'], async (ctx) => {
3359
+ const imageBuffer = await ctx.markdownToImage.convertToImage(modifiedMessage);
3360
+ [messageId] = await session.send(koishi_1.h.image(imageBuffer, `image/${config.imageType}`));
3361
+ });
3332
3362
  }
3333
3363
  if (config.retractDelay !== 0) {
3334
3364
  isPushMessageId = true;
@@ -3411,8 +3441,10 @@ ${gridHtml}
3411
3441
  }
3412
3442
  })
3413
3443
  .join('\n');
3414
- const imageBuffer = await ctx.markdownToImage.convertToImage(modifiedMessage);
3415
- [messageId] = await session.send(koishi_1.h.image(imageBuffer, `image/${config.imageType}`));
3444
+ ctx.inject(['markdownToImage'], async (ctx) => {
3445
+ const imageBuffer = await ctx.markdownToImage.convertToImage(modifiedMessage);
3446
+ [messageId] = await session.send(koishi_1.h.image(imageBuffer, `image/${config.imageType}`));
3447
+ });
3416
3448
  }
3417
3449
  }
3418
3450
  else {
@@ -5336,4 +5368,3 @@ ${content}
5336
5368
  </div>`;
5337
5369
  // apply
5338
5370
  }
5339
- exports.apply = apply;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-wordle-game",
3
3
  "description": "欢迎来到 [Wordle](https://www.nytimes.com/games/wordle/index.html) | [汉兜](https://handle.antfu.me/) | [词影](https://cy.surprising.studio/) |... 猜单词|猜成语|猜数字|猜数学方程式|... 的小游戏,支持QQ官方MD模板,且包含多种词库、主题、游戏设置和排行榜系统等。",
4
- "version": "2.4.7",
4
+ "version": "2.4.9",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -61,10 +61,10 @@
61
61
  "猜"
62
62
  ],
63
63
  "peerDependencies": {
64
- "koishi": "^4.17.5"
64
+ "koishi": "^4.17.9"
65
65
  },
66
66
  "devDependencies": {
67
- "koishi-plugin-markdown-to-image-service": "^1.1.8",
67
+ "koishi-plugin-markdown-to-image-service": "^1.1.9",
68
68
  "koishi-plugin-monetary": "^0.1.3",
69
69
  "koishi-plugin-puppeteer": "^3.8.4"
70
70
  },
package/readme.md CHANGED
@@ -74,7 +74,8 @@ npm install koishi-plugin-wordle-game
74
74
  - 建议自行添加指令别名,以方便您和您的用户使用。
75
75
  - 享受猜单词|四字词语|成语|数字|...游戏吧!😊
76
76
  - 如果使用过程中出现成语的未知错误,可以前往 `data/wordleGame/idioms.json` 文件中搜索该成语,查看是否存在拼音的错误。
77
- - 当然你也可以直接删除这个 `idioms.json` 文件,然后重新启动机器人,这样会重新生成一个可能已经修复问题的新的 `idioms.json` 文件。
77
+ - 当然你也可以直接删除这个 `idioms.json`
78
+ 文件,然后重新启动机器人,这样会重新生成一个可能已经修复问题的新的 `idioms.json` 文件。
78
79
  - 这个文件里可以添加自定义的成语 0.0,例如:如果你想加 “原神启动” 也是可以的,注意格式即可(提醒:最后一个元素后面不要加逗号,因为不符合
79
80
  JSON 格式)。
80
81
  - 遇到解决不了的问题,也可以想办法联系我,我很乐意帮助你!希望你玩的开心~😊
@@ -132,6 +133,8 @@ npm install koishi-plugin-wordle-game
132
133
  - 文本内容中特定插值的 key,用于存放文本。如果你的插值为 {{.info}},那么请在这里填 info。
133
134
  - `numberOfMessageButtonsPerRow: number`
134
135
  - 每行消息按钮的数量。
136
+ - `isUsingUnifiedKoishiBuiltInUsername: boolean`
137
+ - 是否使用统一的 Koishi 内置用户名。
135
138
 
136
139
  ## 🎳 游戏指令
137
140
 
@@ -279,7 +282,8 @@ npm install koishi-plugin-wordle-game
279
282
  - [skywind3000/ECDICT](https://github.com/skywind3000/ECDICT) - 英汉语词典数据库
280
283
  - [koishi-plugin-wordle](https://www.npmjs.com/package/koishi-plugin-wordle) - Wordle 经典模式词典
281
284
  - [nonebot-plugin-wordle](https://github.com/noneplugin/nonebot-plugin-wordle) - Nonebot Wordle 的词典
282
- - [Wordle 2315 words list](https://gist.github.com/DevilXD/6ad6cc1fe37872d069a795edd51233b2#file-wordle_words-txt) - 经典 Wordle 的单词列表
285
+ - [Wordle 2315 words list](https://gist.github.com/DevilXD/6ad6cc1fe37872d069a795edd51233b2#file-wordle_words-txt) - 经典
286
+ Wordle 的单词列表
283
287
 
284
288
  ## 🐱 QQ 群
285
289