diff --git a/apps/pixiv.js b/apps/pixiv.js index 8e607fc..130a3ff 100644 --- a/apps/pixiv.js +++ b/apps/pixiv.js @@ -80,7 +80,7 @@ export class example extends plugin { img.push(segment.image(i)) } - Cfg.getCDsendMsg(e, img, false) + Cfg.recallsendMsg(e, img) return true; } diff --git a/apps/setu.js b/apps/setu.js index bdfa95f..6f136ad 100644 --- a/apps/setu.js +++ b/apps/setu.js @@ -205,7 +205,7 @@ export class sese extends plugin { let res = {}; - if (!fs.existsSync(this.path)) { + if (fs.existsSync(this.path)) { res = await Cfg.getread(this.path) } diff --git a/model/Config.js b/model/Config.js index 0a83bab..7b063a4 100644 --- a/model/Config.js +++ b/model/Config.js @@ -20,7 +20,7 @@ class Config { }) } - /** 写入文件 */ + /** 写入json文件 */ async getwrite(path, cot = {}) { return await fs.promises .writeFile(path, JSON.stringify(cot, '', '\t')) @@ -112,23 +112,39 @@ class Config { } //发送消息 - let res = await e.reply(forwardMsg) + let res = await e.reply(forwardMsg, false, { recallMsg: time }) if (!res) { if (isfk) { await e.reply("消息发送失败,可能被风控") } return false } - if (time > 0 && res && res.message_id && e.isGroup) { - setTimeout(() => { - e.group.recallMsg(res.message_id); - logger.mark("[椰奶]执行撤回") - }, time * 1000); - } return true; } + /** + * @description: 发送消息并根据指定时间撤回群消息 + * @param {*} e oicq + * @param {*} msg 消息 + * @param {Number} time 撤回时间 + * @param {Boolean} isfk 是否发送默认风控消息 + * @return {*} + */ + async recallsendMsg(e, msg, time = 0, isfk = true) { + time = time || await this.recalltime(e) + + //发送消息 + let res = await e.reply(msg, false, { recallMsg: time }) + if (!res) { + if (isfk) { + await e.reply("消息发送失败,可能被风控") + } + return false + } + return true; + } + /** * @description: 获取配置的cd发送消息 * @param {*} e oicq @@ -138,10 +154,26 @@ class Config { * @return {Boolean} */ async getCDsendMsg(e, msg, isBot = true, isfk = true) { + let time = await this.recalltime(e) + + let res = await this.getforwardMsg(e, msg, time, isBot, isfk) + + if (!res) return false; + + return true; + } + + /** + * @description: 获取群的撤回时间 + * @param {*} e oicq + * @return {Number} + */ + async recalltime(e) { + if (!e.isGroup) return 0; let path = "./plugins/yenai-plugin/config/setu/setu.json" - //获取CD - let cfgs = {} - let time = 120 + //获取撤回时间 + let cfgs = {}; + let time = 120; if (fs.existsSync(path)) { cfgs = await this.getread(path) } @@ -149,16 +181,14 @@ class Config { if (cfgs[e.group_id]) { time = cfgs[e.group_id].recall } - let res = await this.getforwardMsg(e, msg, time, isBot, isfk) - if (!res) return false; - - return true; + return time } + /** * @description: 取cookie * @param {String} data 如:qun.qq.com * @return {Object} - */ + */ getck(data) { let cookie = Bot.cookies[data] let ck = cookie.replace(/=/g, `":"`).replace(/;/g, `","`).replace(/ /g, "").trim()