From e81834a9304e681aaf91895b2d20bae7fc0380e5 Mon Sep 17 00:00:00 2001 From: ikuaki1009 <109460768+ikuaki1009@users.noreply.github.com> Date: Fri, 21 Apr 2023 13:51:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E4=B8=AD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20e.bot=20=E8=80=8C=E4=B8=8D=E6=98=AF=E5=85=A8=E5=B1=80=20Bot?= =?UTF-8?q?=20(#71)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/common.js | 6 ++-- lib/plugins/loader.js | 8 ++--- plugins/example/进群退群通知.js | 4 +-- plugins/genshin/apps/abbrSet.js | 12 +++---- plugins/genshin/apps/gcLog.js | 2 +- plugins/genshin/model/mysNews.js | 4 +-- plugins/other/sendLog.js | 6 ++-- plugins/other/update.js | 6 ++-- plugins/system/add.js | 54 ++++++++++++++++---------------- plugins/system/invite.js | 4 +-- plugins/system/quit.js | 2 +- plugins/system/status.js | 2 +- 12 files changed, 55 insertions(+), 55 deletions(-) diff --git a/lib/common/common.js b/lib/common/common.js index 2ea6084..671a505 100644 --- a/lib/common/common.js +++ b/lib/common/common.js @@ -69,15 +69,15 @@ async function makeForwardMsg (e, msg = [], dec = '') { // 是频道直接返回 join if (e.isGuild) return msg.join("\n") - let nickname = Bot.nickname + let nickname = e.bot.nickname if (e.isGroup) { - let info = await Bot.getGroupMemberInfo(e.group_id, Bot.uin) + let info = await e.bot.getGroupMemberInfo(e.group_id, e.bot.uin) nickname = info.card || info.nickname } let userInfo = { - user_id: Bot.uin, + user_id: e.bot.uin, nickname } diff --git a/lib/plugins/loader.js b/lib/plugins/loader.js index 30feade..e345b6c 100644 --- a/lib/plugins/loader.js +++ b/lib/plugins/loader.js @@ -367,9 +367,9 @@ class PluginsLoader { e.img.push(val.url) break case 'at': - if (val.qq == Bot.uin) { + if (val.qq == e.bot.uin) { e.atBot = true - } else if (val.id == Bot.tiny_id) { + } else if (val.id == e.bot.tiny_id) { e.atBot = true /** 多个at 以最后的为准 */ } else if (val.id) { @@ -526,9 +526,9 @@ class PluginsLoader { logger.warn(err) }) } else { - let friend = Bot.fl.get(e.user_id) + let friend = e.bot.fl.get(e.user_id) if (!friend) return - return await Bot.pickUser(e.user_id).sendMsg(msg).catch((err) => { + return await e.bot.pickUser(e.user_id).sendMsg(msg).catch((err) => { logger.warn(err) }) } diff --git a/plugins/example/进群退群通知.js b/plugins/example/进群退群通知.js index 8607824..6bef8f8 100644 --- a/plugins/example/进群退群通知.js +++ b/plugins/example/进群退群通知.js @@ -17,7 +17,7 @@ export class newcomer extends plugin { /** 冷却cd 30s */ let cd = 30 - if (this.e.user_id == Bot.uin) return + if (this.e.user_id == this.e.bot.uin) return /** cd */ let key = `Yz:newcomers:${this.e.group_id}` @@ -46,7 +46,7 @@ export class outNotice extends plugin { } async accept () { - if (this.e.user_id == Bot.uin) return + if (this.e.user_id == this.e.bot.uin) return let name, msg if (this.e.member) { diff --git a/plugins/genshin/apps/abbrSet.js b/plugins/genshin/apps/abbrSet.js index 7c4639f..3063eb2 100644 --- a/plugins/genshin/apps/abbrSet.js +++ b/plugins/genshin/apps/abbrSet.js @@ -61,10 +61,10 @@ export class abbrSet extends plugin { if (this.e.isMaster) return true /** 管理员 */ if (abbrSetAuth == 1) { - if (!Bot.gml.has(this.e.group_id)) { + if (!this.e.bot.gml.has(this.e.group_id)) { return false } - if (!Bot.gml.get(this.e.group_id).get(this.e.user_id)) { + if (!this.e.bot.gml.get(this.e.group_id).get(this.e.user_id)) { return false } if (!this.e.member.is_admin) { @@ -163,19 +163,19 @@ export class abbrSet extends plugin { let title = `${role.name}别名,${list.length}个` - msg = await this.makeForwardMsg(Bot.uin, title, msg) + msg = await this.makeForwardMsg(this.e.bot.uin, title, msg) await this.e.reply(msg) } async makeForwardMsg (qq, title, msg) { - let nickname = Bot.nickname + let nickname = this.e.bot.nickname if (this.e.isGroup) { - let info = await Bot.getGroupMemberInfo(this.e.group_id, qq) + let info = await this.e.bot.getGroupMemberInfo(this.e.group_id, qq) nickname = info.card ?? info.nickname } let userInfo = { - user_id: Bot.uin, + user_id: this.e.bot.uin, nickname } diff --git a/plugins/genshin/apps/gcLog.js b/plugins/genshin/apps/gcLog.js index 1f769f8..27650ea 100644 --- a/plugins/genshin/apps/gcLog.js +++ b/plugins/genshin/apps/gcLog.js @@ -139,7 +139,7 @@ export class gcLog extends plugin { return } - let friend = Bot.fl.get(Number(this.e.user_id)) + let friend = this.e.bot.fl.get(Number(this.e.user_id)) if (!friend) { await this.reply('无法发送文件,请先添加好友') return diff --git a/plugins/genshin/model/mysNews.js b/plugins/genshin/model/mysNews.js index 913f2cf..96888eb 100644 --- a/plugins/genshin/model/mysNews.js +++ b/plugins/genshin/model/mysNews.js @@ -323,7 +323,7 @@ export default class MysNews extends base { if (sended) return // 判断是否存在群关系 - if (!Bot.gl.get(Number(groupId))) { + if (!this.e.bot.gl.get(Number(groupId))) { logger.error(`[米游社${typeName}推送] 群${groupId}未关联`) return } @@ -340,7 +340,7 @@ export default class MysNews extends base { } this.pushGroup[groupId]++ - this.e.group = Bot.pickGroup(Number(groupId)) + this.e.group = this.e.bot.pickGroup(Number(groupId)) this.e.group_id = Number(groupId) let tmp = await this.replyMsg(this[postId].img, `原神${typeName}推送:${this[postId].title}`) diff --git a/plugins/other/sendLog.js b/plugins/other/sendLog.js index 3f74424..03ea644 100644 --- a/plugins/other/sendLog.js +++ b/plugins/other/sendLog.js @@ -80,13 +80,13 @@ export class sendLog extends plugin { } async makeForwardMsg (title, msg) { - let nickname = Bot.nickname + let nickname = this.e.bot.nickname if (this.e.isGroup) { - let info = await Bot.getGroupMemberInfo(this.e.group_id, Bot.uin) + let info = await this.e.bot.getGroupMemberInfo(this.e.group_id, this.e.bot.uin) nickname = info.card ?? info.nickname } let userInfo = { - user_id: Bot.uin, + user_id: this.e.bot.uin, nickname } diff --git a/plugins/other/update.js b/plugins/other/update.js index 79959f0..36b4f55 100644 --- a/plugins/other/update.js +++ b/plugins/other/update.js @@ -262,13 +262,13 @@ export class update extends plugin { } async makeForwardMsg (title, msg, end) { - let nickname = Bot.nickname + let nickname = this.e.bot.nickname if (this.e.isGroup) { - let info = await Bot.getGroupMemberInfo(this.e.group_id, Bot.uin) + let info = await this.e.bot.getGroupMemberInfo(this.e.group_id, this.e.bot.uin) nickname = info.card ?? info.nickname } let userInfo = { - user_id: Bot.uin, + user_id: this.e.bot.uin, nickname } diff --git a/plugins/system/add.js b/plugins/system/add.js index c556392..6bb0ce6 100644 --- a/plugins/system/add.js +++ b/plugins/system/add.js @@ -99,8 +99,8 @@ export class add extends plugin { /** 添加全局表情,存入到机器人qq文件中 */ if (this.isGlobal) { - this.group_id = Bot.uin; - return Bot.uin; + this.group_id = this.e.bot.uin; + return this.e.bot.uin; } if (this.e.isGroup) { @@ -128,10 +128,10 @@ export class add extends plugin { return false } if (groupCfg.imgAddLimit == 1) { - if (!Bot.gml.has(this.group_id)) { + if (!this.e.bot.gml.has(this.group_id)) { return false } - if (!Bot.gml.get(this.group_id).get(this.e.user_id)) { + if (!this.e.bot.gml.get(this.group_id).get(this.e.user_id)) { return false } if (!this.e.member.is_admin) { @@ -155,7 +155,7 @@ export class add extends plugin { } if (this.e.at) { - let at = lodash.filter(this.e.message, (o) => { return o.type == 'at' && o.qq != Bot.uin }) + let at = lodash.filter(this.e.message, (o) => { return o.type == 'at' && o.qq != this.e.bot.uin }) if (at.length > 1) { this.e.reply('添加错误:只能@一个人当关键词') return false @@ -202,7 +202,7 @@ export class add extends plugin { /** 过滤#添加 */ .replace(/#|#|图片|表情|添加|删除|全局/g, '') /** 过滤@ */ - .replace(new RegExp('{at:' + Bot.uin + '}', 'g'), '') + .replace(new RegExp('{at:' + this.e.bot.uin + '}', 'g'), '') .trim() this.keyWord = this.trimAlias(this.keyWord) @@ -245,7 +245,7 @@ export class add extends plugin { for (let i in message) { if (message[i].type == 'at') { - if (message[i].qq == Bot.uin) { + if (message[i].qq == this.e.bot.uin) { this.e.reply('添加内容不能@机器人!') return } @@ -301,7 +301,7 @@ export class add extends plugin { continue } if (msg[i].type == 'at') { - if (msg[i].qq == Bot.uin) { + if (msg[i].qq == this.e.bot.uin) { delete msg[i] continue } else { @@ -327,12 +327,12 @@ export class add extends plugin { saveGlobalJson() { let obj = {}; - for (let [k, v] of textArr[Bot.uin]) { + for (let [k, v] of textArr[this.e.bot.uin]) { obj[k] = v; } fs.writeFileSync( - `${this.path}${Bot.uin}.json`, + `${this.path}${this.e.bot.uin}.json`, JSON.stringify(obj, "", "\t") ); } @@ -390,7 +390,7 @@ export class add extends plugin { let keyWord = this.e.toString() .replace(/#|#/g, '') - .replace(`{at:${Bot.uin}}`, '') + .replace(`{at:${this.e.bot.uin}}`, '') .trim() keyWord = this.trimAlias(keyWord) @@ -399,14 +399,14 @@ export class add extends plugin { if (isNaN(keyWord)) { num = keyWord.charAt(keyWord.length - 1) - if (!isNaN(num) && !textArr[this.group_id].has(keyWord) && !textArr[Bot.uin].has(keyWord)) { + if (!isNaN(num) && !textArr[this.group_id].has(keyWord) && !textArr[this.e.bot.uin].has(keyWord)) { keyWord = lodash.trimEnd(keyWord, num).trim() num-- } } let msg = textArr[this.group_id].get(keyWord) || [] - let globalMsg = textArr[Bot.uin].get(keyWord) || [] + let globalMsg = textArr[this.e.bot.uin].get(keyWord) || [] if (lodash.isEmpty(msg) && lodash.isEmpty(globalMsg)) return false msg = [...msg, ...globalMsg] @@ -513,11 +513,11 @@ export class add extends plugin { /** 初始化全局已添加内容 */ initGlobalTextArr() { - if (textArr[Bot.uin]) return; + if (textArr[this.e.bot.uin]) return; - textArr[Bot.uin] = new Map(); + textArr[this.e.bot.uin] = new Map(); - let globalPath = `${this.path}${Bot.uin}.json`; + let globalPath = `${this.path}${this.e.bot.uin}.json`; if (!fs.existsSync(globalPath)) { return; } @@ -529,20 +529,20 @@ export class add extends plugin { if (text[i][0] && !Array.isArray(text[i][0])) { text[i] = [text[i]]; } - textArr[Bot.uin].set(String(i), text[i]); + textArr[this.e.bot.uin].set(String(i), text[i]); } } catch (error) { logger.error(`json格式错误:${globalPath}`); - delete textArr[Bot.uin]; + delete textArr[this.e.bot.uin]; return false; } /** 加载表情 */ - let globalFacePath = `${this.facePath}${Bot.uin}`; + let globalFacePath = `${this.facePath}${this.e.bot.uin}`; if (fs.existsSync(globalFacePath)) { const files = fs - .readdirSync(`${this.facePath}${Bot.uin}`) + .readdirSync(`${this.facePath}${this.e.bot.uin}`) .filter((file) => /\.(jpeg|jpg|png|gif)$/g.test(file)); for (let val of files) { @@ -550,9 +550,9 @@ export class add extends plugin { tmp[0] = tmp[0].replace(/_[0-9]{10}$/, ""); if (/at|image/g.test(val)) continue; - if (textArr[Bot.uin].has(tmp[0])) continue; + if (textArr[this.e.bot.uin].has(tmp[0])) continue; - textArr[Bot.uin].set(tmp[0], [ + textArr[this.e.bot.uin].set(tmp[0], [ [ { local: `${globalFacePath}/${val}`, @@ -737,19 +737,19 @@ export class add extends plugin { title = `表情${search},${count}条` } - let forwardMsg = await this.makeForwardMsg(Bot.uin, title, msg, end) + let forwardMsg = await this.makeForwardMsg(this.e.bot.uin, title, msg, end) this.e.reply(forwardMsg) } async makeForwardMsg (qq, title, msg, end = '') { - let nickname = Bot.nickname + let nickname = this.e.bot.nickname if (this.e.isGroup) { - let info = await Bot.getGroupMemberInfo(this.e.group_id, qq) + let info = await this.e.bot.getGroupMemberInfo(this.e.group_id, qq) nickname = info.card ?? info.nickname } let userInfo = { - user_id: Bot.uin, + user_id: this.e.bot.uin, nickname } @@ -808,7 +808,7 @@ export class add extends plugin { for (let qq of tmp) { qq = qq.match(/[1-9][0-9]{4,14}/g)[0] - let member = await await Bot.getGroupMemberInfo(this.group_id, Number(qq)).catch(() => { }) + let member = await await this.e.bot.getGroupMemberInfo(this.group_id, Number(qq)).catch(() => { }) let name = member?.card ?? member?.nickname if (!name) continue msg = msg.replace(`{at:${qq}}`, `@${name}`) diff --git a/plugins/system/invite.js b/plugins/system/invite.js index 1f7afef..78041ce 100644 --- a/plugins/system/invite.js +++ b/plugins/system/invite.js @@ -14,9 +14,9 @@ export class invite extends plugin { logger.mark(`[邀请加群]:${this.e.group_name}:${this.e.group_id}`) return } - Bot.logger.mark(`[主人邀请加群]:${this.e.group_name}:${this.e.group_id}`) + logger.mark(`[主人邀请加群]:${this.e.group_name}:${this.e.group_id}`) this.e.approve(true) - Bot.sendPrivateMsg(this.e.user_id, `已同意加群:${this.e.group_name}`).catch((err) => { + this.e.bot.sendPrivateMsg(this.e.user_id, `已同意加群:${this.e.group_name}`).catch((err) => { logger.error(err) }) } diff --git a/plugins/system/quit.js b/plugins/system/quit.js index 87a7e3f..7b667b2 100644 --- a/plugins/system/quit.js +++ b/plugins/system/quit.js @@ -10,7 +10,7 @@ export class quit extends plugin { } async accept () { - if (this.e.user_id != Bot.uin) return + if (this.e.user_id != this.e.bot.uin) return let other = cfg.other if (other.autoQuit <= 0) return diff --git a/plugins/system/status.js b/plugins/system/status.js index 8672fd9..1ae96c4 100644 --- a/plugins/system/status.js +++ b/plugins/system/status.js @@ -28,7 +28,7 @@ export class status extends plugin { } async statusMaster () { - let runTime = moment().diff(moment.unix(Bot.stat.start_time), 'seconds') + let runTime = moment().diff(moment.unix(this.e.bot.stat.start_time), 'seconds') let Day = Math.floor(runTime / 3600 / 24) let Hour = Math.floor((runTime / 3600) % 24) let Min = Math.floor((runTime / 60) % 60)