koishi-plugin-wordle-game 2.4.7 → 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 +1 -0
- package/lib/index.js +65 -34
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
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.
|
|
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
|
-
|
|
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
|
|
2288
|
+
return sendMessage(session, `请输入新的玩家名字。`, `改名`);
|
|
2288
2289
|
}
|
|
2289
|
-
if (!(config.isEnableQQOfficialRobotMarkdownTemplate && session.platform === 'qq' && config.key
|
|
2290
|
-
return
|
|
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
|
|
2294
|
+
return sendMessage(session, `新的玩家名字过长,请重新输入。`, `改名`);
|
|
2295
2295
|
}
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
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
|
-
|
|
2304
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
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
|
-
|
|
3331
|
-
|
|
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
|
-
|
|
3415
|
-
|
|
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.
|
|
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.
|
|
64
|
+
"koishi": "^4.17.9"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"koishi-plugin-markdown-to-image-service": "^1.1.
|
|
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
|
},
|