koishi-plugin-cocoyyy-console 1.1.1 → 1.1.2-beta.0
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 +36 -45
- package/lib/services/game_func/game_command.d.ts +2 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -500,7 +500,7 @@ var gameFuncMenuList = [
|
|
|
500
500
|
},
|
|
501
501
|
{
|
|
502
502
|
name: "endgame",
|
|
503
|
-
description: "
|
|
503
|
+
description: "游戏进行时使用,结束游戏",
|
|
504
504
|
command: "endgame"
|
|
505
505
|
}
|
|
506
506
|
];
|
|
@@ -2174,6 +2174,7 @@ __name(rerollSituationPuzzle, "rerollSituationPuzzle");
|
|
|
2174
2174
|
// src/services/game_func/game_command.ts
|
|
2175
2175
|
var local_config2 = null;
|
|
2176
2176
|
var is_thinking = false;
|
|
2177
|
+
var now_game = null;
|
|
2177
2178
|
var gameList = [
|
|
2178
2179
|
{
|
|
2179
2180
|
name: "AI海龟汤",
|
|
@@ -2182,7 +2183,6 @@ var gameList = [
|
|
|
2182
2183
|
}
|
|
2183
2184
|
];
|
|
2184
2185
|
var commandList = [
|
|
2185
|
-
"endgame",
|
|
2186
2186
|
"gamelist",
|
|
2187
2187
|
"startgame"
|
|
2188
2188
|
];
|
|
@@ -2197,7 +2197,7 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2197
2197
|
} else {
|
|
2198
2198
|
logger.error("[loadYamlConfig Error]: 未配置 Game 配置文件路径");
|
|
2199
2199
|
}
|
|
2200
|
-
ctx.command("gamelist", "查看所有游戏").action(async ({
|
|
2200
|
+
ctx.command("gamelist", "查看所有游戏").action(async ({}) => {
|
|
2201
2201
|
return `[所有命令都需要@bot]
|
|
2202
2202
|
游戏列表:
|
|
2203
2203
|
${gameList.map((item) => item.command + ": " + item.name).join("\n ")}
|
|
@@ -2217,6 +2217,7 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2217
2217
|
case gameList[0].command:
|
|
2218
2218
|
await session.send("正在开始游戏...后续问答请参照格式:@bot [问题]\n需要刷新谜题时发送:@bot reroll");
|
|
2219
2219
|
const resp = await startSituationPuzzle(ai_config);
|
|
2220
|
+
now_game = game;
|
|
2220
2221
|
return checkResp(resp);
|
|
2221
2222
|
default:
|
|
2222
2223
|
return `游戏不存在,请输入gamelist查看所有游戏`;
|
|
@@ -2225,35 +2226,6 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2225
2226
|
is_thinking = false;
|
|
2226
2227
|
}
|
|
2227
2228
|
});
|
|
2228
|
-
ctx.command("endgame", "结束游戏").action(async ({ session }) => {
|
|
2229
|
-
if (!dev_mode) {
|
|
2230
|
-
if (!is_at_bot(session)) return;
|
|
2231
|
-
}
|
|
2232
|
-
if (!is_gaming) return "未开始游戏";
|
|
2233
|
-
if (is_thinking) return "正在思考,请耐心等待...";
|
|
2234
|
-
try {
|
|
2235
|
-
is_thinking = true;
|
|
2236
|
-
await session.send("正在结束游戏...");
|
|
2237
|
-
const resp = await endSituationPuzzle(ai_config);
|
|
2238
|
-
return checkResp(resp);
|
|
2239
|
-
} finally {
|
|
2240
|
-
is_thinking = false;
|
|
2241
|
-
}
|
|
2242
|
-
});
|
|
2243
|
-
ctx.command("reroll", "重新生成新谜题").action(async ({ session }) => {
|
|
2244
|
-
if (!dev_mode) {
|
|
2245
|
-
if (!is_at_bot(session)) return;
|
|
2246
|
-
}
|
|
2247
|
-
if (!is_gaming) return "未开始游戏";
|
|
2248
|
-
if (is_thinking) return "正在思考,请耐心等待...";
|
|
2249
|
-
try {
|
|
2250
|
-
is_thinking = true;
|
|
2251
|
-
const resp = await rerollSituationPuzzle(ai_config);
|
|
2252
|
-
return checkResp(resp);
|
|
2253
|
-
} finally {
|
|
2254
|
-
is_thinking = false;
|
|
2255
|
-
}
|
|
2256
|
-
});
|
|
2257
2229
|
}
|
|
2258
2230
|
__name(registerGameCommands, "registerGameCommands");
|
|
2259
2231
|
function registerGameMiddleware(ctx, ai_config) {
|
|
@@ -2265,23 +2237,42 @@ function registerGameMiddleware(ctx, ai_config) {
|
|
|
2265
2237
|
if (is_thinking) return "正在思考,请耐心等待...";
|
|
2266
2238
|
const withoutTags = content.replace(/<[^>]+>/g, " ");
|
|
2267
2239
|
const text = withoutTags.replace(/\s+/g, " ").trim();
|
|
2268
|
-
commandList
|
|
2269
|
-
if (text.includes(
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
const resp = await questSituationPuzzle(text, ai_config);
|
|
2278
|
-
return (0, import_koishi12.h)("at", { id: userId }) + " " + checkResp(resp);
|
|
2279
|
-
} finally {
|
|
2280
|
-
is_thinking = false;
|
|
2240
|
+
for (const command of commandList) {
|
|
2241
|
+
if (text.includes(command)) return "正在游戏中,请结束游戏后使用该命令";
|
|
2242
|
+
}
|
|
2243
|
+
switch (now_game) {
|
|
2244
|
+
case gameList[0].command:
|
|
2245
|
+
const resp = await situationPuzzleMiddleware(session, ai_config);
|
|
2246
|
+
return resp;
|
|
2247
|
+
default:
|
|
2248
|
+
return next();
|
|
2281
2249
|
}
|
|
2282
2250
|
});
|
|
2283
2251
|
}
|
|
2284
2252
|
__name(registerGameMiddleware, "registerGameMiddleware");
|
|
2253
|
+
async function situationPuzzleMiddleware(session, ai_config) {
|
|
2254
|
+
const { content, uid, userId } = session;
|
|
2255
|
+
const withoutTags = content.replace(/<[^>]+>/g, " ");
|
|
2256
|
+
const text = withoutTags.replace(/\s+/g, " ").trim();
|
|
2257
|
+
try {
|
|
2258
|
+
is_thinking = true;
|
|
2259
|
+
if (text.includes("reroll")) {
|
|
2260
|
+
const resp2 = await rerollSituationPuzzle(ai_config);
|
|
2261
|
+
return checkResp(resp2);
|
|
2262
|
+
}
|
|
2263
|
+
if (text.includes("endgame")) {
|
|
2264
|
+
await session.send("正在结束游戏...");
|
|
2265
|
+
const resp2 = await endSituationPuzzle(ai_config);
|
|
2266
|
+
now_game = null;
|
|
2267
|
+
return checkResp(resp2);
|
|
2268
|
+
}
|
|
2269
|
+
const resp = await questSituationPuzzle(text, ai_config);
|
|
2270
|
+
return (0, import_koishi12.h)("at", { id: userId }) + " " + checkResp(resp);
|
|
2271
|
+
} finally {
|
|
2272
|
+
is_thinking = false;
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
__name(situationPuzzleMiddleware, "situationPuzzleMiddleware");
|
|
2285
2276
|
function checkResp(resp) {
|
|
2286
2277
|
if (!resp) {
|
|
2287
2278
|
return "返回有误,请检查日志";
|
|
@@ -2,6 +2,7 @@ import { Context } from 'koishi';
|
|
|
2
2
|
import { GameConfig } from '../../utils/configs/game_config';
|
|
3
3
|
import { AiAPIConfig } from '../../utils/config';
|
|
4
4
|
declare let local_config: any;
|
|
5
|
+
declare let now_game: any;
|
|
5
6
|
declare function registerGameCommands(ctx: Context, game_config: GameConfig, ai_config: AiAPIConfig): void;
|
|
6
7
|
declare function registerGameMiddleware(ctx: Context, ai_config: AiAPIConfig): void;
|
|
7
|
-
export { local_config, registerGameCommands, registerGameMiddleware, };
|
|
8
|
+
export { local_config, now_game, registerGameCommands, registerGameMiddleware, };
|