增加bika次数限制配置

This commit is contained in:
yeyang
2023-02-08 18:25:53 +08:00
parent b59229e3b6
commit 0bc2b50a56
4 changed files with 25 additions and 9 deletions

View File

@@ -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
}
}

View File

@@ -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
}

View File

@@ -1,3 +1,7 @@
#是否允许私聊使用
allowPM: true
#每名用户每日使用次数限制 0则无限制
limit: 30
#哔咔图片直连,直接使用哔咔原图发送不使用图片反代,国内则需使用代理
bikaDirectConnection: false
#哔咔图片反代

View File

@@ -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