From d52dc665f435bf7ba4eec5ab43eba631d9782208 Mon Sep 17 00:00:00 2001 From: yeyang <746659424@qq.com> Date: Tue, 23 Apr 2024 21:13:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E6=B0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assistant.js | 374 ++--------------------------- apps/assistant/BlockOne.js | 130 ++++++++++ apps/assistant/Qzone.js | 148 ++++++++++++ apps/assistant/sendMsg.js | 128 ++++++++++ apps/fun.js | 32 --- apps/groupAdmin/groupAdminOther.js | 4 +- apps/groupAdmin/groupAnnounce.js | 4 +- apps/groupAdmin/groupLuckyword.js | 4 +- constants/errorMsg.js | 2 + 9 files changed, 429 insertions(+), 397 deletions(-) create mode 100644 apps/assistant/BlockOne.js create mode 100644 apps/assistant/Qzone.js create mode 100644 apps/assistant/sendMsg.js create mode 100644 constants/errorMsg.js diff --git a/apps/assistant.js b/apps/assistant.js index 22455c0..3e8a852 100644 --- a/apps/assistant.js +++ b/apps/assistant.js @@ -1,19 +1,11 @@ import _ from "lodash" -import moment from "moment" -import fs from "node:fs" -import yaml from "yaml" -import { Config, Version } from "../components/index.js" import { status } from "../constants/other.js" import { common, QQApi } from "../model/index.js" import { sleep } from "../tools/index.js" - -/** API请求错误文案 */ -const API_ERROR = "❎ 出错辣,请稍后重试" +import { API_ERROR } from "../constants/errorMsg.js" // 命令正则 -let FriendsReg = /^#发好友\s?(\d+)\s?([^]*)$/ -let GroupMsgReg = /^#发群聊\s?(\d+)\s?([^]*)$/ -let GroupListMsgReg = /^#发群列表\s?(\d+(,\d+){0,})\s?([^]*)$/ + let friendTypeReg = /^#更改好友申请方式([0123])((.*)\s(.*))?$/ export class Assistant extends plugin { @@ -39,18 +31,6 @@ export class Assistant extends plugin { reg: "^#改状态", fnc: "SetOnlineStatus" }, - { - reg: FriendsReg, // 发好友 - fnc: "SendFriendMsg" - }, - { - reg: GroupMsgReg, // 发群聊 - fnc: "SendGroupMsg" - }, - { - reg: GroupListMsgReg, // 发群列表 - fnc: "SendGroupListMsg" - }, { reg: "^#退群", fnc: "QuitGroup" @@ -71,22 +51,6 @@ export class Assistant extends plugin { reg: "^#取face", fnc: "Face" }, - { - reg: "^#获?取说说列表(\\d+)?$", - fnc: "Qzonelist" - }, - { - reg: "^#删说说(\\d+)$", - fnc: "Qzonedel" - }, - { - reg: "^#发说说", - fnc: "Qzonesay" - }, - { - reg: "^#(清空说说|清空留言)$", - fnc: "QzonedelAll" - }, { reg: "^#改群名片", fnc: "SetGroupCard" @@ -124,12 +88,8 @@ export class Assistant extends plugin { fnc: "setModel" }, { - reg: "^#拉[黑白](群聊?)?", - fnc: "BlockOne" - }, - { - reg: "^#(取消|(删|移)除)拉[黑白](群聊?)?", - fnc: "CancelBlockOne" + reg: "^#?(查?看|取)头像", + fnc: "LookAvatar" } ] }) @@ -367,104 +327,6 @@ export class Assistant extends plugin { return true } - /** - * 发好友 - * @param e - */ - async SendFriendMsg(e) { - if (!common.checkPermission(e, "master")) return - let regRet = FriendsReg.exec(e.msg) - let qq = regRet[1] - e.message[0].text = regRet[2] - if (!/^\d+$/.test(qq)) return e.reply("❎ QQ号不正确,人家做不到的啦>_<~") - - if (!this.Bot.fl.get(Number(qq))) return e.reply("❎ 好友列表查无此人") - - if (!e.message[0].text) e.message.shift() - - if (e.message.length === 0) return e.reply("❎ 消息不能为空") - - await this.Bot.pickFriend(qq).sendMsg(e.message) - .then(() => e.reply("✅ 私聊消息已送达")) - .catch(err => common.handleException(e, err, { MsgTemplate: "❎ 发送失败\n错误信息为:{error}" })) - } - - /** - * 发群聊 - * @param e - */ - async SendGroupMsg(e) { - if (!common.checkPermission(e, "master")) return - let regRet = GroupMsgReg.exec(e.msg) - - let gpid = regRet[1] - - e.message[0].text = regRet[2] - - if (!e.message[0].text) e.message.shift() - - if (e.message.length === 0) return e.reply("❎ 消息不能为空") - - if (!/^\d+$/.test(gpid)) return e.reply("❎ 您输入的群号不合法") - - if (!this.Bot.gl.get(Number(gpid))) return e.reply("❎ 群聊列表查无此群") - - await this.Bot.pickGroup(gpid).sendMsg(e.message) - .then(() => e.reply("✅ 群聊消息已送达")) - .catch((err) => common.handleException(e, err, { MsgTemplate: "❎ 发送失败\n错误信息为:{error}" })) - } - - // 发送群列表 - async SendGroupListMsg(e) { - if (!common.checkPermission(e, "master")) return - // 获取参数 - let regRet = GroupListMsgReg.exec(e.msg) - let gpid = regRet[1] - e.message[0].text = regRet[3] - - if (!e.message[0].text) e.message.shift() - - if (e.message.length === 0) return e.reply("❎ 消息不能为空") - - let groupidList = [] - let sendList = [] - - // 获取群列表 - let listMap = Array.from(this.Bot.gl.values()) - - listMap.forEach((item) => { - groupidList.push(item.group_id) - }) - - let groupids = gpid.split(",") - - if (!groupids.every(item => item <= groupidList.length)) return e.reply("❎ 序号超过合法值!!!") - - groupids.forEach((item) => { - sendList.push(groupidList[Number(item) - 1]) - }) - - if (sendList.length > 3) return e.reply("❎ 不能同时发太多群聊,号寄概率增加!!!") - - if (sendList.length === 1) { - await this.Bot.pickGroup(sendList[0]).sendMsg(e.message) - .then(() => e.reply("✅ " + sendList[0] + " 群聊消息已送达")) - .catch((err) => - common.handleException(e, err, { MsgTemplate: `❎ ${sendList[0]} 发送失败\n错误信息为:{error}` }) - ) - } else { - e.reply("发送多个群聊,将每5秒发送一条消息!") - for (let i of sendList) { - await this.Bot.pickGroup(i).sendMsg(e.message) - .then(() => e.reply("✅ " + i + " 群聊消息已送达")) - .catch((err) => - common.handleException(e, err, { MsgTemplate: `❎ ${i} 发送失败\n错误信息为:{error}` })) - await sleep(5000) - } - } - return false - } - /** * 退群 * @param e @@ -630,122 +492,6 @@ export class Assistant extends plugin { } } - /** - * QQ空间 说说列表 - * @param e - */ - async Qzonelist(e) { - if (!common.checkPermission(e, "master")) return - let page = e.msg.replace(/#|获?取说说列表/g, "").trim() - if (!page) { - page = 0 - } else { - page = page - 1 - } - - // 获取说说列表 - let list = await new QQApi(e).getQzone(5, page * 5) - - if (!list) return e.reply(API_ERROR) - if (list.total == 0) return e.reply("✅ 说说列表为空") - - let msg = [ - "✅ 获取成功,说说列表如下:\n", - ...list.msglist.map((item, index) => - `${page * 5 + index + 1}.${_.truncate(item.content, { length: 15 })}\n- [${item.secret ? "私密" : "公开"}] | ${moment(item.created_time * 1000).format("MM/DD HH:mm")} | ${item.commentlist?.length || 0}条评论\n` - ), - `页数:[${page + 1}/${Math.ceil(list.total / 5)}]` - ] - e.reply(msg) - } - - /** - * 删除说说 - * @param e - */ - async Qzonedel(e) { - if (!common.checkPermission(e, "master")) return - let pos = e.msg.match(/\d+/) - // 获取说说列表 - let list = await new QQApi(e).getQzone(1, pos - 1) - - if (!list) return e.reply(API_ERROR) - if (!list.msglist) return e.reply("❎ 未获取到该说说") - - // 要删除的说说 - let domain = list.msglist[0] - // 请求接口 - let result = await new QQApi(e).delQzone(domain.tid, domain.t1_source) - if (!result) return e.reply(API_ERROR) - // debug - logger.debug(e.logFnc, result) - - if (result.subcode != 0) e.reply("❎ 未知错误" + JSON.parse(result)) - // 发送结果 - e.reply(`✅ 删除说说成功:\n ${pos}.${_.truncate(domain.content, { length: 15 })} \n - [${domain.secret ? "私密" : "公开"}] | ${moment(domain.created_time * 1000).format("MM/DD HH:mm")} | ${domain.commentlist?.length || 0} 条评论`) - } - - /** - * 发说说 - * @param e - */ - async Qzonesay(e) { - if (!common.checkPermission(e, "master")) return - let con = e.msg.replace(/#|发说说/g, "").trim() - let result = await new QQApi(e).setQzone(con, e.img) - if (!result) return e.reply(API_ERROR) - - if (result.code != 0) return e.reply(`❎ 说说发表失败\n${JSON.stringify(result)}`) - - let msg = [ "✅ 说说发表成功,内容:\n", _.truncate(result.content, { length: 15 }) ] - if (result.pic) { - msg.push(segment.image(result.pic[0].url1)) - } - msg.push(`\n- [${result.secret ? "私密" : "公开"}] | ${moment(result.t1_ntime * 1000).format("MM/DD HH:mm")}`) - e.reply(msg) - } - - /** - * 清空说说和留言 - * @param e - */ - async QzonedelAll(e) { - if (!common.checkPermission(e, "master")) return - if (/清空说说/.test(e.msg)) { - this.setContext("_QzonedelAllContext") - e.reply("✳️ 即将删除全部说说请发送:\n" + "------确认清空或取消------") - e.Qzonedetermine = true - } else if (/清空留言/.test(e.msg)) { - this.setContext("_QzonedelAllContext") - e.reply("✳️ 即将删除全部留言请发送:\n" + "------确认清空或取消------") - e.Qzonedetermine = false - } - } - - async _QzonedelAllContext(e) { - let msg = this.e.msg - if (/#?确认清空/.test(msg)) { - this.finish("_QzonedelAllContext") - let result - if (e.Qzonedetermine) { - result = await new QQApi(this.e).delQzoneAll() - } else { - result = await new QQApi(this.e).delQzoneMsgbAll() - } - - this.e.reply(result) - return true - } else if (/#?取消/.test(msg)) { - this.finish("_QzonedelAllContext") - this.e.reply("✅ 已取消") - return false - } else { - this.setContext("_QzonedelAllContext") - this.e.reply("❎ 请输入:确认清空或取消") - return false - } - } - // 获取群|好友列表 async GlOrFl(e) { if (!common.checkPermission(e, "master")) return @@ -859,109 +605,19 @@ export class Assistant extends plugin { e.reply(_.get(res, [ "13031", "data", "rsp", "iRet" ]) == 0 ? "设置成功" : "设置失败") } - async BlockOne(e) { - if (!common.checkPermission(e, "master")) return - let type = "" - let name = "拉" - if (/^#拉白(群聊?)?/.test(this.e.msg)) { - type += "white" - name += "白" - } else { - type += "black" - name += "黑" - } - if (/^#拉[黑白](群聊?)/.test(this.e.msg)) { - type += "Group" - name += "群" - } else { - type += Version.name == "TRSS-Yunzai" ? "User" : "QQ" - } - const configPath = "config/config/other.yaml" - /** 判断at */ - if (this.e.at) { - this.blackResult = this.e.at - } else { - if (Version.name == "TRSS-Yunzai") { - /** TRSS-Yunzai匹配所有字符 */ - const blackId = this.e.msg.replace(/^#拉[黑白](群聊?)?/, "").trim() - this.blackResult = Number(blackId) || String(blackId) - } else { - const match = this.e.msg.match(/\d+/) - if (match?.[0]) { this.blackResult = Number(match[0]) || String(match[0]) } - } - } - if (!this.blackResult || common.getPermission(new Proxy({ - get isMaster() { return Config.masterQQ.includes(this.user_id) || Config.masterQQ.includes(String(this.user_id)) }, - user_id: this.blackResult - }, { - get: (target, prop, receiver) => target[prop] ?? e[prop] - }), "master") === true) { return this.e.reply(`❎ ${name}失败,没有键入用户或群号`) } + // 查看头像 + async LookAvatar() { + const id = this.e.msg.replace(/^#?((查?看头像)|取头像)/, "").trim() || this.e.at || + this.e.message.find(item => item.type == "at")?.qq || this.e.user_id try { - const yamlContentBuffer = await fs.promises.readFile(configPath) - const yamlContent = yamlContentBuffer.toString("utf-8") - const data = yaml.parse(yamlContent) - if (!Array.isArray(data[type])) { data[type] = [] } - if (!data[type].includes(this.blackResult)) { - data[type].push(this.blackResult) - const updatedYaml = yaml.stringify(data, { quote: false }) - const resultYaml = updatedYaml.replace(/"/g, "") - await fs.promises.writeFile(configPath, resultYaml, "utf-8") - await this.e.reply(`✅ 已把这个坏淫${name}掉惹!!!`) - } else { - await this.e.reply(`❎ 已把这个坏淫${name}过辣`) - } + let 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)) } catch (error) { - await this.e.reply(`❎ 额...${name}失败哩,可能这个淫比较腻害>_<`) - logger.error(error) - } - } - - async CancelBlockOne(e) { - if (!common.checkPermission(e, "master")) return - let type = "" - let name = "取消拉" - if (/^#(取消|删除|移除)(群聊?)?拉白(群聊?)?/.test(this.e.msg)) { - type += "white" - name += "白" - } else { - type += "black" - name += "黑" - } - if (/^#(取消|删除|移除)拉[黑白](群聊?)/.test(this.e.msg)) { - type += "Group" - name += "群" - } else { - type += Version.name == "TRSS-Yunzai" ? "User" : "QQ" - } - const configPath = "config/config/other.yaml" - if (this.e.at) { - this.blackResult = this.e.at - } else { - if (Version.name == "TRSS-Yunzai") { - const blackId = this.e.msg.replace(/^#(取消|(删|移)除)拉[黑白](群聊?)?/, "").trim() - this.blackResult = Number(blackId) || String(blackId) - } else { - const match = this.e.msg.match(/\d+/) - if (match?.[0]) { this.blackResult = Number(match[0]) || String(match[0]) } - } - } - if (!this.blackResult) { return this.e.reply(`❎ ${name}失败,没有键入用户或群号`) } - try { - const yamlContentBuffer = await fs.promises.readFile(configPath) - const yamlContent = yamlContentBuffer.toString("utf-8") - const data = yaml.parse(yamlContent) - if (Array.isArray(data[type]) && data[type].includes(this.blackResult)) { - const itemToRemove = this.blackResult.toString() - data[type] = data[type].filter(item => item.toString() !== itemToRemove) - const updatedYaml = yaml.stringify(data) - await fs.promises.writeFile(configPath, updatedYaml, "utf-8") - await this.e.reply(`✅ 已把这个坏淫${name}掉惹!!!`) - } else { - await this.e.reply(`❎ ${name}失败,找不到辣>_<`) - } - } catch (error) { - await this.e.reply(`❎ 额...${name}失败哩,可能这个淫比较腻害>_<`) - logger.error(error) + logger.error("获取头像错误", error) } + await this.reply("❎ 获取头像错误", true) + return false } } diff --git a/apps/assistant/BlockOne.js b/apps/assistant/BlockOne.js new file mode 100644 index 0000000..62e6883 --- /dev/null +++ b/apps/assistant/BlockOne.js @@ -0,0 +1,130 @@ +import fs from "node:fs" +import yaml from "yaml" +import { Config, Version } from "../../components/index.js" +import { common } from "../../model/index.js" + +export class BlockOne extends plugin { + constructor() { + super({ + name: "椰奶助手-拉黑白名单", + event: "message.group", + priority: 500, + rule: [ + { + reg: "^#拉[黑白](群聊?)?", + fnc: "BlockOne" + }, + { + reg: "^#(取消|(删|移)除)拉[黑白](群聊?)?", + fnc: "CancelBlockOne" + } + ] + }) + } + + async BlockOne(e) { + if (!common.checkPermission(e, "master")) return + let type = "" + let name = "拉" + if (/^#拉白(群聊?)?/.test(this.e.msg)) { + type += "white" + name += "白" + } else { + type += "black" + name += "黑" + } + if (/^#拉[黑白](群聊?)/.test(this.e.msg)) { + type += "Group" + name += "群" + } else { + type += Version.name == "TRSS-Yunzai" ? "User" : "QQ" + } + const configPath = "config/config/other.yaml" + /** 判断at */ + if (this.e.at) { + this.blackResult = this.e.at + } else { + if (Version.name == "TRSS-Yunzai") { + /** TRSS-Yunzai匹配所有字符 */ + const blackId = this.e.msg.replace(/^#拉[黑白](群聊?)?/, "").trim() + this.blackResult = Number(blackId) || String(blackId) + } else { + const match = this.e.msg.match(/\d+/) + if (match?.[0]) { this.blackResult = Number(match[0]) || String(match[0]) } + } + } + if (!this.blackResult || common.getPermission(new Proxy({ + get isMaster() { return Config.masterQQ.includes(this.user_id) || Config.masterQQ.includes(String(this.user_id)) }, + user_id: this.blackResult + }, { + get: (target, prop, receiver) => target[prop] ?? e[prop] + }), "master") === true) { return this.e.reply(`❎ ${name}失败,没有键入用户或群号`) } + try { + const yamlContentBuffer = await fs.promises.readFile(configPath) + const yamlContent = yamlContentBuffer.toString("utf-8") + const data = yaml.parse(yamlContent) + if (!Array.isArray(data[type])) { data[type] = [] } + if (!data[type].includes(this.blackResult)) { + data[type].push(this.blackResult) + const updatedYaml = yaml.stringify(data, { quote: false }) + const resultYaml = updatedYaml.replace(/"/g, "") + await fs.promises.writeFile(configPath, resultYaml, "utf-8") + await this.e.reply(`✅ 已把这个坏淫${name}掉惹!!!`) + } else { + await this.e.reply(`❎ 已把这个坏淫${name}过辣`) + } + } catch (error) { + await this.e.reply(`❎ 额...${name}失败哩,可能这个淫比较腻害>_<`) + logger.error(error) + } + } + + async CancelBlockOne(e) { + if (!common.checkPermission(e, "master")) return + let type = "" + let name = "取消拉" + if (/^#(取消|删除|移除)(群聊?)?拉白(群聊?)?/.test(this.e.msg)) { + type += "white" + name += "白" + } else { + type += "black" + name += "黑" + } + if (/^#(取消|删除|移除)拉[黑白](群聊?)/.test(this.e.msg)) { + type += "Group" + name += "群" + } else { + type += Version.name == "TRSS-Yunzai" ? "User" : "QQ" + } + const configPath = "config/config/other.yaml" + if (this.e.at) { + this.blackResult = this.e.at + } else { + if (Version.name == "TRSS-Yunzai") { + const blackId = this.e.msg.replace(/^#(取消|(删|移)除)拉[黑白](群聊?)?/, "").trim() + this.blackResult = Number(blackId) || String(blackId) + } else { + const match = this.e.msg.match(/\d+/) + if (match?.[0]) { this.blackResult = Number(match[0]) || String(match[0]) } + } + } + if (!this.blackResult) { return this.e.reply(`❎ ${name}失败,没有键入用户或群号`) } + try { + const yamlContentBuffer = await fs.promises.readFile(configPath) + const yamlContent = yamlContentBuffer.toString("utf-8") + const data = yaml.parse(yamlContent) + if (Array.isArray(data[type]) && data[type].includes(this.blackResult)) { + const itemToRemove = this.blackResult.toString() + data[type] = data[type].filter(item => item.toString() !== itemToRemove) + const updatedYaml = yaml.stringify(data) + await fs.promises.writeFile(configPath, updatedYaml, "utf-8") + await this.e.reply(`✅ 已把这个坏淫${name}掉惹!!!`) + } else { + await this.e.reply(`❎ ${name}失败,找不到辣>_<`) + } + } catch (error) { + await this.e.reply(`❎ 额...${name}失败哩,可能这个淫比较腻害>_<`) + logger.error(error) + } + } +} diff --git a/apps/assistant/Qzone.js b/apps/assistant/Qzone.js new file mode 100644 index 0000000..aeb72fd --- /dev/null +++ b/apps/assistant/Qzone.js @@ -0,0 +1,148 @@ +import _ from "lodash" +import moment from "moment" +import { common, QQApi } from "../../model/index.js" +import { API_ERROR } from "../../constants/errorMsg.js" + +export class Qzone extends plugin { + constructor() { + super({ + name: "椰奶助手-空间", + event: "message.group", + priority: 500, + rule: [ + { + reg: "^#获?取说说列表(\\d+)?$", + fnc: "Qzonelist" + }, + { + reg: "^#删说说(\\d+)$", + fnc: "Qzonedel" + }, + { + reg: "^#发说说", + fnc: "Qzonesay" + }, + { + reg: "^#(清空说说|清空留言)$", + fnc: "QzonedelAll" + } + ] + }) + } + + /** + * QQ空间 说说列表 + * @param e + */ + async Qzonelist(e) { + if (!common.checkPermission(e, "master")) return + let page = e.msg.replace(/#|获?取说说列表/g, "").trim() + if (!page) { + page = 0 + } else { + page = page - 1 + } + + // 获取说说列表 + let list = await new QQApi(e).getQzone(5, page * 5) + + if (!list) return e.reply(API_ERROR) + if (list.total == 0) return e.reply("✅ 说说列表为空") + + let msg = [ + "✅ 获取成功,说说列表如下:\n", + ...list.msglist.map((item, index) => + `${page * 5 + index + 1}.${_.truncate(item.content, { length: 15 })}\n- [${item.secret ? "私密" : "公开"}] | ${moment(item.created_time * 1000).format("MM/DD HH:mm")} | ${item.commentlist?.length || 0}条评论\n` + ), + `页数:[${page + 1}/${Math.ceil(list.total / 5)}]` + ] + e.reply(msg) + } + + /** + * 删除说说 + * @param e + */ + async Qzonedel(e) { + if (!common.checkPermission(e, "master")) return + let pos = e.msg.match(/\d+/) + // 获取说说列表 + let list = await new QQApi(e).getQzone(1, pos - 1) + + if (!list) return e.reply(API_ERROR) + if (!list.msglist) return e.reply("❎ 未获取到该说说") + + // 要删除的说说 + let domain = list.msglist[0] + // 请求接口 + let result = await new QQApi(e).delQzone(domain.tid, domain.t1_source) + if (!result) return e.reply(API_ERROR) + // debug + logger.debug(e.logFnc, result) + + if (result.subcode != 0) e.reply("❎ 未知错误" + JSON.parse(result)) + // 发送结果 + e.reply(`✅ 删除说说成功:\n ${pos}.${_.truncate(domain.content, { length: 15 })} \n - [${domain.secret ? "私密" : "公开"}] | ${moment(domain.created_time * 1000).format("MM/DD HH:mm")} | ${domain.commentlist?.length || 0} 条评论`) + } + + /** + * 发说说 + * @param e + */ + async Qzonesay(e) { + if (!common.checkPermission(e, "master")) return + let con = e.msg.replace(/#|发说说/g, "").trim() + let result = await new QQApi(e).setQzone(con, e.img) + if (!result) return e.reply(API_ERROR) + + if (result.code != 0) return e.reply(`❎ 说说发表失败\n${JSON.stringify(result)}`) + + let msg = [ "✅ 说说发表成功,内容:\n", _.truncate(result.content, { length: 15 }) ] + if (result.pic) { + msg.push(segment.image(result.pic[0].url1)) + } + msg.push(`\n- [${result.secret ? "私密" : "公开"}] | ${moment(result.t1_ntime * 1000).format("MM/DD HH:mm")}`) + e.reply(msg) + } + + /** + * 清空说说和留言 + * @param e + */ + async QzonedelAll(e) { + if (!common.checkPermission(e, "master")) return + if (/清空说说/.test(e.msg)) { + this.setContext("_QzonedelAllContext") + e.reply("✳️ 即将删除全部说说请发送:\n" + "------确认清空或取消------") + this.e.Qzonedetermine = true + } else if (/清空留言/.test(e.msg)) { + this.setContext("_QzonedelAllContext") + e.reply("✳️ 即将删除全部留言请发送:\n" + "------确认清空或取消------") + this.e.Qzonedetermine = false + } + } + + async _QzonedelAllContext() { + let msg = this.e.msg + if (/#?确认清空/.test(msg)) { + this.finish("_QzonedelAllContext") + let result + if (this.e.Qzonedetermine) { + result = await new QQApi(this.e).delQzoneAll() + } else { + result = await new QQApi(this.e).delQzoneMsgbAll() + } + + this.e.reply(result) + return true + } else if (/#?取消/.test(msg)) { + this.finish("_QzonedelAllContext") + this.e.reply("✅ 已取消") + return false + } else { + this.setContext("_QzonedelAllContext") + this.e.reply("❎ 请输入:确认清空或取消") + return false + } + } +} diff --git a/apps/assistant/sendMsg.js b/apps/assistant/sendMsg.js new file mode 100644 index 0000000..c0cd493 --- /dev/null +++ b/apps/assistant/sendMsg.js @@ -0,0 +1,128 @@ +import { common } from "../../model/index.js" +import { sleep } from "../../tools/index.js" + +let FriendsReg = /^#发好友\s?(\d+)\s?([^]*)$/ +let GroupMsgReg = /^#发群聊\s?(\d+)\s?([^]*)$/ +let GroupListMsgReg = /^#发群列表\s?(\d+(,\d+){0,})\s?([^]*)$/ + +export class sendMsg extends plugin { + constructor() { + super({ + name: "椰奶助手-发消息", + event: "message.group", + priority: 500, + rule: [ + { + reg: FriendsReg, // 发好友 + fnc: "SendFriendMsg" + }, + { + reg: GroupMsgReg, // 发群聊 + fnc: "SendGroupMsg" + }, + { + reg: GroupListMsgReg, // 发群列表 + fnc: "SendGroupListMsg" + } + ] + }) + } + + /** + * 发好友 + * @param e + */ + async SendFriendMsg(e) { + if (!common.checkPermission(e, "master")) return + let regRet = FriendsReg.exec(e.msg) + let qq = regRet[1] + e.message[0].text = regRet[2] + if (!/^\d+$/.test(qq)) return e.reply("❎ QQ号不正确,人家做不到的啦>_<~") + + if (!this.Bot.fl.get(Number(qq))) return e.reply("❎ 好友列表查无此人") + + if (!e.message[0].text) e.message.shift() + + if (e.message.length === 0) return e.reply("❎ 消息不能为空") + + await this.Bot.pickFriend(qq).sendMsg(e.message) + .then(() => e.reply("✅ 私聊消息已送达")) + .catch(err => common.handleException(e, err, { MsgTemplate: "❎ 发送失败\n错误信息为:{error}" })) + } + + /** + * 发群聊 + * @param e + */ + async SendGroupMsg(e) { + if (!common.checkPermission(e, "master")) return + let regRet = GroupMsgReg.exec(e.msg) + + let gpid = regRet[1] + + e.message[0].text = regRet[2] + + if (!e.message[0].text) e.message.shift() + + if (e.message.length === 0) return e.reply("❎ 消息不能为空") + + if (!/^\d+$/.test(gpid)) return e.reply("❎ 您输入的群号不合法") + + if (!this.Bot.gl.get(Number(gpid))) return e.reply("❎ 群聊列表查无此群") + + await this.Bot.pickGroup(gpid).sendMsg(e.message) + .then(() => e.reply("✅ 群聊消息已送达")) + .catch((err) => common.handleException(e, err, { MsgTemplate: "❎ 发送失败\n错误信息为:{error}" })) + } + + // 发送群列表 + async SendGroupListMsg(e) { + if (!common.checkPermission(e, "master")) return + // 获取参数 + let regRet = GroupListMsgReg.exec(e.msg) + let gpid = regRet[1] + e.message[0].text = regRet[3] + + if (!e.message[0].text) e.message.shift() + + if (e.message.length === 0) return e.reply("❎ 消息不能为空") + + let groupidList = [] + let sendList = [] + + // 获取群列表 + let listMap = Array.from(this.Bot.gl.values()) + + listMap.forEach((item) => { + groupidList.push(item.group_id) + }) + + let groupids = gpid.split(",") + + if (!groupids.every(item => item <= groupidList.length)) return e.reply("❎ 序号超过合法值!!!") + + groupids.forEach((item) => { + sendList.push(groupidList[Number(item) - 1]) + }) + + if (sendList.length > 3) return e.reply("❎ 不能同时发太多群聊,号寄概率增加!!!") + + if (sendList.length === 1) { + await this.Bot.pickGroup(sendList[0]).sendMsg(e.message) + .then(() => e.reply("✅ " + sendList[0] + " 群聊消息已送达")) + .catch((err) => + common.handleException(e, err, { MsgTemplate: `❎ ${sendList[0]} 发送失败\n错误信息为:{error}` }) + ) + } else { + e.reply("发送多个群聊,将每5秒发送一条消息!") + for (let i of sendList) { + await this.Bot.pickGroup(i).sendMsg(e.message) + .then(() => e.reply("✅ " + i + " 群聊消息已送达")) + .catch((err) => + common.handleException(e, err, { MsgTemplate: `❎ ${i} 发送失败\n错误信息为:{error}` })) + await sleep(5000) + } + } + return false + } +} diff --git a/apps/fun.js b/apps/fun.js index d053449..8d5c7ce 100644 --- a/apps/fun.js +++ b/apps/fun.js @@ -1,21 +1,9 @@ -import _ from "lodash" -import { Config } from "../components/index.js" import { pandadiuType, xiurenTypeId } from "../constants/fun.js" import { common, funApi, uploadRecord } from "../model/index.js" /** 开始执行文案 */ const START_EXECUTION = "椰奶产出中......" -const picApis = Config.getConfig("picApi") -/** 解析匹配模式 */ -const picApiKeys = [] - -_.forIn(picApis, (values, key) => { - let mode = values.mode !== undefined ? values.mode : picApis.mode - key = key.split("|").map(item => mode ? "^" + item + "$" : item).join("|") - picApiKeys.push(key) -}) - export class Fun extends plugin { constructor(e) { super({ @@ -50,10 +38,6 @@ export class Fun extends plugin { { reg: `^#来点(${Object.keys(xiurenTypeId).join("|")})$`, fnc: "xiuren" - }, - { - reg: "^#?(查?看|取)头像", - fnc: "LookAvatar" } ] }) @@ -162,20 +146,4 @@ export class Fun extends plugin { .then(res => common.recallSendForwardMsg(e, res)) .catch(err => common.handleException(e, err)) } - - // 查看头像 - async LookAvatar() { - const id = this.e.msg.replace(/^#?((查?看头像)|取头像)/, "").trim() || this.e.at || - this.e.message.find(item => item.type == "at")?.qq || this.e.user_id - try { - let 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)) - } catch (error) { - logger.error("获取头像错误", error) - } - await this.reply("❎ 获取头像错误", true) - return false - } } diff --git a/apps/groupAdmin/groupAdminOther.js b/apps/groupAdmin/groupAdminOther.js index e816b64..b8cacfc 100644 --- a/apps/groupAdmin/groupAdminOther.js +++ b/apps/groupAdmin/groupAdminOther.js @@ -1,8 +1,8 @@ import moment from "moment" import _ from "lodash" import { QQApi, common, puppeteer } from "../../model/index.js" -// API请求错误文案 -const API_ERROR = "❎ 出错辣,请稍后重试" +import { API_ERROR } from "../../constants/errorMsg.js" + export class GroupAdminOther extends plugin { constructor() { super({ diff --git a/apps/groupAdmin/groupAnnounce.js b/apps/groupAdmin/groupAnnounce.js index 98fc6d7..548c269 100644 --- a/apps/groupAdmin/groupAnnounce.js +++ b/apps/groupAdmin/groupAnnounce.js @@ -1,6 +1,6 @@ import { QQApi, common } from "../../model/index.js" -// API请求错误文案 -const API_ERROR = "❎ 出错辣,请稍后重试" +import { API_ERROR } from "../../constants/errorMsg.js" + export class GroupAnnounce extends plugin { constructor() { super({ diff --git a/apps/groupAdmin/groupLuckyword.js b/apps/groupAdmin/groupLuckyword.js index fbf245c..f435bb4 100644 --- a/apps/groupAdmin/groupLuckyword.js +++ b/apps/groupAdmin/groupLuckyword.js @@ -1,6 +1,6 @@ import { QQApi, common } from "../../model/index.js" -// API请求错误文案 -const API_ERROR = "❎ 出错辣,请稍后重试" +import { API_ERROR } from "../../constants/errorMsg.js" + export class GroupLuckyword extends plugin { constructor() { super({ diff --git a/constants/errorMsg.js b/constants/errorMsg.js new file mode 100644 index 0000000..44d0973 --- /dev/null +++ b/constants/errorMsg.js @@ -0,0 +1,2 @@ +/** API请求错误message */ +export const API_ERROR = "❎ 出错辣,请稍后重试"