koishi-plugin-cocoyyy-console 1.1.1 → 1.1.2-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.
- package/lib/index.js +36 -53
- 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
|
];
|
|
@@ -1571,12 +1571,6 @@ __name(extractImageAndText, "extractImageAndText");
|
|
|
1571
1571
|
async function checkShitOrNot(session, parttern_msg, config) {
|
|
1572
1572
|
chatHistory = [];
|
|
1573
1573
|
chatHistory.push({ role: "system", content: [{ type: "text", text: parttern_msg }] });
|
|
1574
|
-
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
|
|
1575
|
-
if (err != null) {
|
|
1576
|
-
logger.error("[callOpenRouter Error 1]: " + err);
|
|
1577
|
-
return null;
|
|
1578
|
-
}
|
|
1579
|
-
chatHistory.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
1580
1574
|
const quoteContent = session.quote.content;
|
|
1581
1575
|
logger.info("[checkShitOrNot Info]: 引用消息内容: " + quoteContent);
|
|
1582
1576
|
const { imageUrls, text } = extractImageAndText(quoteContent);
|
|
@@ -1627,8 +1621,6 @@ son判断模式列表:
|
|
|
1627
1621
|
ctx.command("son <参数>", "判定是否为史").action(async ({ session }, ...args) => {
|
|
1628
1622
|
if (!dev_mode) {
|
|
1629
1623
|
if (!is_at_bot_quote(session)) return "请提供正确格式,如: [引用消息] @bot son [判断模式]";
|
|
1630
|
-
} else {
|
|
1631
|
-
if (!session.quote) return "请引用消息后使用功能";
|
|
1632
1624
|
}
|
|
1633
1625
|
if (think_flag) return "请等待思考结果";
|
|
1634
1626
|
const parttern = args?.[0];
|
|
@@ -2174,6 +2166,7 @@ __name(rerollSituationPuzzle, "rerollSituationPuzzle");
|
|
|
2174
2166
|
// src/services/game_func/game_command.ts
|
|
2175
2167
|
var local_config2 = null;
|
|
2176
2168
|
var is_thinking = false;
|
|
2169
|
+
var now_game = null;
|
|
2177
2170
|
var gameList = [
|
|
2178
2171
|
{
|
|
2179
2172
|
name: "AI海龟汤",
|
|
@@ -2182,7 +2175,6 @@ var gameList = [
|
|
|
2182
2175
|
}
|
|
2183
2176
|
];
|
|
2184
2177
|
var commandList = [
|
|
2185
|
-
"endgame",
|
|
2186
2178
|
"gamelist",
|
|
2187
2179
|
"startgame"
|
|
2188
2180
|
];
|
|
@@ -2197,7 +2189,7 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2197
2189
|
} else {
|
|
2198
2190
|
logger.error("[loadYamlConfig Error]: 未配置 Game 配置文件路径");
|
|
2199
2191
|
}
|
|
2200
|
-
ctx.command("gamelist", "查看所有游戏").action(async ({
|
|
2192
|
+
ctx.command("gamelist", "查看所有游戏").action(async ({}) => {
|
|
2201
2193
|
return `[所有命令都需要@bot]
|
|
2202
2194
|
游戏列表:
|
|
2203
2195
|
${gameList.map((item) => item.command + ": " + item.name).join("\n ")}
|
|
@@ -2217,6 +2209,7 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2217
2209
|
case gameList[0].command:
|
|
2218
2210
|
await session.send("正在开始游戏...后续问答请参照格式:@bot [问题]\n需要刷新谜题时发送:@bot reroll");
|
|
2219
2211
|
const resp = await startSituationPuzzle(ai_config);
|
|
2212
|
+
now_game = game;
|
|
2220
2213
|
return checkResp(resp);
|
|
2221
2214
|
default:
|
|
2222
2215
|
return `游戏不存在,请输入gamelist查看所有游戏`;
|
|
@@ -2225,35 +2218,6 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2225
2218
|
is_thinking = false;
|
|
2226
2219
|
}
|
|
2227
2220
|
});
|
|
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
2221
|
}
|
|
2258
2222
|
__name(registerGameCommands, "registerGameCommands");
|
|
2259
2223
|
function registerGameMiddleware(ctx, ai_config) {
|
|
@@ -2265,23 +2229,42 @@ function registerGameMiddleware(ctx, ai_config) {
|
|
|
2265
2229
|
if (is_thinking) return "正在思考,请耐心等待...";
|
|
2266
2230
|
const withoutTags = content.replace(/<[^>]+>/g, " ");
|
|
2267
2231
|
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;
|
|
2232
|
+
for (const command of commandList) {
|
|
2233
|
+
if (text.includes(command)) return "正在游戏中,请结束游戏后使用该命令";
|
|
2234
|
+
}
|
|
2235
|
+
switch (now_game) {
|
|
2236
|
+
case gameList[0].command:
|
|
2237
|
+
const resp = await situationPuzzleMiddleware(session, ai_config);
|
|
2238
|
+
return resp;
|
|
2239
|
+
default:
|
|
2240
|
+
return next();
|
|
2281
2241
|
}
|
|
2282
2242
|
});
|
|
2283
2243
|
}
|
|
2284
2244
|
__name(registerGameMiddleware, "registerGameMiddleware");
|
|
2245
|
+
async function situationPuzzleMiddleware(session, ai_config) {
|
|
2246
|
+
const { content, uid, userId } = session;
|
|
2247
|
+
const withoutTags = content.replace(/<[^>]+>/g, " ");
|
|
2248
|
+
const text = withoutTags.replace(/\s+/g, " ").trim();
|
|
2249
|
+
try {
|
|
2250
|
+
is_thinking = true;
|
|
2251
|
+
if (text.includes("reroll")) {
|
|
2252
|
+
const resp2 = await rerollSituationPuzzle(ai_config);
|
|
2253
|
+
return checkResp(resp2);
|
|
2254
|
+
}
|
|
2255
|
+
if (text.includes("endgame")) {
|
|
2256
|
+
await session.send("正在结束游戏...");
|
|
2257
|
+
const resp2 = await endSituationPuzzle(ai_config);
|
|
2258
|
+
now_game = null;
|
|
2259
|
+
return checkResp(resp2);
|
|
2260
|
+
}
|
|
2261
|
+
const resp = await questSituationPuzzle(text, ai_config);
|
|
2262
|
+
return (0, import_koishi12.h)("at", { id: userId }) + " " + checkResp(resp);
|
|
2263
|
+
} finally {
|
|
2264
|
+
is_thinking = false;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
__name(situationPuzzleMiddleware, "situationPuzzleMiddleware");
|
|
2285
2268
|
function checkResp(resp) {
|
|
2286
2269
|
if (!resp) {
|
|
2287
2270
|
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, };
|