From cbdb23708fc859e965ac9d548819f1bb627833e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=89=E9=A3=8E=E6=9D=A5?= <3139373986@qq.com> Date: Wed, 5 Jun 2024 02:42:01 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20=E7=BB=86=E8=8A=82=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 等风来 <3139373986@qq.com> --- CHANGELOG.md | 7 +++ apps/assistant.js | 51 ------------------- apps/assistant/other.js | 88 +++++++++++++++++++++++++++------ config/system/gpAdmin_system.js | 10 ++-- config/system/help_system.js | 38 ++++++++++---- 5 files changed, 114 insertions(+), 80 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0849ae..89f2879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.4.7 +* 新增`#投票踢人`命令ⁿᵉʷ +* 优化发好友、发群聊 + * 消息为空后可单独发送,以支持更多消息类型 +* 新增`#ocr`命令ⁿᵉʷ +* 修复同意回复 + # 1.4.6 * 状态新增默认背景图随机,`backdrop`配置设置为false则一直使用默认背景图ⁿᵉʷ * 默认背景图路径修改为**resources/state/img/bg**目录下请将背景图移至该目录 diff --git a/apps/assistant.js b/apps/assistant.js index c3dca6e..eee83dd 100644 --- a/apps/assistant.js +++ b/apps/assistant.js @@ -2,9 +2,7 @@ import _ from "lodash" import { status } from "../constants/other.js" import { common, QQApi } from "../model/index.js" import { sleep } from "../tools/index.js" -import { Config } from "../components/index.js" import { API_ERROR } from "../constants/errorMsg.js" -import cfg from "../../../lib/config/config.js" // 命令正则 @@ -80,14 +78,6 @@ export class Assistant extends plugin { { reg: "^#设置机型", fnc: "setModel" - }, - { - reg: "^#?(查?看|取)(群)?头像", - fnc: "LookAvatar" - }, - { - reg: "^#?(设置|修改)日志等级", - fnc: "logs" } ] }) @@ -530,45 +520,4 @@ export class Assistant extends plugin { let res = await new QQApi(e).setModel(model).catch(err => logger.error(err)) e.reply(_.get(res, [ "13031", "data", "rsp", "iRet" ]) == 0 ? "设置成功" : "设置失败") } - - /** - * 查看头像 - */ - async LookAvatar() { - try { - let id, url - if (this.e.msg.includes("群")) { - id = this.e.msg.replace(/^#?(查?看|取)(群)?头像/, "").trim() || this.e.group_id - url = await this.e.bot.pickGroup(id).getAvatarUrl() - } else { - id = this.e.msg.replace(/^#?(查?看|取)(群)?头像/, "").trim() || this.e.at || this.e.message.find(item => item.type == "at")?.qq || this.e.user_id - url = await this.e.group?.pickMember(id)?.getAvatarUrl() - if (!url) url = await this.e.bot.pickFriend(id).getAvatarUrl() - } - const msgTest = this.e.msg.includes("取") - if (url) return await this.e.reply(msgTest ? `${url}` : segment.image(url), true) - } catch (error) { - logger.error("获取头像错误", error) - } - await this.reply("❎ 获取头像错误", true) - return false - } - - /** - * 设置日志等级 - */ - async logs() { - if (!common.checkPermission(this.e, "master")) return - - const logs = [ "trace", "debug", "info", "warn", "fatal", "mark", "error", "off" ] - const level = this.e.msg.replace(/^#?(设置|修改)日志等级/, "").trim() - - if (!logs.includes(level)) return this.e.reply("❎ 请输入正确的参数,可选:\ntrace,debug,info,warn,fatal,mark,error,off") - - const { log_level } = cfg.bot - if (log_level === level) return this.e.reply(`❎ 日志等级已是${level}了`) - - Config.modify("bot", "log_level", level, "config", true) - this.e.reply(`✅ 已将日志等级设置为${level}`) - } } diff --git a/apps/assistant/other.js b/apps/assistant/other.js index 3e9d880..9a27ffd 100644 --- a/apps/assistant/other.js +++ b/apps/assistant/other.js @@ -1,5 +1,7 @@ -import { common } from "../../model/index.js" import _ from "lodash" +import { Config } from "../../components/index.js" +import { common } from "../../model/index.js" +import cfg from "../../../../lib/config/config.js" export class Assistant_Other extends plugin { constructor() { @@ -17,10 +19,17 @@ export class Assistant_Other extends plugin { fnc: "Face" }, { - reg: "^#ocr", + reg: "^#(ocr|提?取文字)", fnc: "imageOcr" + }, + { + reg: "^#?(查?看|取)(群)?头像", + fnc: "LookAvatar" + }, + { + reg: "^#?(设置|修改)日志等级", + fnc: "logs" } - ] }) } @@ -98,19 +107,29 @@ export class Assistant_Other extends plugin { } } + /** + * 图片提取文字 + * @param e + */ async imageOcr(e) { - const imageOcr = e.bot.imageOcr?.bind(e.bot) || Bot.imageOcr - if (!imageOcr) return this.reply("❎ 当前协议暂不支持OCR") - const sourceImg = await common.takeSourceMsg(e, { img: true }) - const img = sourceImg || e.img - if (_.isEmpty(img)) { - this.setContext("_imageOcrContext") - return this.reply("⚠ 请发送图片") + try { + const imageOcr = e.bot?.imageOcr?.bind(e.bot) || Bot.imageOcr + if (!imageOcr) return this.reply("❎ 当前协议暂不支持OCR") + const sourceImg = await common.takeSourceMsg(e, { img: true }) + const img = sourceImg || e.img + if (_.isEmpty(img)) { + this.setContext("_imageOcrContext") + return this.reply("⚠ 请发送图片") + } + let res = await imageOcr(img[0]) + let r = res?.wordslist?.map(i => i.words).join("\n") + if (!r) return e.reply("❎ 发生错误,请稍后再试。") + e.reply(r, true) + return true + } catch (error) { + e.reply("❎ 发生错误,请稍后再试。") + logger.error("获取OCR错误:", error) } - let res = await imageOcr(img[0]) - let r = res.wordslist.map(i => i.words).join("\n") - e.reply(r) - return true } async _imageOcrContext(e) { @@ -126,4 +145,45 @@ export class Assistant_Other extends plugin { this.imageOcr(e) this.finish("_imageOcrContext") } + + /** + * 查看头像 + */ + async LookAvatar() { + try { + let id, url + if (this.e.msg.includes("群")) { + id = this.e.msg.replace(/^#?(查?看|取)(群)?头像/, "").trim() || this.e.group_id + url = await this.e.bot.pickGroup(id).getAvatarUrl() + } else { + id = this.e.msg.replace(/^#?(查?看|取)(群)?头像/, "").trim() || this.e.at || this.e.message.find(item => item.type == "at")?.qq || this.e.user_id + url = await this.e.group?.pickMember(id)?.getAvatarUrl() + if (!url) url = await this.e.bot.pickFriend(id).getAvatarUrl() + } + const msgTest = this.e.msg.includes("取") + if (url) return await this.e.reply(msgTest ? `${url}` : segment.image(url), true) + } catch (error) { + logger.error("获取头像错误", error) + } + await this.reply("❎ 获取头像错误", true) + return false + } + + /** + * 设置日志等级 + */ + async logs() { + if (!common.checkPermission(this.e, "master")) return + + const logs = [ "trace", "debug", "info", "warn", "fatal", "mark", "error", "off" ] + const level = this.e.msg.replace(/^#?(设置|修改)日志等级/, "").trim() + + if (!logs.includes(level)) return this.e.reply("❎ 请输入正确的参数,可选:\ntrace,debug,info,warn,fatal,mark,error,off") + + const { log_level } = cfg.bot + if (log_level === level) return this.e.reply(`❎ 日志等级已是${level}了`) + + Config.modify("bot", "log_level", level, "config", true) + this.e.reply(`✅ 已将日志等级设置为${level}`) + } } diff --git a/config/system/gpAdmin_system.js b/config/system/gpAdmin_system.js index 1f7fc87..a70f4fd 100644 --- a/config/system/gpAdmin_system.js +++ b/config/system/gpAdmin_system.js @@ -199,18 +199,18 @@ export const helpList = [ } ] }, { - group: "投票禁言(更多配置请看config/groupAdmin.yaml)", + group: "群投票(更多配置请看config/groupAdmin.yaml)", list: [ { - title: "#(启用|禁用)投票禁言", + title: "#(启用|禁用)投票(禁言|踢人)", desc: "是否允许群员投票", icon: 4 }, { - title: "#投票禁言<@QQ>", - desc: "投票禁言不听话的群员", + title: "#投票(禁言|踢人)<@QQ>", + desc: "投票裁决不听话的群员", icon: 6 }, { - title: "#(支持|反对)禁言<@QQ>", + title: "#(支持|反对)投票<@QQ>", desc: "跟随投票", icon: 12 }, { diff --git a/config/system/help_system.js b/config/system/help_system.js index e994df2..220f612 100644 --- a/config/system/help_system.js +++ b/config/system/help_system.js @@ -99,13 +99,9 @@ export const helpList = [ icon: 14 }, { - title: "#拉黑 #取消拉黑", - desc: "可带at或直接键入qq,拉黑后面可带\"群\"", + title: "#拉(黑|白) #取消拉(黑|白)", + desc: "可带at或直接键入qq,后面可带\"群\"", icon: 13 - }, { - title: "#拉白 #取消拉白", - desc: "用法与 #拉黑 相同", - icon: 14 } ] }, @@ -243,10 +239,6 @@ export const helpList = [ icon: 19, title: "#桌游排行", desc: "桌游排行" - }, { - title: "#(看|取)(群)?头像 <@QQ>", - desc: "查看用户/群的高清头像图片", - icon: 16 } ] }, @@ -280,6 +272,32 @@ export const helpList = [ } ] }, + { + group: "其他", + list: [ + { + title: "#取直链", + desc: "取一条图片直链", + icon: 5 + }, { + title: "#取face", + desc: "取表情id", + icon: 11 + }, { + title: "#ocr", + desc: "图片取文字", + icon: 3 + }, { + title: "#(看|取)(群)?头像 <@QQ>", + desc: "查看用户/群的高清头像图片", + icon: 16 + }, { + title: "#设置日志等级 <参数>", + desc: "设置控制台日志等级", + icon: 6 + } + ] + }, { group: "设置,版本相关", auth: "master",