From 880edace8aa5f09a1c58841051d15b46250260a0 Mon Sep 17 00:00:00 2001 From: zyc404 Date: Sun, 8 Oct 2023 18:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E9=80=82=E9=85=8DTrss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/view/setting_view.json | 6 ++++++ server/index.js | 20 ++++++++++---------- server/modules/user.js | 10 +++++----- utils/common.js | 8 ++++++++ utils/config.js | 2 ++ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/resources/view/setting_view.json b/resources/view/setting_view.json index 66aac7f..9aa8063 100644 --- a/resources/view/setting_view.json +++ b/resources/view/setting_view.json @@ -122,6 +122,12 @@ "label": "额外工具url", "placeholder": "测试期间提供一个公益接口,一段时间后撤掉", "data": "extraUrl" + }, + { + "type": "text", + "label": "Trss主账号", + "placeholder": "用于Trss配置脚本时使用的主账号", + "data": "trssBotUin" } ] }, diff --git a/server/index.js b/server/index.js index d3e46ee..56da027 100644 --- a/server/index.js +++ b/server/index.js @@ -12,7 +12,7 @@ import websocketclient from 'ws' import { Config } from '../utils/config.js' import { UserInfo, GetUser, AddUser } from './modules/user_data.js' -import { getPublicIP, getUserData, getMasterQQ, randomString } from '../utils/common.js' +import { getPublicIP, getUserData, getMasterQQ, randomString, getUin } from '../utils/common.js' import webRoute from './modules/web_route.js' import webUser from './modules/user.js' @@ -107,7 +107,7 @@ async function mediaLink() { ws.on('open', () => { ws.send(JSON.stringify({ command: 'register', - region: Bot.uin, + region: getUin(), type: 'server', })) }) @@ -128,30 +128,30 @@ async function mediaLink() { const user = UserInfo(data.token) if (user) { ws.login = true - ws.send(JSON.stringify({ command: data.command, state: true, region: Bot.uin, type: 'server' })) + ws.send(JSON.stringify({ command: data.command, state: true, region: getUin(), type: 'server' })) } else { - ws.send(JSON.stringify({ command: data.command, state: false, error: '权限验证失败', region: Bot.uin, type: 'server' })) + ws.send(JSON.stringify({ command: data.command, state: false, error: '权限验证失败', region: getUin(), type: 'server' })) } } break case 'post_login': if (data.qq && data.passwd) { const token = randomString(32) - if (data.qq == Bot.uin && await redis.get('CHATGPT:ADMIN_PASSWD') == data.passwd) { + if (data.qq == getUin() && await redis.get('CHATGPT:ADMIN_PASSWD') == data.passwd) { AddUser({ user: data.qq, token: token, autho: 'admin' }) - ws.send(JSON.stringify({ command: data.command, state: true, autho: 'admin', token: token, region: Bot.uin, type: 'server' })) + ws.send(JSON.stringify({ command: data.command, state: true, autho: 'admin', token: token, region: getUin(), type: 'server' })) } else { const user = await getUserData(data.qq) if (user.passwd != '' && user.passwd === data.passwd) { AddUser({ user: data.qq, token: token, autho: 'user' }) - ws.send(JSON.stringify({ command: data.command, state: true, autho: 'user', token: token, region: Bot.uin, type: 'server' })) + ws.send(JSON.stringify({ command: data.command, state: true, autho: 'user', token: token, region: getUin(), type: 'server' })) } else { - ws.send(JSON.stringify({ command: data.command, state: false, error: `用户名密码错误,如果忘记密码请私聊机器人输入 ${data.qq == Bot.uin ? '#修改管理密码' : '#修改用户密码'} 进行修改`, region: Bot.uin, type: 'server' })) + ws.send(JSON.stringify({ command: data.command, state: false, error: `用户名密码错误,如果忘记密码请私聊机器人输入 ${data.qq == getUin() ? '#修改管理密码' : '#修改用户密码'} 进行修改`, region: getUin(), type: 'server' })) } } } else { - ws.send(JSON.stringify({ command: data.command, state: false, error: '未输入用户名或密码', region: Bot.uin, type: 'server' })) + ws.send(JSON.stringify({ command: data.command, state: false, error: '未输入用户名或密码', region: getUin(), type: 'server' })) } break case 'post_command': @@ -163,7 +163,7 @@ async function mediaLink() { const response = await fetch(`http://localhost:${Config.serverPort || 3321}${data.postPath}`, fetchOptions) if (response.ok) { const json = await response.json() - ws.send(JSON.stringify({ command: data.command, state: true, region: Bot.uin, type: 'server', path: data.postPath, data: json })) + ws.send(JSON.stringify({ command: data.command, state: true, region: getUin(), type: 'server', path: data.postPath, data: json })) } break } diff --git a/server/modules/user.js b/server/modules/user.js index bc15482..a781a6b 100644 --- a/server/modules/user.js +++ b/server/modules/user.js @@ -1,5 +1,5 @@ import { UserInfo, AddUser } from './user_data.js' -import { randomString, getUserData, getMasterQQ } from '../../utils/common.js' +import { randomString, getUserData, getMasterQQ, getUin } from '../../utils/common.js' import fs from 'fs' async function User(fastify, options) { @@ -8,7 +8,7 @@ async function User(fastify, options) { const body = request.body || {} if (body.qq && body.passwd) { const token = randomString(32) - if (body.qq == Bot.uin && await redis.get('CHATGPT:ADMIN_PASSWD') == body.passwd) { + if (body.qq == getUin() && await redis.get('CHATGPT:ADMIN_PASSWD') == body.passwd) { AddUser({ user: body.qq, token: token, autho: 'admin' }) reply.setCookie('token', token, { path: '/' }) reply.send({ login: true, autho: 'admin', token: token }) @@ -19,16 +19,16 @@ async function User(fastify, options) { reply.setCookie('token', token, { path: '/' }) reply.send({ login: true, autho: 'user', token: token }) } else { - reply.send({ login: false, err: `用户名密码错误,如果忘记密码请私聊机器人输入 ${body.qq == Bot.uin ? '#修改管理密码' : '#修改用户密码'} 进行修改` }) + reply.send({ login: false, err: `用户名密码错误,如果忘记密码请私聊机器人输入 ${body.qq == getUin() ? '#修改管理密码' : '#修改用户密码'} 进行修改` }) } } } else if (body.otp) { const token = randomString(32) const opt = await redis.get(`CHATGPT:SERVER_QUICK`) if (opt && body.otp == opt) { - AddUser({ user: Bot.uin, token: token, autho: 'admin' }) + AddUser({ user: getUin(), token: token, autho: 'admin' }) reply.setCookie('token', token, { path: '/' }) - reply.send({ login: true, autho: 'admin', token: token, user: Bot.uin }) + reply.send({ login: true, autho: 'admin', token: token, user: getUin() }) } else { reply.send({ login: false, err: `快捷登录代码错误,请检查后重试` }) } diff --git a/utils/common.js b/utils/common.js index b25e51d..eba807e 100644 --- a/utils/common.js +++ b/utils/common.js @@ -821,6 +821,14 @@ export function getMaxModelTokens (model = 'gpt-3.5-turbo') { } } +export function getUin (e) { + if (e?.bot?.uin) return e.bot.uin + if (Array.isArray(Bot.uin)) { + if (Config.trssBotUin && Bot.uin.indexOf(Config.trssBotUin) > -1) return Config.trssBotUin + else return Bot.uin[0] + } else return Bot.uin +} + /** * 生成当前语音模式下可发送的音频信息 * @param e - 上下文对象 diff --git a/utils/config.js b/utils/config.js index c3ae38d..c7f9bfd 100644 --- a/utils/config.js +++ b/utils/config.js @@ -151,6 +151,8 @@ const defaultConfig = { claudeAITimeout: 120, claudeAIJA3: '772,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,27-5-65281-13-35-0-51-18-16-43-10-45-11-17513-23,29-23-24,0', claudeAIUA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36', + // trss配置 + trssBotUin: '', version: 'v2.7.5' } const _path = process.cwd()