koishi-plugin-cocoyyy-console 1.0.16-beta.1 → 1.0.16-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.d.ts CHANGED
@@ -8,6 +8,7 @@ export interface Config {
8
8
  mysql_config?: my_config.MysqlConfig;
9
9
  tag_config?: my_config.SaveConfig;
10
10
  repeat_config?: my_config.RepeatConfig;
11
+ test?: string;
11
12
  }
12
13
  export declare const Config: Schema<Config>;
13
14
  export declare let logger: Logger;
package/lib/index.js CHANGED
@@ -47,6 +47,7 @@ var FunctionConfigSchema = import_koishi.Schema.object({
47
47
  tag_flag: import_koishi.Schema.boolean().default(true).description("标签功能是否启用"),
48
48
  repeat_flag: import_koishi.Schema.boolean().default(true).description("复读功能是否启用"),
49
49
  rbq_flag: import_koishi.Schema.boolean().default(true).description("*人功能是否启用"),
50
+ shit_or_not_flag: import_koishi.Schema.boolean().default(true).description("鉴别史消息功能是否启用"),
50
51
  kuro_flag: import_koishi.Schema.boolean().default(true).description("鸣潮功能是否启用")
51
52
  });
52
53
 
@@ -321,7 +322,7 @@ function getMenuList(command = null, functionConfig) {
321
322
  return `[所有命令都需要@bot]
322
323
  当前可用功能列表:
323
324
  ${menuList.map((item) => item.name + ": " + item.description).join("\n ")}
324
- 输入"help 功能名"查看特定功能的指令和使用示例。`;
325
+ 输入"help [功能名]"查看特定功能的指令和使用示例。`;
325
326
  }
326
327
  }
327
328
  __name(getMenuList, "getMenuList");
@@ -1352,12 +1353,44 @@ function registerRbqCommands(ctx, connected) {
1352
1353
  __name(registerRbqCommands, "registerRbqCommands");
1353
1354
 
1354
1355
  // src/services/test_command.ts
1355
- function registerTestCommands(ctx) {
1356
- ctx.command("test <参数>", "test").action(async ({ session }, phoneNumber, code) => {
1357
- try {
1358
- } catch (err) {
1359
- console.error(err);
1360
- return `test error: ${err.message}`;
1356
+ var import_tesseract = require("tesseract.js");
1357
+ var CONSTANTS = {
1358
+ ESU: "前提条件"
1359
+ };
1360
+ var chatHistory = [];
1361
+ function registerTestCommands(ctx, config) {
1362
+ ctx.command("test1 <prompt:text>", "调用 OpenRouter 模型进行测试").action(async ({ session }, prompt) => {
1363
+ const apiKey = config?.test || process.env.OPENROUTER_API_KEY;
1364
+ if (!apiKey) return "未配置 OpenRouter API Key(config.test 或环境变量 OPENROUTER_API_KEY)";
1365
+ const content = prompt?.trim();
1366
+ if (!content) return "请输入要测试的内容";
1367
+ chatHistory.push({ role: "user", content });
1368
+ const messages = [
1369
+ { role: "system", content: CONSTANTS.ESU },
1370
+ ...chatHistory
1371
+ ];
1372
+ });
1373
+ ctx.command("test <path>", "测试用").action(async ({ session }, path) => {
1374
+ const { content, uid, userId } = session;
1375
+ if (session.quote) {
1376
+ const quoteContent = session.quote.content;
1377
+ const quoteUserId = session.quote.user.id;
1378
+ logger.error(`quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
1379
+ } else {
1380
+ logger.error(`content: ${content} userId: ${userId}`);
1381
+ }
1382
+ });
1383
+ ctx.middleware((session, next) => {
1384
+ const { content, uid, userId } = session;
1385
+ const cid = session.cid;
1386
+ if (session.guildId != "829263238") return next();
1387
+ if (ctx.bots[uid]) return next();
1388
+ if (session.quote) {
1389
+ const quoteContent = session.quote.content;
1390
+ const quoteUserId = session.quote.user.id;
1391
+ logger.error(`quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
1392
+ } else {
1393
+ logger.error(`content: ${content} userId: ${userId}`);
1361
1394
  }
1362
1395
  });
1363
1396
  }
@@ -1473,7 +1506,7 @@ __name(createUpdateUser, "createUpdateUser");
1473
1506
 
1474
1507
  // src/services/kuro_func/kuro_service.ts
1475
1508
  var userTokenMap = /* @__PURE__ */ new Map();
1476
- var CONSTANTS = {
1509
+ var CONSTANTS2 = {
1477
1510
  BASE_URL: "https://api.kurobbs.com",
1478
1511
  LOGIN_URL: "/user/sdkLogin",
1479
1512
  GAME_DATA_URL: "/gamer/role/list",
@@ -1501,7 +1534,7 @@ var wavesApi = import_axios.default.create();
1501
1534
  wavesApi.interceptors.request.use(
1502
1535
  async (config) => {
1503
1536
  if (config.url.startsWith("/")) {
1504
- config.url = CONSTANTS.BASE_URL + config.url;
1537
+ config.url = CONSTANTS2.BASE_URL + config.url;
1505
1538
  }
1506
1539
  return config;
1507
1540
  },
@@ -1555,7 +1588,7 @@ async function getToken(session, mobile, code) {
1555
1588
  code
1556
1589
  });
1557
1590
  try {
1558
- const user_response = await wavesApi.post(CONSTANTS.LOGIN_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, devCode } });
1591
+ const user_response = await wavesApi.post(CONSTANTS2.LOGIN_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, devCode } });
1559
1592
  if (user_response.data.code != 200) {
1560
1593
  logger.error(`验证码登录失败: ${user_response.data.msg}`);
1561
1594
  return { status: false, msg: user_response.data.msg };
@@ -1595,7 +1628,7 @@ async function getGameData(token) {
1595
1628
  let data = import_qs.default.stringify({
1596
1629
  "gameId": 3
1597
1630
  });
1598
- const response = await wavesApi.post(CONSTANTS.GAME_DATA_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token } });
1631
+ const response = await wavesApi.post(CONSTANTS2.GAME_DATA_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": token } });
1599
1632
  if (response.data.code === 200) {
1600
1633
  return { status: true, data: response.data.data[0] };
1601
1634
  } else {
@@ -1614,7 +1647,7 @@ async function isAvailable(serverId, roleId, token) {
1614
1647
  "roleId": roleId
1615
1648
  });
1616
1649
  try {
1617
- const response = await wavesApi.post(CONSTANTS.TOKEN_REFRESH_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token } });
1650
+ const response = await wavesApi.post(CONSTANTS2.TOKEN_REFRESH_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": token } });
1618
1651
  if (response.data.code === 220) {
1619
1652
  logger.info(`${roleId} 获取可用性成功,账号已过期`);
1620
1653
  return { status: false, msg: "账号已过期" };
@@ -1635,7 +1668,7 @@ async function refreshData(bat, serverId, roleId, token) {
1635
1668
  "roleId": roleId
1636
1669
  });
1637
1670
  try {
1638
- const response = await wavesApi.post(CONSTANTS.REFRESH_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token, "b-at": bat } });
1671
+ const response = await wavesApi.post(CONSTANTS2.REFRESH_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": token, "b-at": bat } });
1639
1672
  if (response.data.code === 10902 || response.data.code === 200) {
1640
1673
  return { status: true, data: response.data.data };
1641
1674
  } else {
@@ -1662,7 +1695,7 @@ async function signIn(qq_uid) {
1662
1695
  "reqMonth": ((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")
1663
1696
  });
1664
1697
  try {
1665
- const response = await wavesApi.post(CONSTANTS.SIGNIN_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": userInfo.token, devcode: "", "b-at": userInfo.bat } });
1698
+ const response = await wavesApi.post(CONSTANTS2.SIGNIN_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": userInfo.token, devcode: "", "b-at": userInfo.bat } });
1666
1699
  if (response.data.code === 200) {
1667
1700
  if (response.data.data === null) {
1668
1701
  logger.info(`[signIn Info]: ${qq_uid} 签到失败,返回空数据`);
@@ -1691,7 +1724,7 @@ async function getRoleData(qq_uid) {
1691
1724
  "roleId": userInfo.role_id
1692
1725
  });
1693
1726
  try {
1694
- const response = await wavesApi.post(CONSTANTS.ROLE_DATA_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": userInfo.token, "b-at": userInfo.bat } });
1727
+ const response = await wavesApi.post(CONSTANTS2.ROLE_DATA_URL, data, { headers: { ...CONSTANTS2.REQUEST_HEADERS_BASE, "token": userInfo.token, "b-at": userInfo.bat } });
1695
1728
  if (response.data.code === 10902 || response.data.code === 200) {
1696
1729
  response.data.data = JSON.parse(response.data.data);
1697
1730
  if (response.data.data === null || !response.data.data.showToGuest) {
@@ -1779,7 +1812,8 @@ var Config = import_koishi9.Schema.object({
1779
1812
  redis_config: RedisConfigSchema.description("Redis配置"),
1780
1813
  mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
1781
1814
  tag_config: SaveConfigSchema.description("tag图片保存配置"),
1782
- repeat_config: RepeatConfigSchema.description("复读配置")
1815
+ repeat_config: RepeatConfigSchema.description("复读配置"),
1816
+ test: import_koishi9.Schema.string().description("测试")
1783
1817
  });
1784
1818
  var logger = new import_koishi9.Logger(name);
1785
1819
  var savePath = null;
@@ -1806,7 +1840,7 @@ async function apply(ctx, config) {
1806
1840
  if (config.function_config)
1807
1841
  registerKuroCommands(ctx, connected);
1808
1842
  if (dev_mode)
1809
- registerTestCommands(ctx);
1843
+ registerTestCommands(ctx, config);
1810
1844
  }
1811
1845
  __name(apply, "apply");
1812
1846
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { OpenRouterMessage } from '../../utils/ai_axios';
2
+ import { Session } from 'koishi';
3
+ declare function ocrImage(buffer: Buffer): Promise<string>;
4
+ declare function checkShitOrNot(session: Session, parttern_msg: string): Promise<OpenRouterMessage[]>;
5
+ export { checkShitOrNot, ocrImage };
@@ -1,3 +1,5 @@
1
1
  import { Context } from 'koishi';
2
- declare function registerTestCommands(ctx: Context): void;
2
+ import { Config } from '..';
3
+ declare function registerTestCommands(ctx: Context, config: Config): void;
4
+ export declare function ocrImage(buffer: Buffer): Promise<string>;
3
5
  export { registerTestCommands };
@@ -0,0 +1,17 @@
1
+ export interface OpenRouterMessage {
2
+ role: 'system' | 'user' | 'assistant';
3
+ content: string;
4
+ }
5
+ export interface OpenRouterResult {
6
+ err: string | null;
7
+ resp: string | null;
8
+ }
9
+ /**
10
+ * 调用 OpenRouter API 进行对话
11
+ * @param apiKey OpenRouter API Key
12
+ * @param messages 消息数组,包含系统消息和用户消息
13
+ * @param model 模型名称,默认为 gpt-4o-mini
14
+ * @returns 返回包含错误和响应的对象 { err: string | null, resp: string | null }
15
+ * err 不为 null 时表示出错,resp 不为 null 时表示成功
16
+ */
17
+ export declare function callOpenRouter(api_url: string, api_key: string, api_model: string, messages: OpenRouterMessage[]): Promise<OpenRouterResult>;
@@ -4,6 +4,7 @@ interface FunctionConfig {
4
4
  tag_flag: boolean;
5
5
  repeat_flag: boolean;
6
6
  rbq_flag: boolean;
7
+ shit_or_not_flag: boolean;
7
8
  kuro_flag: boolean;
8
9
  }
9
10
  declare const FunctionConfigSchema: Schema<FunctionConfig>;
@@ -0,0 +1,8 @@
1
+ import { Schema } from 'koishi';
2
+ interface ShitOrNotConfig {
3
+ api_url?: string;
4
+ api_model?: string;
5
+ api_key?: string;
6
+ }
7
+ declare const ShitOrNotConfigSchema: Schema<ShitOrNotConfig>;
8
+ export { ShitOrNotConfig, ShitOrNotConfigSchema, };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cocoyyy-console",
3
3
  "description": "自用koishi插件,功能包含复读,记录黑历史,*人等",
4
- "version": "1.0.16-beta.1",
4
+ "version": "1.0.16-beta.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [
@@ -25,6 +25,7 @@
25
25
  "mysql2": "^3.11.0",
26
26
  "qs": "^6.14.0",
27
27
  "sequelize": "^6.37.3",
28
- "ioredis": "^5.8.2"
28
+ "ioredis": "^5.8.2",
29
+ "tesseract.js": "^5.1.0"
29
30
  }
30
31
  }