From 7d9e504861076b9ee07f2a1763663d8493c6f625 Mon Sep 17 00:00:00 2001 From: stapxs <1007028430.stapx@gmail.com> Date: Tue, 13 Aug 2024 16:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=B7=E4=B8=8D=E4=BA=86=E4=B8=80=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit :sparkles: 客户端脚本支持!现在你可以通过编写 js 脚本来执行一些自动化操作;在 设置 - 高级 - 进阶功能 处打开它。 :bug: 修正获取历史会话异步异常的问题 :heavy_plus_sign: 新增依赖 prismjs、vue-prism-editor --- package.json | 5 +- src/App.vue | 22 +- src/assets/css/append/append_new.css | 43 +++ src/assets/css/append/append_vibrancy.css | 9 + src/assets/l10n/zh-CN.json | 12 + src/function/electron/ipc.ts | 57 +-- src/function/elements/information.ts | 3 + src/function/msg.ts | 14 + src/function/utils/appUtil.ts | 3 - src/function/utils/msgUtil.ts | 4 +- src/main.ts | 3 + src/pages/Scripts.vue | 418 ++++++++++++++++++++++ src/pages/options/OptDev.vue | 17 + 13 files changed, 572 insertions(+), 38 deletions(-) create mode 100644 src/pages/Scripts.vue diff --git a/package.json b/package.json index 17272d25..76097629 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stapxs-qq-lite", - "version": "2.7.18", + "version": "2.8.0", "private": false, "author": "Stapx Steve [林槐]", "description": "一个兼容 OneBot 的非官方网页版 QQ 客户端,使用 Vue 重制的全新版本。", @@ -17,6 +17,7 @@ "dependencies": { "@jakejarrett/gtk-theme": "^2.0.1", "@stapxs/umami-logger-typescript": "^1.0.12", + "@types/prismjs": "^1.26.4", "axios": "^1.7.2", "browser-image-compression": "^2.0.0", "core-js": "^3.8.3", @@ -28,6 +29,7 @@ "js-yaml-loader": "^1.2.2", "jsonpath": "^1.1.1", "pinyin": "^3.0.0-alpha.4", + "prismjs": "^1.29.0", "raw-loader": "^4.0.2", "register-service-worker": "^1.7.2", "semver-compare": "^1.0.0", @@ -39,6 +41,7 @@ "vue": "^3.2.13", "vue-clipboard2": "^0.3.3", "vue-i18n": "^9.2.2", + "vue-prism-editor": "^2.0.0-alpha.2", "vue3-bcui": "^0.2.3", "vue3-danmaku": "^1.6.0", "vue3-infinite-scroll-better": "^2.2.0", diff --git a/src/App.vue b/src/App.vue index e0e931fa..a9c4e7cd 100644 --- a/src/App.vue +++ b/src/App.vue @@ -11,18 +11,21 @@
+
+ +
header { + margin-top: 35px; +} +.script-view .list > header > span { + margin: 10px -5px 0 -5px; + font-size: 0.8rem; +} +.script-view .list-body { + margin: 0 -5px; +} +.script-view .list-body h2 { + font-size: 0.9rem; +} +.script-view .list-body span { + font-size: 0.8rem; +} +.script-view .list-body span svg { + margin: 0; + font-size: 0.75rem; +} +.script-view .editor-main { + box-shadow: -5px 0px 4px -5px var(--color-shader); +} +.script-view .save-controller > span, +.script-view .save-controller > svg { + font-size: 0.8rem; +} +.script-view .opt-item > select, +.script-view .ss-button { + height: 30px !important; +} +.script-view .ss-button, +.script-view .opt-item > select, +.script-view .ss-button > svg { + font-size: 0.75rem; +} +.script-view .editor { + font-size: 0.8rem; +} + @media (max-width: 700px) { .main-body > ul { background: var(--color-card-2) !important; diff --git a/src/assets/css/append/append_vibrancy.css b/src/assets/css/append/append_vibrancy.css index 39cfd48e..792ad0bc 100644 --- a/src/assets/css/append/append_vibrancy.css +++ b/src/assets/css/append/append_vibrancy.css @@ -89,6 +89,15 @@ left: 270px; } +.script-view { + background: rgba(var(--color-card-rgb), 0.6) !important; +} +.script-view .list > header > span, +.script-view .list-body > div { + background: transparent; + backdrop-filter: blur(10px); +} + @media (max-width: 500px) { .chat-pan > div.info { margin-top: 35px; diff --git a/src/assets/l10n/zh-CN.json b/src/assets/l10n/zh-CN.json index f86231e8..3a7216b5 100644 --- a/src/assets/l10n/zh-CN.json +++ b/src/assets/l10n/zh-CN.json @@ -321,6 +321,18 @@ "option_dev_chat_respond": "关闭回应功能", "option_dev_chat_respond_tip": "如果你不想用它或者 bot 不支持,可以关闭这个功能", "chat_jump_reply_fail": "(获取回复消息失败)", + "title_scripts": "脚本", + "scripts_tip": "脚本功能提供了一种简便的自动化操作方式,能够执行如自动回复等任务。", + "scripts_run_save": "保存", + "scripts_run_condition": "条件", + "scripts_run_trigger": "触发", + "scripts_run_message": "新消息", + "option_dev_append": "进阶功能", + "option_dev_scripts_tip": "显示脚本功能面板", + "statue_enabled": "已启用", + "statue_disabled": "已禁用", + "scripts_run_title_err": "脚本标题已存在", + "scripts_run_notice": "脚本方法将限制在当前页面内,你可以参考当前页面的源代码来了解可用的方法可用。", "menu_about": "关于", "menu_update": "检查更新…", diff --git a/src/function/electron/ipc.ts b/src/function/electron/ipc.ts index f43c8154..5e9db4ff 100644 --- a/src/function/electron/ipc.ts +++ b/src/function/electron/ipc.ts @@ -20,32 +20,32 @@ export function regIpcListener() { return os.release() }) // 代理请求 HTTP - ipcMain.on('sys:requestHttp', (event, args) => { - console.log(args) + // ipcMain.on('sys:requestHttp', (event, args) => { + // console.log(args) - const cookies = JSON.parse(args.cookies) - console.log(cookies) - const cookieStrs = Object.keys(cookies).map((key) => { - return key + '=' + cookies[key] - }) - console.log(cookieStrs.join('; ')) - // 异步请求,不需要立即返回 - axios({ - method: args.type, - url: args.url, - headers: { - 'Content-Type': 'application/json', - 'Cookie': cookieStrs.join('; '), - }, - data: args.data - }).then((res) => { - // res.data - console.log(res.data) - }).catch((err) => { - // err - console.error(err) - }) - }) + // const cookies = JSON.parse(args.cookies) + // console.log(cookies) + // const cookieStrs = Object.keys(cookies).map((key) => { + // return key + '=' + cookies[key] + // }) + // console.log(cookieStrs.join('; ')) + // // 异步请求,不需要立即返回 + // axios({ + // method: args.type, + // url: args.url, + // headers: { + // 'Content-Type': 'application/json', + // 'Cookie': cookieStrs.join('; '), + // }, + // data: args.data + // }).then((res) => { + // // res.data + // console.log(res.data) + // }).catch((err) => { + // // err + // console.error(err) + // }) + // }) // 关闭窗口 ipcMain.on('win:close', () => { if(win) win.close() @@ -63,6 +63,13 @@ export function regIpcListener() { app.relaunch() app.exit() }) + // 保存信息 + ipcMain.on('sys:store', (event, arg) => { + store.set(arg.key, arg.value) + }) + ipcMain.handle('sys:getStore', (event, key) => { + return store.get(key) + }) // 保存设置 // PS:升级至 electron 27 后 cookie 已完全无法持久化,只能进行保存 ipcMain.on('opt:saveAll', (event, arg) => { diff --git a/src/function/elements/information.ts b/src/function/elements/information.ts index 0cd17307..f35189c0 100644 --- a/src/function/elements/information.ts +++ b/src/function/elements/information.ts @@ -37,6 +37,9 @@ export interface RunTimeDataElem { classes: any[], sw?: boolean }, + watch: { // PS: 一些给监听器捕捉用的数据 + newMsg: any + }, messageList: any[] mergeMessageList?: any[] | undefined, stickerCache?: any[], diff --git a/src/function/msg.ts b/src/function/msg.ts index 8dca34c7..dc3ea131 100644 --- a/src/function/msg.ts +++ b/src/function/msg.ts @@ -33,6 +33,9 @@ const popInfo = new PopInfo() // eslint-disable-next-line let msgPath = require('@/assets/pathMap/Lagrange.OneBot.yaml') +// 其他 tag +let listLoadTimes = 0 + export function parse(str: string) { const msg = JSON.parse(str) if (msg.echo !== undefined) { @@ -244,6 +247,7 @@ function createRecentContact(data: any) { } function saveUser(msg: { [key: string]: any }, type: string) { + listLoadTimes ++ let list: any[] | undefined if(msgPath.user_list) list = getMsgData('user_list', msg, msgPath.user_list) @@ -324,6 +328,12 @@ function saveUser(msg: { [key: string]: any }, type: string) { value: app.config.globalProperties.$t('menu_user_list', { count: runtimeData.userList.length }) }) } + // 如果获取次数大于 0 并且是双数,刷新一下历史会话 + if(listLoadTimes > 0 && listLoadTimes % 2 == 0) { + // 获取最近的会话 + if(runtimeData.jsonMap.recent_contact) + Connector.send(runtimeData.jsonMap.recent_contact.name, {}, 'GetRecentContact') + } } function updateTopMsg(msg: any, echoList: string[]) { @@ -781,6 +791,7 @@ function newMsg(data: any) { return item.user_id == sender }) const isImportant = senderInfo?.class_id == 9999 + runtimeData.watch.newMsg = data // 消息回调检查 // PS:如果在新消息中获取到了自己的消息,则自动打开“停止消息回调”设置防止发送的消息重复 @@ -1170,6 +1181,9 @@ const baseRuntime = { connectSsl: false, classes: [] }, + watch: { + newMsg: {} + }, chatInfo: { show: { type: '', id: 0, name: '', avatar: '' }, info: { diff --git a/src/function/utils/appUtil.ts b/src/function/utils/appUtil.ts index 75e12fe7..d0f56797 100644 --- a/src/function/utils/appUtil.ts +++ b/src/function/utils/appUtil.ts @@ -155,9 +155,6 @@ export function reloadUsers() { Connector.send(groupName, {}, 'getGroupList') // 获取系统消息 Connector.send('get_system_msg', {}, 'getSystemMsg') - // 获取最近的会话 - if(runtimeData.jsonMap.recent_contact) - Connector.send(runtimeData.jsonMap.recent_contact.name, {}, 'GetRecentContact') } } diff --git a/src/function/utils/msgUtil.ts b/src/function/utils/msgUtil.ts index 6ff11cd4..85a531ba 100644 --- a/src/function/utils/msgUtil.ts +++ b/src/function/utils/msgUtil.ts @@ -390,7 +390,7 @@ export function sendMsgRaw(id: string, type: string, msg: string | { type: strin switch (type) { case 'group': Connector.send( - runtimeData.jsonMap.message_list.name_group_send ?? 'send_group_msg', + runtimeData.jsonMap.message_list.name_group_send ?? 'send_msg', { 'group_id': id, 'message': msg },'sendMsgBack_uuid_' + msgUUID); break case 'user': { @@ -400,7 +400,7 @@ export function sendMsgRaw(id: string, type: string, msg: string | { type: strin { 'user_id': id.split('/')[0], 'group_id': id.split('/')[1], 'message': msg }, 'sendMsgBack_uuid_' + msgUUID); } else { Connector.send( - runtimeData.jsonMap.message_list.name_user_send ?? 'send_private_msg', + runtimeData.jsonMap.message_list.name_user_send ?? 'send_msg', { 'user_id': id, 'message': msg }, 'sendMsgBack_uuid_' + msgUUID); } break diff --git a/src/main.ts b/src/main.ts index 5211bc8e..ef6d39a9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import VueViewer from 'v-viewer' import VueClipboard from 'vue-clipboard2' import InfiniteScroll from 'vue3-infinite-scroll-better' import packageInfo from '../package.json' +import { PrismEditor } from 'vue-prism-editor' import App from './App.vue' @@ -16,6 +17,7 @@ import { faSquare } from '@fortawesome/free-regular-svg-icons' import './registerServiceWorker' import 'viewerjs/dist/viewer.css' +import 'vue-prism-editor/dist/prismeditor.min.css' import './assets/css/view.css' import './assets/css/chat.css' @@ -48,6 +50,7 @@ app.use(InfiniteScroll) library.add(fas) library.add(faSquare) app.component('font-awesome-icon', FontAwesomeIcon) +app.component('PrismEditor', PrismEditor) app.mount('#app') export default app diff --git a/src/pages/Scripts.vue b/src/pages/Scripts.vue new file mode 100644 index 00000000..a6e6b7a6 --- /dev/null +++ b/src/pages/Scripts.vue @@ -0,0 +1,418 @@ + + + + + + + diff --git a/src/pages/options/OptDev.vue b/src/pages/options/OptDev.vue index 4bf37585..8f1e283b 100644 --- a/src/pages/options/OptDev.vue +++ b/src/pages/options/OptDev.vue @@ -7,6 +7,23 @@