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

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
@@ -38,7 +38,7 @@ __export(src_exports, {
38
38
  savePath: () => savePath
39
39
  });
40
40
  module.exports = __toCommonJS(src_exports);
41
- var import_koishi12 = require("koishi");
41
+ var import_koishi13 = require("koishi");
42
42
 
43
43
  // src/utils/configs/function_config.ts
44
44
  var import_koishi = require("koishi");
@@ -2075,41 +2075,66 @@ function registerKuroCommands(ctx, connected) {
2075
2075
  }
2076
2076
  __name(registerKuroCommands, "registerKuroCommands");
2077
2077
 
2078
+ // src/services/game_func/game_command.ts
2079
+ var import_koishi12 = require("koishi");
2080
+
2078
2081
  // src/services/game_func/game_service.ts
2079
2082
  var is_gaming = false;
2080
- var is_thinking = false;
2083
+ var chatPrompt = [];
2081
2084
  var chatHistory2 = [];
2085
+ var gameTimeout = null;
2086
+ var GAME_TIMEOUT_MINUTES = local_config2?.game?.timeout_minutes || 10;
2082
2087
  async function startSituationPuzzle(config) {
2083
- if (is_gaming)
2084
- return "海龟汤正在进行中,请先结束游戏";
2088
+ chatPrompt = [];
2085
2089
  chatHistory2 = [];
2086
2090
  const prompt_start = local_config2?.game?.situation_puzzle;
2087
- chatHistory2.push({ role: "system", content: [{ type: "text", text: prompt_start }] });
2088
- const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
2091
+ chatPrompt.push({ role: "system", content: [{ type: "text", text: prompt_start }] });
2092
+ const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatPrompt);
2089
2093
  if (err != null) {
2090
2094
  logger.error("[startSituationPuzzle Error]: " + err);
2095
+ chatPrompt.pop();
2091
2096
  return null;
2092
2097
  }
2093
- chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
2098
+ chatPrompt.push({ role: "assistant", content: [{ type: "text", text: resp }] });
2094
2099
  is_gaming = true;
2100
+ clearGameTimeout();
2101
+ gameTimeout = setTimeout(async () => {
2102
+ logger.info(`[SituationPuzzle Timeout]: 游戏已超时(${GAME_TIMEOUT_MINUTES}分钟),自动结束游戏`);
2103
+ is_gaming = false;
2104
+ chatPrompt = [];
2105
+ chatHistory2 = [];
2106
+ gameTimeout = null;
2107
+ }, GAME_TIMEOUT_MINUTES * 60 * 1e3);
2095
2108
  return resp;
2096
2109
  }
2097
2110
  __name(startSituationPuzzle, "startSituationPuzzle");
