koishi-plugin-cocoyyy-console 1.1.0-beta.0 → 1.1.0-beta.2
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 +132 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -489,13 +489,18 @@ __name(getSonFuncMenu, "getSonFuncMenu");
|
|
|
489
489
|
var gameFuncMenuList = [
|
|
490
490
|
{
|
|
491
491
|
name: "gamelist",
|
|
492
|
-
description: "
|
|
493
|
-
command: "
|
|
492
|
+
description: "查看游戏列表",
|
|
493
|
+
command: "gamelist"
|
|
494
494
|
},
|
|
495
495
|
{
|
|
496
|
-
name: "
|
|
496
|
+
name: "startgame",
|
|
497
497
|
description: "开始游戏",
|
|
498
|
-
command: "
|
|
498
|
+
command: "startgame [游戏]"
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
name: "endgame",
|
|
502
|
+
description: "结束游戏",
|
|
503
|
+
command: "endgame"
|
|
499
504
|
}
|
|
500
505
|
];
|
|
501
506
|
function getGameFuncMenu(command = null) {
|
|
@@ -1514,6 +1519,9 @@ async function callOpenRouter(api_url, api_key, api_model = "gpt-4o-mini", messa
|
|
|
1514
1519
|
let err = null;
|
|
1515
1520
|
if (typeof reply === "string") {
|
|
1516
1521
|
responseText = reply.trim();
|
|
1522
|
+
if (!responseText) {
|
|
1523
|
+
err = "OpenRouter 返回空内容";
|
|
1524
|
+
}
|
|
1517
1525
|
} else if (Array.isArray(reply)) {
|
|
1518
1526
|
responseText = reply.map((part) => part?.text ?? "").join("").trim();
|
|
1519
1527
|
if (!responseText) {
|
|
@@ -2067,6 +2075,122 @@ function registerKuroCommands(ctx, connected) {
|
|
|
2067
2075
|
}
|
|
2068
2076
|
__name(registerKuroCommands, "registerKuroCommands");
|
|
2069
2077
|
|
|
2078
|
+
// src/services/game_func/game_service.ts
|
|
2079
|
+
var is_gaming = false;
|
|
2080
|
+
var chatHistory2 = [];
|
|
2081
|
+
async function startSituationPuzzle(config) {
|
|
2082
|
+
if (is_gaming)
|
|
2083
|
+
return "海龟汤正在进行中,请先结束游戏";
|
|
2084
|
+
chatHistory2 = [];
|
|
2085
|
+
const prompt_start = `你是一个海龟汤游戏主持人,现在开始游戏。
|
|
2086
|
+
请生成一个海龟汤谜题,要求如下:
|
|
2087
|
+
1. 谜题是中文问句且内容简洁,包含一个看似矛盾或难以理解的情境
|
|
2088
|
+
2. 谜题长度不超过100字
|
|
2089
|
+
3. 谜题答案需要符合逻辑但出人意料
|
|
2090
|
+
`;
|
|
2091
|
+
chatHistory2.push({ role: "system", content: [{ type: "text", text: prompt_start }] });
|
|
2092
|
+
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2093
|
+
if (err != null) {
|
|
2094
|
+
logger.error("[startSituationPuzzle Error]: " + err);
|
|
2095
|
+
return null;
|
|
2096
|
+
}
|
|
2097
|
+
chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
2098
|
+
is_gaming = true;
|
|
2099
|
+
return resp;
|
|
2100
|
+
}
|
|
2101
|
+
__name(startSituationPuzzle, "startSituationPuzzle");
|
|
2102
|
+
async function questSituationPuzzle(content, config) {
|
|
2103
|
+
chatHistory2.push({ role: "user", content: [{ type: "text", text: content }] });
|
|
2104
|
+
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2105
|
+
if (err != null) {
|
|
2106
|
+
logger.error("[questSituationPuzzle Error]: " + err);
|
|
2107
|
+
return null;
|
|
2108
|
+
}
|
|
2109
|
+
chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
2110
|
+
}
|
|
2111
|
+
__name(questSituationPuzzle, "questSituationPuzzle");
|
|
2112
|
+
async function endSituationPuzzle(config) {
|
|
2113
|
+
is_gaming = false;
|
|
2114
|
+
chatHistory2.push({ role: "user", content: [{ type: "text", text: "结束游戏,请给出答案" }] });
|
|
2115
|
+
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2116
|
+
if (err != null) {
|
|
2117
|
+
logger.error("[endSituationPuzzle Error]: " + err);
|
|
2118
|
+
return null;
|
|
2119
|
+
}
|
|
2120
|
+
return resp;
|
|
2121
|
+
}
|
|
2122
|
+
__name(endSituationPuzzle, "endSituationPuzzle");
|
|
2123
|
+
|
|
2124
|
+
// src/services/game_func/game_command.ts
|
|
2125
|
+
var local_config2 = null;
|
|
2126
|
+
var gameList = [
|
|
2127
|
+
{
|
|
2128
|
+
name: "AI海龟汤",
|
|
2129
|
+
description: "AI海龟汤游戏,通过AI回答问题,猜测答案",
|
|
2130
|
+
command: "puzzle"
|
|
2131
|
+
}
|
|
2132
|
+
];
|
|
2133
|
+
function registerGameCommands(ctx, game_config, ai_config) {
|
|
2134
|
+
if (game_config?.config_path) {
|
|
2135
|
+
local_config2 = loadYamlConfig(game_config.config_path);
|
|
2136
|
+
if (local_config2) {
|
|
2137
|
+
logger.info("[loadYamlConfig Info]: SON 成功加载配置文件");
|
|
2138
|
+
} else {
|
|
2139
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件加载失败,将使用默认配置");
|
|
2140
|
+
}
|
|
2141
|
+
} else {
|
|
2142
|
+
logger.error("[loadYamlConfig Error]: 未配置 SON 配置文件路径");
|
|
2143
|
+
}
|
|
2144
|
+
ctx.command("gamelist", "查看所有游戏").action(async ({ session }) => {
|
|
2145
|
+
return `[所有命令都需要@bot]
|
|
2146
|
+
游戏列表:
|
|
2147
|
+
${gameList.map((item) => item.command + ": " + item.name).join("\n ")}
|
|
2148
|
+
输入@bot startgame [游戏]开始游戏,如果遇到问题请联系开发人员。`;
|
|
2149
|
+
});
|
|
2150
|
+
ctx.command("startgame <参数>", "开始游戏,参数为游戏名称").action(async ({ session }, ...args) => {
|
|
2151
|
+
if (!dev_mode) {
|
|
2152
|
+
if (!is_at_bot(session)) return;
|
|
2153
|
+
}
|
|
2154
|
+
const game = args?.[0];
|
|
2155
|
+
if (!game) return "请提供正确格式,如:@bot startgame [游戏]";
|
|
2156
|
+
switch (game) {
|
|
2157
|
+
case gameList[0].command:
|
|
2158
|
+
await session.send("正在开始游戏...后续问答请参照格式:@bot [问题]");
|
|
2159
|
+
const resp = await startSituationPuzzle(ai_config);
|
|
2160
|
+
return checkResp(resp);
|
|
2161
|
+
default:
|
|
2162
|
+
return `游戏不存在,请输入gamelist查看所有游戏`;
|
|
2163
|
+
}
|
|
2164
|
+
});
|
|
2165
|
+
ctx.command("endgame", "结束游戏").action(async ({ session }, ...args) => {
|
|
2166
|
+
if (!dev_mode) {
|
|
2167
|
+
if (!is_at_bot(session)) return;
|
|
2168
|
+
}
|
|
2169
|
+
const resp = await endSituationPuzzle(ai_config);
|
|
2170
|
+
return checkResp(resp);
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
__name(registerGameCommands, "registerGameCommands");
|
|
2174
|
+
function registerGameMiddleware(ctx, ai_config) {
|
|
2175
|
+
ctx.middleware(async (session, next) => {
|
|
2176
|
+
if (!is_gaming) return next();
|
|
2177
|
+
const { content, uid, userId } = session;
|
|
2178
|
+
if (ctx.bots[uid]) return next();
|
|
2179
|
+
if (!is_at_bot(session)) return next();
|
|
2180
|
+
logger.info("[game middleware Info]: " + session.content);
|
|
2181
|
+
const resp = await questSituationPuzzle(session.content, ai_config);
|
|
2182
|
+
return checkResp(resp);
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
__name(registerGameMiddleware, "registerGameMiddleware");
|
|
2186
|
+
function checkResp(resp) {
|
|
2187
|
+
if (!resp) {
|
|
2188
|
+
return "返回有误,请检查日志";
|
|
2189
|
+
}
|
|
2190
|
+
return resp;
|
|
2191
|
+
}
|
|
2192
|
+
__name(checkResp, "checkResp");
|
|
2193
|
+
|
|
2070
2194
|
// src/index.ts
|
|
2071
2195
|
var name = "cocoyyy-console";
|
|
2072
2196
|
var dev_mode;
|
|
@@ -2102,6 +2226,10 @@ async function apply(ctx, config) {
|
|
|
2102
2226
|
registerRepeatMiddleware(ctx, config?.repeat_config);
|
|
2103
2227
|
if (config.function_config.son_flag)
|
|
2104
2228
|
registerShitOrNotCommands(ctx, config?.ai_config, config?.son_config);
|
|
2229
|
+
if (config.function_config.game_flag) {
|
|
2230
|
+
registerGameCommands(ctx, config?.game_config, config?.ai_config);
|
|
2231
|
+
registerGameMiddleware(ctx, config?.ai_config);
|
|
2232
|
+
}
|
|
2105
2233
|
if (config.function_config.rbq_flag)
|
|
2106
2234
|
registerRbqCommands(ctx, connected);
|
|
2107
2235
|
if (config.function_config)
|