koishi-plugin-cocoyyy-console 1.1.0-beta.1 → 1.1.0-beta.3
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 +12 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1519,6 +1519,9 @@ async function callOpenRouter(api_url, api_key, api_model = "gpt-4o-mini", messa
|
|
|
1519
1519
|
let err = null;
|
|
1520
1520
|
if (typeof reply === "string") {
|
|
1521
1521
|
responseText = reply.trim();
|
|
1522
|
+
if (responseText === "" || responseText === null) {
|
|
1523
|
+
err = "OpenRouter 返回空内容";
|
|
1524
|
+
}
|
|
1522
1525
|
} else if (Array.isArray(reply)) {
|
|
1523
1526
|
responseText = reply.map((part) => part?.text ?? "").join("").trim();
|
|
1524
1527
|
if (!responseText) {
|
|
@@ -1527,6 +1530,7 @@ async function callOpenRouter(api_url, api_key, api_model = "gpt-4o-mini", messa
|
|
|
1527
1530
|
} else {
|
|
1528
1531
|
err = "OpenRouter 返回了未知格式,请检查日志";
|
|
1529
1532
|
}
|
|
1533
|
+
logger.error("[callOpenRouter Info]: " + responseText + ", err: " + err);
|
|
1530
1534
|
return { err, resp: responseText };
|
|
1531
1535
|
} catch (error) {
|
|
1532
1536
|
const err = error;
|
|
@@ -2099,7 +2103,7 @@ __name(startSituationPuzzle, "startSituationPuzzle");
|
|
|
2099
2103
|
async function questSituationPuzzle(content, config) {
|
|
2100
2104
|
chatHistory2.push({ role: "user", content: [{ type: "text", text: content }] });
|
|
2101
2105
|
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2102
|
-
if (err != null) {
|
|
2106
|
+
if (err != null || err != "") {
|
|
2103
2107
|
logger.error("[questSituationPuzzle Error]: " + err);
|
|
2104
2108
|
return null;
|
|
2105
2109
|
}
|
|
@@ -2142,17 +2146,17 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2142
2146
|
return `[所有命令都需要@bot]
|
|
2143
2147
|
游戏列表:
|
|
2144
2148
|
${gameList.map((item) => item.command + ": " + item.name).join("\n ")}
|
|
2145
|
-
|
|
2149
|
+
输入@bot startgame [游戏]开始游戏,如果遇到问题请联系开发人员。`;
|
|
2146
2150
|
});
|
|
2147
2151
|
ctx.command("startgame <参数>", "开始游戏,参数为游戏名称").action(async ({ session }, ...args) => {
|
|
2148
2152
|
if (!dev_mode) {
|
|
2149
2153
|
if (!is_at_bot(session)) return;
|
|
2150
2154
|
}
|
|
2151
2155
|
const game = args?.[0];
|
|
2152
|
-
if (!game) return "请提供正确格式,如:@bot
|
|
2156
|
+
if (!game) return "请提供正确格式,如:@bot startgame [游戏]";
|
|
2153
2157
|
switch (game) {
|
|
2154
2158
|
case gameList[0].command:
|
|
2155
|
-
await session.send("
|
|
2159
|
+
await session.send("正在开始游戏...后续问答请参照格式:@bot [问题]");
|
|
2156
2160
|
const resp = await startSituationPuzzle(ai_config);
|
|
2157
2161
|
return checkResp(resp);
|
|
2158
2162
|
default:
|
|
@@ -2174,7 +2178,10 @@ function registerGameMiddleware(ctx, ai_config) {
|
|
|
2174
2178
|
const { content, uid, userId } = session;
|
|
2175
2179
|
if (ctx.bots[uid]) return next();
|
|
2176
2180
|
if (!is_at_bot(session)) return next();
|
|
2177
|
-
const
|
|
2181
|
+
const withoutTags = content.replace(/<[^>]+>/g, " ");
|
|
2182
|
+
const text = withoutTags.replace(/\s+/g, " ").trim();
|
|
2183
|
+
logger.info("[game middleware Info]: " + text);
|
|
2184
|
+
const resp = await questSituationPuzzle(text, ai_config);
|
|
2178
2185
|
return checkResp(resp);
|
|
2179
2186
|
});
|
|
2180
2187
|
}
|