diff --git a/dist/buildinfo.json b/dist/buildinfo.json index aaf19fd1..18a4d4fa 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "865d7a7", "timestamp": 1678544073} +{"sha": "94c81f1", "timestamp": 1678546663} diff --git a/dist/index.js b/dist/index.js index ec9863da..2401a347 100644 --- a/dist/index.js +++ b/dist/index.js @@ -30,15 +30,15 @@ var ENV = { // 全局默认初始化消息角色 SYSTEM_INIT_MESSAGE_ROLE: "system", // 是否开启使用统计 - ENABLE_USAGE_STATISTICS: true, + ENABLE_USAGE_STATISTICS: false, // 隐藏部分命令按钮 HIDE_COMMAND_BUTTONS: [], // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678544073, + BUILD_TIMESTAMP: 1678546663, // 当前版本 commit id - BUILD_VERSION: "865d7a7", + BUILD_VERSION: "94c81f1", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, @@ -245,7 +245,7 @@ async function sendMessageToTelegram(message, token, context) { console.log("\u6D88\u606F\u5C06\u5206\u6BB5\u53D1\u9001"); const limit = 4e3; chatContext.parse_mode = "HTML"; - for (let i = 0; i < string.length; i += limit) { + for (let i = 0; i < message.length; i += limit) { const msg = message.slice(i, i + limit); await sendMessage(`
${msg} @@ -435,6 +435,98 @@ async function updateBotUsage(usage) { await DATABASE.put(SHARE_CONTEXT.usageKey, JSON.stringify(dbValue)); } +// src/utils.js +function randomString(length) { + const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + let result = ""; + for (let i = length; i > 0; --i) + result += chars[Math.floor(Math.random() * chars.length)]; + return result; +} +async function historyPassword() { + let password = await DATABASE.get(CONST.PASSWORD_KEY); + if (password === null) { + password = randomString(32); + await DATABASE.put(CONST.PASSWORD_KEY, password); + } + return password; +} +function renderHTML(body) { + return ` + + +ChatGPT-Telegram-Workers + + + + + + + + ${body} + + + `; +} +function errorToString(e) { + return JSON.stringify({ + message: e.message, + stack: e.stack + }); +} +function mergeConfig(config, key, value) { + switch (typeof config[key]) { + case "number": + config[key] = Number(value); + break; + case "boolean": + config[key] = value === "true"; + break; + case "string": + config[key] = value; + break; + case "object": + const object = JSON.parse(value); + if (typeof object === "object") { + config[key] = object; + break; + } + throw new Error("\u4E0D\u652F\u6301\u7684\u914D\u7F6E\u9879\u6216\u6570\u636E\u7C7B\u578B\u9519\u8BEF"); + default: + throw new Error("\u4E0D\u652F\u6301\u7684\u914D\u7F6E\u9879\u6216\u6570\u636E\u7C7B\u578B\u9519\u8BEF"); + } +} + // src/command.js var commandAuthCheck = { default: function() { @@ -503,7 +595,7 @@ var commandHandlers = { }, "/role": { help: "\u8BBE\u7F6E\u9884\u8BBE\u7684\u8EAB\u4EFD", - scopes: ["all_private_chats", "all_chat_administrators"], + scopes: ["all_private_chats"], fn: commandUpdateRole, needAuth: commandAuthCheck.shareModeGroup } @@ -563,26 +655,7 @@ async function commandUpdateRole(message, command, subcommand) { }; } try { - switch (typeof USER_DEFINE.ROLE[role][key]) { - case "number": - USER_DEFINE.ROLE[role][key] = Number(value); - break; - case "boolean": - USER_DEFINE.ROLE[role][key] = value === "true"; - break; - case "string": - USER_DEFINE.ROLE[role][key] = value; - break; - case "object": - const object = JSON.parse(value); - if (typeof object === "object") { - USER_DEFINE.ROLE[role][key] = object; - break; - } - return sendMessageToTelegram("\u4E0D\u652F\u6301\u7684\u914D\u7F6E\u9879\u6216\u6570\u636E\u7C7B\u578B\u9519\u8BEF"); - default: - return sendMessageToTelegram("\u4E0D\u652F\u6301\u7684\u914D\u7F6E\u9879\u6216\u6570\u636E\u7C7B\u578B\u9519\u8BEF"); - } + mergeConfig(USER_DEFINE.ROLE[role], key, value); await DATABASE.put( SHARE_CONTEXT.configStoreKey, JSON.stringify(Object.assign(USER_CONFIG, { USER_DEFINE })) @@ -643,26 +716,7 @@ async function commandUpdateUserConfig(message, command, subcommand) { const key = subcommand.slice(0, kv); const value = subcommand.slice(kv + 1); try { - switch (typeof USER_CONFIG[key]) { - case "number": - USER_CONFIG[key] = Number(value); - break; - case "boolean": - USER_CONFIG[key] = value === "true"; - break; - case "string": - USER_CONFIG[key] = value; - break; - case "object": - const object = JSON.parse(value); - if (typeof object === "object") { - USER_CONFIG[key] = object; - break; - } - return sendMessageToTelegram("\u4E0D\u652F\u6301\u7684\u914D\u7F6E\u9879\u6216\u6570\u636E\u7C7B\u578B\u9519\u8BEF"); - default: - return sendMessageToTelegram("\u4E0D\u652F\u6301\u7684\u914D\u7F6E\u9879\u6216\u6570\u636E\u7C7B\u578B\u9519\u8BEF"); - } + mergeConfig(USER_CONFIG, key, value); await DATABASE.put( SHARE_CONTEXT.configStoreKey, JSON.stringify(USER_CONFIG) @@ -841,76 +895,6 @@ function commandsDocument() { }); } -// src/utils.js -function randomString(length) { - const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - let result = ""; - for (let i = length; i > 0; --i) - result += chars[Math.floor(Math.random() * chars.length)]; - return result; -} -async function historyPassword() { - let password = await DATABASE.get(CONST.PASSWORD_KEY); - if (password === null) { - password = randomString(32); - await DATABASE.put(CONST.PASSWORD_KEY, password); - } - return password; -} -function renderHTML(body) { - return ` - - -ChatGPT-Telegram-Workers - - - - - - - - ${body} - - - `; -} -function errorToString(e) { - return JSON.stringify({ - message: e.message, - stack: e.stack - }); -} - // src/message.js var MAX_TOKEN_LENGTH = 2048; async function msgInitChatContext(message) { diff --git a/dist/timestamp b/dist/timestamp index 75831174..690d0679 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678544073 +1678546663 diff --git a/src/command.js b/src/command.js index d2d0ca63..b79dfa78 100644 --- a/src/command.js +++ b/src/command.js @@ -2,7 +2,7 @@ import {sendMessageToTelegram, sendPhotoToTelegram, sendChatActionToTelegram, ge import {DATABASE, ENV, CONST} from './env.js'; import {SHARE_CONTEXT, USER_CONFIG, CURRENT_CHAT_CONTEXT, USER_DEFINE} from './context.js'; import {requestImageFromOpenAI} from './openai.js'; -import { mergeConfig } from './utils.js'; +import {mergeConfig} from './utils.js'; const commandAuthCheck = { default: function() { @@ -74,7 +74,7 @@ const commandHandlers = { }, '/role': { help: '设置预设的身份', - scopes: ['all_private_chats', 'all_chat_administrators'], + scopes: ['all_private_chats'], fn: commandUpdateRole, needAuth: commandAuthCheck.shareModeGroup, }, @@ -216,7 +216,7 @@ async function commandUpdateUserConfig(message, command, subcommand) { const key = subcommand.slice(0, kv); const value = subcommand.slice(kv + 1); try { - mergeConfig(USER_CONFIG, key, value) + mergeConfig(USER_CONFIG, key, value); await DATABASE.put( SHARE_CONTEXT.configStoreKey, JSON.stringify(USER_CONFIG), diff --git a/src/utils.js b/src/utils.js index d54e393a..c90ef293 100644 --- a/src/utils.js +++ b/src/utils.js @@ -94,4 +94,4 @@ export function mergeConfig(config, key, value) { default: throw new Error('不支持的配置项或数据类型错误'); } -} \ No newline at end of file +}