koishi-plugin-cocoyyy-console 1.1.0-beta.5 → 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 +90 -20
- package/lib/services/game_func/game_service.d.ts +2 -2
- package/package.json +1 -1
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
|
|
41
|
+
var import_koishi13 = require("koishi");
|
|
42
42
|
|
|
43
43
|
// src/utils/configs/function_config.ts
|
|
44
44
|
var import_koishi = require("koishi");
|
|
@@ -2075,56 +2075,96 @@ 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
|
|
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
|
-
|
|
2084
|
-
return "海龟汤正在进行中,请先结束游戏";
|
|
2088
|
+
chatPrompt = [];
|
|
2085
2089
|
chatHistory2 = [];
|
|
2086
2090
|
const prompt_start = local_config2?.game?.situation_puzzle;
|
|
2087
|
-
|
|
2088
|
-
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model,
|
|
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);
|
|
2091
|
-
|
|
2095
|
+
chatPrompt.pop();
|
|
2092
2096
|
return null;
|
|
2093
2097
|
}
|
|
2094
|
-
|
|
2098
|
+
chatPrompt.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
2095
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);
|
|
2096
2108
|
return resp;
|
|
2097
2109
|
}
|
|
2098
2110
|
__name(startSituationPuzzle, "startSituationPuzzle");
|
|
2111
|
+
function clearGameTimeout() {
|
|
2112
|
+
if (gameTimeout) {
|
|
2113
|
+
clearTimeout(gameTimeout);
|
|
2114
|
+
gameTimeout = null;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
__name(clearGameTimeout, "clearGameTimeout");
|
|
2099
2118
|
async function questSituationPuzzle(content, config) {
|
|
2119
|
+
chatHistory2 = [...chatPrompt];
|
|
2100
2120
|
chatHistory2.push({ role: "user", content: [{ type: "text", text: content }] });
|
|
2101
|
-
is_thinking = true;
|
|
2102
2121
|
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2103
|
-
is_thinking = false;
|
|
2104
2122
|
if (err != null) {
|
|
2105
2123
|
logger.error("[questSituationPuzzle Error]: " + err);
|
|
2106
|
-
chatHistory2.pop();
|
|
2107
2124
|
return null;
|
|
2108
2125
|
}
|
|
2109
|
-
|
|
2126
|
+
if (resp.includes("猜中了")) {
|
|
2127
|
+
is_gaming = false;
|
|
2128
|
+
chatPrompt = [];
|
|
2129
|
+
chatHistory2 = [];
|
|
2130
|
+
gameTimeout = null;
|
|
2131
|
+
}
|
|
2110
2132
|
return resp;
|
|
2111
2133
|
}
|
|
2112
2134
|
__name(questSituationPuzzle, "questSituationPuzzle");
|
|
2113
2135
|
async function endSituationPuzzle(config) {
|
|
2114
2136
|
is_gaming = false;
|
|
2137
|
+
chatHistory2 = [...chatPrompt];
|
|
2115
2138
|
chatHistory2.push({ role: "user", content: [{ type: "text", text: "结束游戏,请给出答案" }] });
|
|
2116
2139
|
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2117
2140
|
if (err != null) {
|
|
2118
2141
|
logger.error("[endSituationPuzzle Error]: " + err);
|
|
2119
|
-
chatHistory2.pop();
|
|
2120
2142
|
return null;
|
|
2121
2143
|
}
|
|
2122
2144
|
return resp;
|
|
2123
2145
|
}
|
|
2124
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");
|
|
2125
2164
|
|
|
2126
2165
|
// src/services/game_func/game_command.ts
|
|
2127
2166
|
var local_config2 = null;
|
|
2167
|
+
var is_thinking = false;
|
|
2128
2168
|
var gameList = [
|
|
2129
2169
|
{
|
|
2130
2170
|
name: "AI海龟汤",
|
|
@@ -2132,6 +2172,12 @@ var gameList = [
|
|
|
2132
2172
|
command: "puzzle"
|
|
2133
2173
|
}
|
|
2134
2174
|
];
|
|
2175
|
+
var commandList = [
|
|
2176
|
+
"endgame",
|
|
2177
|
+
"gamelist",
|
|
2178
|
+
"startgame",
|
|
2179
|
+
"reroll"
|
|
2180
|
+
];
|
|
2135
2181
|
function registerGameCommands(ctx, game_config, ai_config) {
|
|
2136
2182
|
if (game_config?.config_path) {
|
|
2137
2183
|
local_config2 = loadYamlConfig(game_config.config_path);
|
|
@@ -2153,6 +2199,8 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2153
2199
|
if (!dev_mode) {
|
|
2154
2200
|
if (!is_at_bot(session)) return;
|
|
2155
2201
|
}
|
|
2202
|
+
if (is_gaming)
|
|
2203
|
+
return "游戏正在进行中,请先结束游戏";
|
|
2156
2204
|
const game = args?.[0];
|
|
2157
2205
|
if (!game) return "请提供正确格式,如:@bot startgame [游戏]";
|
|
2158
2206
|
switch (game) {
|
|
@@ -2164,12 +2212,31 @@ function registerGameCommands(ctx, game_config, ai_config) {
|
|
|
2164
2212
|
return `游戏不存在,请输入gamelist查看所有游戏`;
|
|
2165
2213
|
}
|
|
2166
2214
|
});
|
|
2167
|
-
ctx.command("endgame", "结束游戏").action(async ({ session }
|
|
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 }) => {
|
|
2168
2229
|
if (!dev_mode) {
|
|
2169
2230
|
if (!is_at_bot(session)) return;
|
|
2170
2231
|
}
|
|
2171
|
-
|
|
2172
|
-
|
|
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
|
+
}
|
|
2173
2240
|
});
|
|
2174
2241
|
}
|
|
2175
2242
|
__name(registerGameCommands, "registerGameCommands");
|
|
@@ -2182,8 +2249,11 @@ function registerGameMiddleware(ctx, ai_config) {
|
|
|
2182
2249
|
if (is_thinking) return "正在思考,请耐心等待...";
|
|
2183
2250
|
const withoutTags = content.replace(/<[^>]+>/g, " ");
|
|
2184
2251
|
const text = withoutTags.replace(/\s+/g, " ").trim();
|
|
2252
|
+
commandList.forEach((element) => {
|
|
2253
|
+
if (text.includes(element)) return next();
|
|
2254
|
+
});
|
|
2185
2255
|
const resp = await questSituationPuzzle(text, ai_config);
|
|
2186
|
-
return checkResp(resp);
|
|
2256
|
+
return (0, import_koishi12.h)("at", { id: userId }) + " " + checkResp(resp);
|
|
2187
2257
|
});
|
|
2188
2258
|
}
|
|
2189
2259
|
__name(registerGameMiddleware, "registerGameMiddleware");
|
|
@@ -2198,7 +2268,7 @@ __name(checkResp, "checkResp");
|
|
|
2198
2268
|
// src/index.ts
|
|
2199
2269
|
var name = "cocoyyy-console";
|
|
2200
2270
|
var dev_mode;
|
|
2201
|
-
var Config =
|
|
2271
|
+
var Config = import_koishi13.Schema.object({
|
|
2202
2272
|
function_config: FunctionConfigSchema.description("功能开关配置"),
|
|
2203
2273
|
ai_config: AiAPIConfigSchema.description("AI API配置"),
|
|
2204
2274
|
mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
|
|
@@ -2206,9 +2276,9 @@ var Config = import_koishi12.Schema.object({
|
|
|
2206
2276
|
repeat_config: RepeatConfigSchema.description("复读配置"),
|
|
2207
2277
|
son_config: ShitOrNotConfigSchema.description("SON配置"),
|
|
2208
2278
|
game_config: GameConfigSchema.description("游戏配置"),
|
|
2209
|
-
test:
|
|
2279
|
+
test: import_koishi13.Schema.string().description("测试")
|
|
2210
2280
|
});
|
|
2211
|
-
var logger = new
|
|
2281
|
+
var logger = new import_koishi13.Logger(name);
|
|
2212
2282
|
var savePath = null;
|
|
2213
2283
|
async function apply(ctx, config) {
|
|
2214
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
|
-
|
|
6
|
+
declare function rerollSituationPuzzle(config: AiAPIConfig): Promise<string>;
|
|
7
|
+
export { is_gaming, startSituationPuzzle, questSituationPuzzle, endSituationPuzzle, rerollSituationPuzzle };
|