diff --git a/apps/bika.js b/apps/bika.js index d3e0feb..073e7fc 100644 --- a/apps/bika.js +++ b/apps/bika.js @@ -1,8 +1,6 @@ import { Bika, common, Pixiv } from '../model/index.js' import { Config } from '../components/index.js' import { Admin } from './admin.js' -// 文案 -const SWITCH_ERROR = '主人没有开放这个功能哦(*/ω\*)' // 汉字数字匹配正则 const numReg = '[零一壹二两三四五六七八九十百千万亿\\d]+' @@ -153,10 +151,7 @@ export class NewBika extends plugin { async _Authentication (e) { if (e.isMaster) return true - if (!Config.getGroup(e.group_id).sesepro) { - e.reply(SWITCH_ERROR) - return false - } + if (!common.checkSeSePermission(e, 'sesepro')) return false if (!Config.bika.allowPM && !e.isGroup) { e.reply('主人已禁用私聊该功能') return false diff --git a/apps/fun.js b/apps/fun.js index afd784c..a3accb0 100644 --- a/apps/fun.js +++ b/apps/fun.js @@ -1,22 +1,22 @@ -import plugin from '../../../lib/plugins/plugin.js' -import fetch from 'node-fetch' import _ from 'lodash' +import fetch from 'node-fetch' +import plugin from '../../../lib/plugins/plugin.js' import { Config } from '../components/index.js' -import { common, uploadRecord, QQApi, funApi, memes } from '../model/index.js' -import { successImgs, faildsImgs, heisiType, pandadiuType } from '../constants/fun.js' +import { faildsImgs, heisiType, pandadiuType, successImgs } from '../constants/fun.js' +import { QQApi, common, funApi, memes, uploadRecord } from '../model/index.js' /** API请求错误文案 */ const API_ERROR = '❎ 出错辣,请稍后重试' -/** 未启用文案 */ -const SWITCH_ERROR = '主人没有开放这个功能哦(*/ω\*)' + /** 开始执行文案 */ const START_EXECUTION = '椰奶产出中......' -const picapis = Config.getConfig('picApi') +const picApis = Config.getConfig('picApi') /** 解析匹配模式 */ -let picApiKeys = [] -_.forIn(picapis, (values, key) => { - let mode = values.mode !== undefined ? values.mode : picapis.mode +const picApiKeys = [] + +_.forIn(picApis, (values, key) => { + let mode = values.mode !== undefined ? values.mode : picApis.mode key = key.split('|').map(item => mode ? '^' + item + '$' : item).join('|') picApiKeys.push(key) }) @@ -197,10 +197,7 @@ export class Fun extends plugin { // coser async coser (e) { - const { sese, sesepro } = Config.getGroup(e.group_id) - if (!sese && !sesepro && !e.isMaster) { - return e.reply(SWITCH_ERROR) - } + if (!common.checkSeSePermission(e)) return false e.reply(START_EXECUTION) await funApi.coser() @@ -210,10 +207,10 @@ export class Fun extends plugin { // cos/acg搜索 async acg (e) { - let { sese, sesepro } = Config.getGroup(e.group_id) - if (!sese && !sesepro && !e.isMaster) return e.reply(SWITCH_ERROR) + if (!common.checkSeSePermission(e)) return false e.reply(START_EXECUTION) - let type = e.msg.match(new RegExp(`^#(${Object.keys(pandadiuType).join('|')})?acg(.*)$`)) + const reg = new RegExp(`^#(${Object.keys(pandadiuType).join('|')})?acg(.*)$`) + const type = e.msg.match(reg) await funApi.pandadiu(type[1], type[2]) .then(res => common.recallSendForwardMsg(e, res)) .catch(err => e.reply(err.message)) @@ -221,7 +218,7 @@ export class Fun extends plugin { // 黑丝 async heisiwu (e) { - if (!Config.getGroup(e.group_id).sesepro && !e.isMaster) return e.reply(SWITCH_ERROR) + if (!common.checkSeSePermission(e, 'sesepro')) return false e.reply(START_EXECUTION) // 获取类型 @@ -233,7 +230,7 @@ export class Fun extends plugin { // 萌堆 async mengdui (e) { - if (!Config.getGroup(e.group_id).sesepro && !e.isMaster) return e.reply(SWITCH_ERROR) + if (!common.checkSeSePermission(e, 'sesepro')) return false // 开始执行 e.reply(START_EXECUTION) let regRet = e.msg.match(/#?来点神秘图(s)?(.*)/) @@ -243,7 +240,7 @@ export class Fun extends plugin { } async xiuren (e) { - if (!Config.getGroup(e.group_id).sesepro && !e.isMaster) return e.reply(SWITCH_ERROR) + if (!common.checkSeSePermission(e, 'pro')) return false // 开始执行 e.reply(START_EXECUTION) await funApi.xiuren(e.msg.replace(/#?来点/, '')) @@ -292,9 +289,9 @@ export class Fun extends plugin { if (/jktj|接口统计/.test(e.msg)) { let msg = ['现接口数量如下'] - for (let i in picapis) { + for (let i in picApis) { if (i == 'mode') continue - let urls = picapis[i].url || picapis[i] + let urls = picApis[i].url || picApis[i] msg.push(`\n♡ ${i} => ${Array.isArray(urls) ? urls.length : 1}`) } return e.reply(msg) @@ -302,7 +299,7 @@ export class Fun extends plugin { // 解析消息中的类型 let regRet = apiReg.exec(e.msg) if (regRet[1] == 'mode') return false - let picObj = picapis[_.sample(Object.keys(picapis).filter(item => new RegExp(item).test(regRet[1])))] + let picObj = picApis[_.sample(Object.keys(picApis).filter(item => new RegExp(item).test(regRet[1])))] if (Array.isArray(picObj)) picObj = _.sample(picObj) let urlReg = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9_-](\?)?)*)*$/i if (!picObj.url && !urlReg.test(encodeURI(picObj)) && !Array.isArray(picObj)) { diff --git a/apps/pixiv.js b/apps/pixiv.js index 8d8a146..d328854 100644 --- a/apps/pixiv.js +++ b/apps/pixiv.js @@ -242,17 +242,13 @@ export class NewPixiv extends plugin { .catch(err => e.reply(err.message)) } - async _Authentication (e, type, limit = true) { + async _Authentication (e, type = 'sese', limit = true) { if (e.isMaster) return true if (!Config.pixiv.allowPM && !e.isGroup) { e.reply('主人已禁用私聊该功能') return false } - const { sese, sesepro } = Config.getGroup(e.group_id) - if ((type == 'sese' && !sese && !sesepro) || (type == 'sesepro' && !sesepro)) { - e.reply(SWITCH_ERROR) - return false - } + if (!common.checkSeSePermission(e, type)) return false if (limit && !await common.limit(e.user_id, 'pixiv', Config.pixiv.limit)) { e.reply('您已达今日「Pixiv」次数上限', true, { at: true }) return false diff --git a/apps/setu.js b/apps/setu.js index 3af001a..262b72d 100644 --- a/apps/setu.js +++ b/apps/setu.js @@ -3,9 +3,8 @@ import { Config } from '../components/index.js' import { setu, common } from '../model/index.js' import { Admin } from './admin.js' -const SWITCH_ERROR = '主人没有开放这个功能哦(*/ω\*)' - const NumReg = '[零一壹二两三四五六七八九十百千万亿\\d]+' + export class SeSe extends plugin { constructor () { super({ @@ -99,15 +98,13 @@ export class SeSe extends plugin { async _Authentication (e) { if (e.isMaster) return true - if (!Config.setu.allowPM && !e.isGroup) { + const { allowPM, limit } = Config.setu + if (!allowPM && !e.isGroup) { e.reply('主人已禁用私聊该功能') return false } - if (!Config.getGroup(e.group_id).sesepro) { - e.reply(SWITCH_ERROR) - return false - } - if (!await common.limit(e.user_id, 'setu', Config.setu.limit)) { + if (!common.checkSeSePermission(e, 'sesepro')) return false + if (!await common.limit(e.user_id, 'setu', limit)) { e.reply('您已达今日「setu」次数上限', true, { at: true }) return false } diff --git a/lib/common/common.js b/lib/common/common.js index f7405e0..fd2b5a7 100644 --- a/lib/common/common.js +++ b/lib/common/common.js @@ -4,7 +4,11 @@ import Config from '../../components/Config.js' import setu from '../../model/setu.js' import moment from 'moment' import _ from 'lodash' -export default new class newCommon { + +// 涩涩未开启文案 +const SWITCH_ERROR = '主人没有开放这个功能哦(*/ω\*)' + +export default new class { /** * @description: 延时函数 * @param {*} ms 时间(毫秒) @@ -43,6 +47,26 @@ export default new class newCommon { return true } + /** + * @description: 判断涩涩权限 + * @param {object} e oicq事件对象 + * @param {'sesse'|'sesepro'} type 权限类型 + * @return {boolean} + */ + checkSeSePermission (e, type = 'sese') { + if (e.isMaster) return true + const { sese, sesepro } = Config.getGroup(e.group_id) + if (type == 'sese' && !sese && !sesepro) { + e.reply(SWITCH_ERROR) + return false + } + if (type == 'sesepro' && !sesepro) { + e.reply(SWITCH_ERROR) + return false + } + return true + } + /** 给主人发消息 */ async sendMasterMsg (msg) { if (Config.whole.notificationsAll) { diff --git a/tools/sagiri.js b/tools/sagiri.js index ade0db5..22607cb 100644 --- a/tools/sagiri.js +++ b/tools/sagiri.js @@ -334,10 +334,11 @@ const sites = { 44: Skeb } const resolveResult = item => { - let _a const { data, header } = item const id = header.index_id - if (!sites[id]) { throw new Error(`Cannot resolve data for unknown index ${id}`) } + if (!sites[id]) { + throw new Error(`Cannot resolve data for unknown index ${id}`) + } const { name, urlMatcher, backupUrl, authorData } = sites[id] let url if (data.ext_urls && data.ext_urls.length > 1) { @@ -346,11 +347,13 @@ const resolveResult = item => { url = data.ext_urls } if (!url) url = backupUrl(item) - return Object.assign({ - id, - url, - name - }, ((_a = authorData === null || authorData === void 0 ? void 0 : authorData(item.data)) !== null && _a !== void 0 ? _a : { authorName: null, authorUrl: null })) + const author = authorData?.(item.data) ?? { authorName: null, authorUrl: null } + return { id, url, name, ...author } + // return Object.assign({ + // id, + // url, + // name + // }, ((_a = authorData === null || authorData === void 0 ? void 0 : authorData(item.data)) !== null && _a !== void 0 ? _a : { authorName: null, authorUrl: null })) } const sagiri = (response) => {