From 512a2c49a072dcdffa8f37f7f2174a39a23af5ce Mon Sep 17 00:00:00 2001 From: yeyang <746659424@qq.com> Date: Sun, 2 Jun 2024 20:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E4=BC=98=E5=8C=96=E5=8F=91?= =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E7=BE=A4=E8=81=8A=E6=B6=88=E6=81=AF=EF=BC=8C?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=B8=BA=E7=A9=BA=E5=90=8E=E5=8F=AF=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E5=8F=91=E9=80=81=EF=BC=8C=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A=E6=B6=88=E6=81=AF=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assistant/sendMsg.js | 62 +++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/apps/assistant/sendMsg.js b/apps/assistant/sendMsg.js index 89e9557..b88078e 100644 --- a/apps/assistant/sendMsg.js +++ b/apps/assistant/sendMsg.js @@ -14,15 +14,15 @@ export class SendMsg extends plugin { rule: [ { reg: FriendsReg, // 发好友 - fnc: "SendFriendMsg" + fnc: "sendFriendMsg" }, { reg: GroupMsgReg, // 发群聊 - fnc: "SendGroupMsg" + fnc: "sendGroupMsg" }, { reg: GroupListMsgReg, // 发群列表 - fnc: "SendGroupListMsg" + fnc: "sendGroupListMsg" } ] }) @@ -36,7 +36,7 @@ export class SendMsg extends plugin { * 发好友 * @param e */ - async SendFriendMsg(e) { + async sendFriendMsg(e) { if (!common.checkPermission(e, "master")) return let regRet = FriendsReg.exec(e.msg) @@ -57,20 +57,38 @@ export class SendMsg extends plugin { if (!e.message[0].text) e.message.shift() - if (e.message.length === 0) return e.reply("❎ 消息不能为空") - if (!bot.fl.get(Number(qq))) return e.reply("❎ 好友列表查无此人") + if (e.message.length === 0) { + e._qq = qq + e._bot = bot + this.setContext("_sendFriendMsgContext") + e.reply("⚠ 请发送需要发送的消息\n可发送‘#取消’进行取消") + return + } + await bot.pickFriend(qq).sendMsg(e.message) - .then(() => e.reply("✅ 私聊消息已送达")) + .then(() => e.reply(`✅ ${qq} 私聊消息已送达`)) .catch(err => common.handleException(e, err, { MsgTemplate: "❎ 发送失败\n错误信息为:{error}" })) } + async _sendFriendMsgContext(e) { + if (this.e.msg === "#取消") { + this.finish("_sendFriendMsgContext") + return this.e.reply("✅ 已取消") + } + const { _bot, _qq } = e + _bot.pickFriend(_qq).sendMsg(this.e.message) + .then(() => this.e.reply(`✅ ${_qq} 私聊消息已送达`)) + .catch(err => common.handleException(this.e, err, { MsgTemplate: "❎ 发送失败\n错误信息为:{error}" })) + this.finish("_sendFriendMsgContext") + } + /** * 发群聊 * @param e */ - async SendGroupMsg(e) { + async sendGroupMsg(e) { if (!common.checkPermission(e, "master")) return let regRet = GroupMsgReg.exec(e.msg) @@ -85,26 +103,44 @@ export class SendMsg extends plugin { bot = Bot[botId] } else { bot = this.Bot - } + }; if (!/^\d+$/.test(gpid)) return e.reply("❎ 群号不合法") if (!e.message[0].text) e.message.shift() - if (e.message.length === 0) return e.reply("❎ 消息不能为空") - if (!bot.gl.get(Number(gpid))) return e.reply("❎ 群聊列表查无此群") + if (e.message.length === 0) { + e._gpid = gpid + e._bot = bot + this.setContext("_sendGroupMsgContext") + e.reply("⚠ 请发送需要发送的消息\n可发送‘#取消’进行取消") + return + } + await bot.pickGroup(gpid).sendMsg(e.message) - .then(() => e.reply("✅ 群聊消息已送达")) + .then(() => e.reply(`✅ ${gpid} 群聊消息已送达`)) .catch((err) => common.handleException(e, err, { MsgTemplate: "❎ 发送失败\n错误信息为:{error}" })) } + async _sendGroupMsgContext(e) { + if (this.e.msg === "#取消") { + this.finish("_sendGroupMsgContext") + return this.e.reply("✅ 已取消") + } + const { _bot, _gpid } = e + await _bot.pickGroup(_gpid).sendMsg(this.e.message) + .then(() => this.e.reply(`✅ ${_gpid} 群聊消息已送达`)) + .catch((err) => common.handleException(this.e, err, { MsgTemplate: "❎ 发送失败\n错误信息为:{error}" })) + this.finish("_sendGroupMsgContext") + } + /** * 发群列表 * @param e */ - async SendGroupListMsg(e) { + async sendGroupListMsg(e) { if (!common.checkPermission(e, "master")) return let regRet = GroupListMsgReg.exec(e.msg)