2111
+ function clearGameTimeout() {
2112
+ if (gameTimeout) {
2113
+ clearTimeout(gameTimeout);
2114
+ gameTimeout = null;
2115
+ }
2116
+ }
2117
+ __name(clearGameTimeout, "clearGameTimeout");
2098
2118
  async function questSituationPuzzle(content, config) {
2119
+ chatHistory2 = [...chatPrompt];
2099
2120
  chatHistory2.push({ role: "user", content: [{ type: "text", text: content }] });
2100
- is_thinking = true;
2101
2121
  const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
2102
- is_thinking = false;
2103
- if (err != null || err != "") {
2122
+ if (err != null) {
2104
2123
  logger.error("[questSituationPuzzle Error]: " + err);
2105
2124
  return null;
2106
2125
  }
2107
- chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
2126
+ if (resp.includes("猜中了")) {
2127
+ is_gaming = false;
2128
+ chatPrompt = [];
2129
+ chatHistory2 = [];
2130
+ gameTimeout = null;
2131
+ }
2108
2132
  return resp;
2109
2133
  }
2110
2134
  __name(questSituationPuzzle, "questSituationPuzzle");
2111
2135
  async function endSituationPuzzle(config) {
2112
2136
  is_gaming = false;
2137
+ chatHistory2 = [...chatPrompt];
2113
2138
  chatHistory2.push({ role: "user", content: [{ type: "text", text: "结束游戏,请给出答案" }] });
2114
2139
  const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
2115
2140
  if (err != null) {
@@ -2119,9 +2144,27 @@ async function endSituationPuzzle(config) {
2119
2144
  return resp;
2120
2145
  }
2121
2146
  __name(endSituationPuzzle, "endSituationPuzzle");
2147
+ async function rerollSituationPuzzle(config) {
2148
+ chatHistory2 = [...chatPrompt];
2149
+ chatHistory2.push({ role: "user", content: [{ type: "text", text: "重新生成新谜题" }] });
2150
+ const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
2151
+ if (err != null) {
2152
+ logger.error("[rerollSituationPuzzle Error]: " + err);
2153
+ chatPrompt.pop();
2154
+ return null;
2155
+ }
2156
+ chatPrompt = [];
2157
+ const prompt_start = local_config2?.game?.situation_puzzle;
2158
+ chatPrompt.push({ role: "system", content: [{ type: "text", text: prompt_start }] });
2159
+ chatPrompt.push({ role: "assistant", content: [{ type: "text", text: resp }] });
2160
+ is_gaming = true;
2161
+ return resp;
2162
+ }
2163
+ __name(rerollSituationPuzzle, "rerollSituationPuzzle");
2122
2164
 
2123
2165
  // src/services/game_func/game_command.ts
2124
2166
  var local_config2 = null;
2167
+ var is_thinking = false;
2125
2168
  var gameList = [
2126
2169
  {
2127
2170
  name: "AI海龟汤",
@@ -2129,6 +2172,12 @@ var gameList = [
2129
2172
  command: "puzzle"
2130
2173
  }
2131
2174
  ];
2175
+ var commandList = [
2176
+ "endgame",
2177
+ "gamelist",
2178
+ "startgame",
2179
+ "reroll"
2180
+ ];
2132
2181
  function registerGameCommands(ctx, game_config, ai_config) {
2133
2182
  if (game_config?.config_path) {
2134
2183
  local_config2 = loadYamlConfig(game_config.config_path);
@@ -2150,6 +2199,8 @@ function registerGameCommands(ctx, game_config, ai_config) {
2150
2199
  if (!dev_mode) {
2151
2200
  if (!is_at_bot(session)) return;
2152
2201
  }
2202
+ if (is_gaming)
2203
+ return "游戏正在进行中,请先结束游戏";
2153
2204
  const game = args?.[0];
2154
2205
  if (!game) return "请提供正确格式,如:@bot startgame [游戏]";
2155
2206
  switch (game) {
@@ -2161,12 +2212,31 @@ function registerGameCommands(ctx, game_config, ai_config) {
2161
2212
  return `游戏不存在,请输入gamelist查看所有游戏`;
2162
2213
  }
2163
2214
  });
2164
- ctx.command("endgame", "结束游戏").action(async ({ session }, ...args) => {
2215
+ ctx.command("endgame", "结束游戏").action(async ({ session }) => {
2216
+ if (!dev_mode) {
2217
+ if (!is_at_bot(session)) return;
2218
+ }
2219
+ if (is_thinking) return "正在思考,请耐心等待...";
2220
+ try {
2221
+ is_thinking = true;
2222
+ const resp = await endSituationPuzzle(ai_config);
2223
+ return checkResp(resp);
2224
+ } finally {
2225
+ is_thinking = false;
2226
+ }
2227
+ });
2228
+ ctx.command("reroll", "重新生成新谜题").action(async ({ session }) => {
2165
2229
  if (!dev_mode) {
2166
2230
  if (!is_at_bot(session)) return;
2167
2231
  }
2168
- const resp = await endSituationPuzzle(ai_config);
2169
- return checkResp(resp);
2232
+ if (is_thinking) return "正在思考,请耐心等待...";
2233
+ try {
2234
+ is_thinking = true;
2235
+ const resp = await rerollSituationPuzzle(ai_config);
2236
+ return checkResp(resp);
2237
+ } finally {
2238
+ is_thinking = false;
2239
+ }
2170
2240
  });
2171
2241
  }
2172
2242
  __name(registerGameCommands, "registerGameCommands");
@@ -2179,9 +2249,11 @@ function registerGameMiddleware(ctx, ai_config) {
2179
2249
  if (is_thinking) return "正在思考,请耐心等待...";
2180
2250
  const withoutTags = content.replace(/<[^>]+>/g, " ");
2181
2251
  const text = withoutTags.replace(/\s+/g, " ").trim();
2182
- logger.info("[game middleware Info]: " + text);
2252
+ commandList.forEach((element) => {
2253
+ if (text.includes(element)) return next();
2254
+ });
2183
2255
  const resp = await questSituationPuzzle(text, ai_config);
2184
- return checkResp(resp);
2256
+ return (0, import_koishi12.h)("at", { id: userId }) + " " + checkResp(resp);
2185
2257
  });
2186
2258
  }
2187
2259
  __name(registerGameMiddleware, "registerGameMiddleware");
@@ -2196,7 +2268,7 @@ __name(checkResp, "checkResp");
2196
2268
  // src/index.ts
2197
2269
  var name = "cocoyyy-console";
2198
2270
  var dev_mode;
2199
- var Config = import_koishi12.Schema.object({
2271
+ var Config = import_koishi13.Schema.object({
2200
2272
  function_config: FunctionConfigSchema.description("功能开关配置"),
2201
2273
  ai_config: AiAPIConfigSchema.description("AI API配置"),
2202
2274
  mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
@@ -2204,9 +2276,9 @@ var Config = import_koishi12.Schema.object({
2204
2276
  repeat_config: RepeatConfigSchema.description("复读配置"),
2205
2277
  son_config: ShitOrNotConfigSchema.description("SON配置"),
2206
2278
  game_config: GameConfigSchema.description("游戏配置"),
2207
- test: import_koishi12.Schema.string().description("测试")
2279
+ test: import_koishi13.Schema.string().description("测试")
2208
2280
  });
2209
- var logger = new import_koishi12.Logger(name);
2281
+ var logger = new import_koishi13.Logger(name);
2210
2282
  var savePath = null;
2211
2283
  async function apply(ctx, config) {
2212
2284
  ctx = ctx.guild();
@@ -1,7 +1,7 @@
1
1
  import { AiAPIConfig } from "../../utils/config";
2
2
  declare let is_gaming: boolean;
3
- declare let is_thinking: boolean;
4
3
  declare function startSituationPuzzle(config: AiAPIConfig): Promise<string>;
5
4
  declare function questSituationPuzzle(content: string, config: AiAPIConfig): Promise<string>;
6
5
  declare function endSituationPuzzle(config: AiAPIConfig): Promise<string>;
7
- export { is_gaming, is_thinking, startSituationPuzzle, questSituationPuzzle, endSituationPuzzle };
6
+ declare function rerollSituationPuzzle(config: AiAPIConfig): Promise<string>;
7
+ export { is_gaming, startSituationPuzzle, questSituationPuzzle, endSituationPuzzle, rerollSituationPuzzle };
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.4",
4
+ "version": "1.1.0-beta.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [