koishi-plugin-cocoyyy-console 1.1.0-beta.2 → 1.1.0-beta.4

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 CHANGED
@@ -1519,7 +1519,7 @@ 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) {
1522
+ if (responseText === "" || responseText === null) {
1523
1523
  err = "OpenRouter 返回空内容";
1524
1524
  }
1525
1525
  } else if (Array.isArray(reply)) {
@@ -2077,17 +2077,13 @@ __name(registerKuroCommands, "registerKuroCommands");
2077
2077
 
2078
2078
  // src/services/game_func/game_service.ts
2079
2079
  var is_gaming = false;
2080
+ var is_thinking = false;
2080
2081
  var chatHistory2 = [];
2081
2082
  async function startSituationPuzzle(config) {
2082
2083
  if (is_gaming)
2083
2084
  return "海龟汤正在进行中,请先结束游戏";
2084
2085
  chatHistory2 = [];
2085
- const prompt_start = `你是一个海龟汤游戏主持人,现在开始游戏。
2086
- 请生成一个海龟汤谜题,要求如下:
2087
- 1. 谜题是中文问句且内容简洁,包含一个看似矛盾或难以理解的情境
2088
- 2. 谜题长度不超过100字
2089
- 3. 谜题答案需要符合逻辑但出人意料
2090
- `;
2086
+ const prompt_start = local_config2?.game?.situation_puzzle;
2091
2087
  chatHistory2.push({ role: "system", content: [{ type: "text", text: prompt_start }] });
2092
2088
  const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
2093
2089
  if (err != null) {
@@ -2101,12 +2097,15 @@ async function startSituationPuzzle(config) {
2101
2097
  __name(startSituationPuzzle, "startSituationPuzzle");
2102
2098
  async function questSituationPuzzle(content, config) {
2103
2099
  chatHistory2.push({ role: "user", content: [{ type: "text", text: content }] });
2100
+ is_thinking = true;
2104
2101
  const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
2105
- if (err != null) {
2102
+ is_thinking = false;
2103
+ if (err != null || err != "") {
2106
2104
  logger.error("[questSituationPuzzle Error]: " + err);
2107
2105
  return null;
2108
2106
  }
2109
2107
  chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
2108
+ return resp;
2110
2109
  }
2111
2110
  __name(questSituationPuzzle, "questSituationPuzzle");
2112
2111
  async function endSituationPuzzle(config) {
@@ -2134,12 +2133,12 @@ function registerGameCommands(ctx, game_config, ai_config) {
2134
2133
  if (game_config?.config_path) {
2135
2134
  local_config2 = loadYamlConfig(game_config.config_path);
2136
2135
  if (local_config2) {
2137
- logger.info("[loadYamlConfig Info]: SON 成功加载配置文件");
2136
+ logger.info("[loadYamlConfig Info]: Game 成功加载配置文件");
2138
2137
  } else {
2139
- logger.error("[loadYamlConfig Error]: SON 配置文件加载失败,将使用默认配置");
2138
+ logger.error("[loadYamlConfig Error]: Game 配置文件加载失败,将使用默认配置");
2140
2139
  }
2141
2140
  } else {
2142
- logger.error("[loadYamlConfig Error]: 未配置 SON 配置文件路径");
2141
+ logger.error("[loadYamlConfig Error]: 未配置 Game 配置文件路径");
2143
2142
  }
2144
2143
  ctx.command("gamelist", "查看所有游戏").action(async ({ session }) => {
2145
2144
  return `[所有命令都需要@bot]
@@ -2177,8 +2176,11 @@ function registerGameMiddleware(ctx, ai_config) {
2177
2176
  const { content, uid, userId } = session;
2178
2177
  if (ctx.bots[uid]) return next();
2179
2178
  if (!is_at_bot(session)) return next();
2180
- logger.info("[game middleware Info]: " + session.content);
2181
- const resp = await questSituationPuzzle(session.content, ai_config);
2179
+ if (is_thinking) return "正在思考,请耐心等待...";
2180
+ const withoutTags = content.replace(/<[^>]+>/g, " ");
2181
+ const text = withoutTags.replace(/\s+/g, " ").trim();
2182
+ logger.info("[game middleware Info]: " + text);
2183
+ const resp = await questSituationPuzzle(text, ai_config);
2182
2184
  return checkResp(resp);
2183
2185
  });
2184
2186
  }
@@ -1,6 +1,7 @@
1
1
  import { Context } from 'koishi';
2
2
  import { GameConfig } from '../../utils/configs/game_config';
3
3
  import { AiAPIConfig } from '../../utils/config';
4
+ declare let local_config: any;
4
5
  declare function registerGameCommands(ctx: Context, game_config: GameConfig, ai_config: AiAPIConfig): void;
5
6
  declare function registerGameMiddleware(ctx: Context, ai_config: AiAPIConfig): void;
6
- export { registerGameCommands, registerGameMiddleware, };
7
+ export { local_config, registerGameCommands, registerGameMiddleware, };
@@ -1,6 +1,7 @@
1
1
  import { AiAPIConfig } from "../../utils/config";
2
2
  declare let is_gaming: boolean;
3
+ declare let is_thinking: boolean;
3
4
  declare function startSituationPuzzle(config: AiAPIConfig): Promise<string>;
4
- declare function questSituationPuzzle(content: string, config: AiAPIConfig): Promise<any>;
5
+ declare function questSituationPuzzle(content: string, config: AiAPIConfig): Promise<string>;
5
6
  declare function endSituationPuzzle(config: AiAPIConfig): Promise<string>;
6
- export { is_gaming, startSituationPuzzle, questSituationPuzzle, endSituationPuzzle };
7
+ export { is_gaming, is_thinking, startSituationPuzzle, questSituationPuzzle, endSituationPuzzle };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cocoyyy-console",
3
3
  "description": "自用koishi插件,功能包含复读,记录黑历史,*人等",
4
- "version": "1.1.0-beta.2",
4
+ "version": "1.1.0-beta.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [