koishi-plugin-wordle-game 2.4.6 → 2.4.8

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,29 +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
- // 玩家记录表操作
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, `新的玩家名字已经存在,请重新输入。`, `改名`);
2331
+ }
2304
2332
  const userRecord = await ctx.database.get('wordle_player_records', { userId });
2305
2333
  if (userRecord.length === 0) {
2306
2334
  await ctx.database.create('wordle_player_records', {
@@ -2311,10 +2339,8 @@ ${rankType3.map((type, index) => `${index + 1}. ${type}`).join('\n')}`}
2311
2339
  else {
2312
2340
  await ctx.database.set('wordle_player_records', { userId }, { username: newPlayerName });
2313
2341
  }
2314
- // 返回
2315
- return await sendMessage(session, `【@${username}】\n玩家名字已更改为:【${newPlayerName}】`, `查询玩家记录 开始游戏 改名`, 2);
2316
- });
2317
- // hs*
2342
+ return await sendMessage(session, `玩家名字已更改为:【${newPlayerName}】`, `查询玩家记录 开始游戏 改名`, 2);
2343
+ }
2318
2344
  function replaceSymbols(message) {
2319
2345
  let firstLessThan = true;
2320
2346
  let firstGreaterThan = true;
@@ -2344,15 +2370,20 @@ ${rankType3.map((type, index) => `${index + 1}. ${type}`).join('\n')}`}
2344
2370
  async function getSessionUserName(session) {
2345
2371
  let sessionUserName = session.username;
2346
2372
  if (isQQOfficialRobotMarkdownTemplateEnabled && session.platform === 'qq') {
2347
- let userRecord = await ctx.database.get('wordle_player_records', { userId: session.userId });
2348
- if (userRecord.length === 0) {
2349
- await ctx.database.create('wordle_player_records', {
2350
- userId: session.userId,
2351
- username: sessionUserName,
2352
- });
2353
- 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;
2354
2386
  }
2355
- sessionUserName = userRecord[0].username;
2356
2387
  }
2357
2388
  return sessionUserName;
2358
2389
  }
@@ -3324,8 +3355,10 @@ ${gridHtml}
3324
3355
  }
3325
3356
  })
3326
3357
  .join('\n');
3327
- const imageBuffer = await ctx.markdownToImage.convertToImage(modifiedMessage);
3328
- [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
+ });
3329
3362
  }
3330
3363
  if (config.retractDelay !== 0) {
3331
3364
  isPushMessageId = true;
@@ -3408,8 +3441,10 @@ ${gridHtml}
3408
3441
  }
3409
3442
  })
3410
3443
  .join('\n');
3411
- const imageBuffer = await ctx.markdownToImage.convertToImage(modifiedMessage);
3412
- [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
+ });
3413
3448
  }
3414
3449
  }
3415
3450
  else {
@@ -5333,4 +5368,3 @@ ${content}
5333
5368
  </div>`;
5334
5369
  // apply
5335
5370
  }
5336
- 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.6",
4
+ "version": "2.4.8",
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
@@ -272,9 +272,10 @@ npm install koishi-plugin-wordle-game
272
272
  - [Numberle](https://dduarte.github.io/numberle/) - 数字猜测游戏
273
273
  - [词影](https://cy.surprising.studio/) - 词影游戏代码与样式
274
274
  - [Numberle](https://numberle.org/) - 数学方程式猜测游戏
275
+ - [Wordle](https://www.nytimes.com/games/wordle/index.html) - 原版 Wordle 游戏网页样式
275
276
  - [LewdleGame](https://www.lewdlegame.com/App) - Lewdle 模式单词列表
276
277
  - [WordlePlay](https://wordleplay.com/wordle-games) - 拓展玩法/单词列表补充
277
- - [Wordle](https://www.nytimes.com/games/wordle/index.html) - 原版 Wordle 游戏网页样式
278
+ - 感谢 ly、麦神等朋友的纠错与反馈喵 ~
278
279
  - [skywind3000/ECDICT](https://github.com/skywind3000/ECDICT) - 英汉语词典数据库
279
280
  - [koishi-plugin-wordle](https://www.npmjs.com/package/koishi-plugin-wordle) - Wordle 经典模式词典
280
281
  - [nonebot-plugin-wordle](https://github.com/noneplugin/nonebot-plugin-wordle) - Nonebot Wordle 的词典