From 0bc2b50a56d1acf35251abf2a3275d31c0ef5cc2 Mon Sep 17 00:00:00 2001 From: yeyang <746659424@qq.com> Date: Wed, 8 Feb 2023 18:25:53 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=A2=9E=E5=8A=A0bika=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=E9=99=90=E5=88=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/bika.js | 27 +++++++++++++++++++-------- apps/picSearch.js | 2 +- config/default_config/bika.yaml | 4 ++++ lib/common/common.js | 1 + 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/apps/bika.js b/apps/bika.js index b789b0b..d33818b 100644 --- a/apps/bika.js +++ b/apps/bika.js @@ -48,7 +48,7 @@ export class NewBika extends plugin { /** 搜索 */ async search (e) { - if (!this.handlePermission()) return e.reply(SWITCH_ERROR) + if (!await this.Authentication(e)) return e.reply(Pixiv.startMsg) let regRet = e.msg.match(searchReg) let page = common.translateChinaNum(regRet[5]) @@ -59,7 +59,7 @@ export class NewBika extends plugin { /** 漫画页面 */ async comicPage (e) { - if (!this.handlePermission()) return e.reply(SWITCH_ERROR) + if (!await this.Authentication(e)) return e.reply(Pixiv.startMsg) let regRet = e.msg.match(comicPageReg) let page = common.translateChinaNum(regRet[4]) @@ -71,7 +71,7 @@ export class NewBika extends plugin { /** 类别列表 */ async categories (e) { - if (!this.handlePermission()) return e.reply(SWITCH_ERROR) + if (!await this.Authentication(e)) return e.reply(Pixiv.startMsg) let msg = await Bika.categories().catch(err => { e.reply(err.message) }) if (!msg) return @@ -80,7 +80,7 @@ export class NewBika extends plugin { /** 漫画细节 */ async comicDetail (e) { - if (!this.handlePermission()) return e.reply(SWITCH_ERROR) + if (!await this.Authentication(e)) return e.reply(Pixiv.startMsg) let id = e.msg.match(new RegExp(`#?${Prefix}(详情|细节)(.*)`))[3] let msg = await Bika.comicDetail(id).catch(err => { e.reply(err.message) }) @@ -110,9 +110,20 @@ export class NewBika extends plugin { e.reply(`✅ 已${/开启/.test(e.msg) ? '开启' : '关闭'}哔咔直连`) } - /** 权限判定 */ - handlePermission () { - let { sesepro } = Config.getGroup(this.e.group_id) - return sesepro || this.e.isMaster + async Authentication (e) { + if (e.isMaster) return true + if (!Config.getGroup(e.group_id).sesepro) { + e.reply(SWITCH_ERROR) + return false + } + if (!Config.bika.allowPM && !e.isGroup) { + e.reply('主人已禁用私聊该功能') + return false + } + if (!await common.limit(e.user_id, 'bika', Config.bika.limit)) { + e.reply('[bika]您已达今日次数上限', true, { at: true }) + return false + } + return true } } diff --git a/apps/picSearch.js b/apps/picSearch.js index 404dbc8..34bc2c5 100644 --- a/apps/picSearch.js +++ b/apps/picSearch.js @@ -90,7 +90,7 @@ export class NewPicSearch extends plugin { e.reply('主人已禁用私聊该功能') return false } - if (!await common.limit(e.user_id, 'PicSearch', Config.picSearch.limit)) { + if (!await common.limit(e.user_id, 'picSearch', Config.picSearch.limit)) { e.reply('[PicSearch]您已达今日次数上限', true, { at: true }) return false } diff --git a/config/default_config/bika.yaml b/config/default_config/bika.yaml index a49c969..8e5da9e 100644 --- a/config/default_config/bika.yaml +++ b/config/default_config/bika.yaml @@ -1,3 +1,7 @@ +#是否允许私聊使用 +allowPM: true +#每名用户每日使用次数限制 0则无限制 +limit: 30 #哔咔图片直连,直接使用哔咔原图发送不使用图片反代,国内则需使用代理 bikaDirectConnection: false #哔咔图片反代 diff --git a/lib/common/common.js b/lib/common/common.js index 5a58303..fa23c58 100644 --- a/lib/common/common.js +++ b/lib/common/common.js @@ -157,6 +157,7 @@ export default new class newCommon { * @return {Boolean} */ async limit (userId, key, maxlimit) { + if (maxlimit <= 0) return true let redisKey = `yenai:${key}:limit:${userId}` let nowNum = await redis.get(redisKey) if (nowNum > maxlimit) return false