💩 优化代码,优化注释
This commit is contained in:
323
apps/admin.js
323
apps/admin.js
@@ -1,52 +1,313 @@
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { update } from '../../other/update.js'
|
||||
import { Version, Plugin_Name } from '../components/index.js'
|
||||
import { puppeteer } from '../model/index.js'
|
||||
import fs from 'fs'
|
||||
import _ from 'lodash'
|
||||
import { Config } from '../components/index.js'
|
||||
import { setu, puppeteer } from '../model/index.js'
|
||||
const OtherCfgType = {
|
||||
全部通知: 'notificationsAll',
|
||||
状态: 'state',
|
||||
陌生人点赞: 'Strangers_love',
|
||||
// 给有问题的用户关闭定时器
|
||||
状态任务: 'statusTask'
|
||||
}
|
||||
const SeSeCfgType = {
|
||||
涩涩: 'sese',
|
||||
涩涩pro: 'sesepro',
|
||||
匿名: 'anonymous',
|
||||
代理: 'switchProxy'
|
||||
}
|
||||
const NoticeCfgType = {
|
||||
好友消息: 'privateMessage',
|
||||
群消息: 'groupMessage',
|
||||
群临时消息: 'grouptemporaryMessage',
|
||||
群撤回: 'groupRecall',
|
||||
好友撤回: 'PrivateRecall',
|
||||
// 申请通知
|
||||
好友申请: 'friendRequest',
|
||||
群邀请: 'groupInviteRequest',
|
||||
加群申请: 'addGroupApplication',
|
||||
// 信息变动
|
||||
群管理变动: 'groupAdminChange',
|
||||
// 列表变动
|
||||
好友列表变动: 'friendNumberChange',
|
||||
群聊列表变动: 'groupNumberChange',
|
||||
群成员变动: 'groupMemberNumberChange',
|
||||
// 其他通知
|
||||
闪照: 'flashPhoto',
|
||||
禁言: 'botBeenBanned',
|
||||
输入: 'input'
|
||||
}
|
||||
const SwitchCfgType = { ...NoticeCfgType, ...OtherCfgType, ...SeSeCfgType }
|
||||
const NumberCfgType = {
|
||||
渲染精度: {
|
||||
key: 'renderScale',
|
||||
limit: '50-200'
|
||||
},
|
||||
删除缓存时间: {
|
||||
key: 'deltime',
|
||||
limit: '>120'
|
||||
}
|
||||
}
|
||||
|
||||
const SwitchCfgReg = new RegExp(`^#椰奶设置(${Object.keys(SwitchCfgType).join('|')})(开启|关闭)$`)
|
||||
|
||||
const NumberCfgReg = new RegExp(`^#椰奶设置(${Object.keys(NumberCfgType).join('|')})(\\d+)秒?$`)
|
||||
export class Admin extends plugin {
|
||||
constructor () {
|
||||
super({
|
||||
name: '椰奶版本信息',
|
||||
name: '椰奶配置',
|
||||
event: 'message',
|
||||
priority: 400,
|
||||
priority: 100,
|
||||
rule: [
|
||||
{
|
||||
reg: '^#?椰奶(插件)?版本$',
|
||||
fnc: 'plugin_version'
|
||||
reg: SwitchCfgReg,
|
||||
fnc: 'ConfigSwitch',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#?椰奶(插件)?更新日志$',
|
||||
fnc: 'update_log'
|
||||
reg: NumberCfgReg,
|
||||
fnc: 'ConfigNumber',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#椰奶(sese|涩涩)?设置$',
|
||||
fnc: 'Settings',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#椰奶(启用|禁用)全部通知$',
|
||||
fnc: 'SetAllNotice',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#(增加|减少|查看)头衔屏蔽词.*$',
|
||||
fnc: 'ProhibitedTitle',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#切换头衔屏蔽词匹配(模式)?$',
|
||||
fnc: 'ProhibitedTitlePattern',
|
||||
permission: 'master'
|
||||
}
|
||||
]
|
||||
})
|
||||
this.key = 'yenai:restart'
|
||||
}
|
||||
|
||||
async plugin_version () {
|
||||
return versionInfo(this.e)
|
||||
}
|
||||
// 更改配置
|
||||
async ConfigSwitch (e) {
|
||||
// 解析消息
|
||||
let regRet = SwitchCfgReg.exec(e.msg)
|
||||
let index = regRet[1]
|
||||
let yes = regRet[2] == '开启'
|
||||
|
||||
async update_log () {
|
||||
// eslint-disable-next-line new-cap
|
||||
let Update_Plugin = new update()
|
||||
Update_Plugin.e = this.e
|
||||
Update_Plugin.reply = this.reply
|
||||
// 单独处理
|
||||
if (index == '涩涩pro' && yes) Config.modify('whole', 'sese', yes)
|
||||
|
||||
if (Update_Plugin.getPlugin(Plugin_Name)) {
|
||||
this.e.reply(await Update_Plugin.getLog(Plugin_Name))
|
||||
if (index == '涩涩' && !yes) Config.modify('whole', 'sesepro', yes)
|
||||
// 特殊处理
|
||||
if (index == '代理') {
|
||||
Config.modify('proxy', 'switchProxy', yes)
|
||||
} else {
|
||||
Config.modify('whole', SwitchCfgType[index], yes)
|
||||
}
|
||||
return true
|
||||
if (Object.keys(SeSeCfgType).includes(index)) {
|
||||
return this.SeSe_Settings(e)
|
||||
}
|
||||
// 渲染图片
|
||||
this.index_Settings(e)
|
||||
}
|
||||
|
||||
// 修改数字设置
|
||||
async ConfigNumber (e) {
|
||||
let regRet = e.msg.match(NumberCfgReg)
|
||||
let type = NumberCfgType[regRet[1]]
|
||||
let number = checkNumberValue(regRet[2], type.limit)
|
||||
Config.modify(type.name ?? 'whole', type.key, number)
|
||||
this.index_Settings(e)
|
||||
}
|
||||
|
||||
// 修改全部通知设置
|
||||
async SetAllNotice (e) {
|
||||
let yes = /启用/.test(e.msg)
|
||||
for (let i in NoticeCfgType) {
|
||||
Config.modify('whole', NoticeCfgType[i], yes)
|
||||
}
|
||||
this.index_Settings(e)
|
||||
}
|
||||
|
||||
async Settings (e) {
|
||||
if (/sese|涩涩/.test(e.msg)) {
|
||||
this.SeSe_Settings(e)
|
||||
} else {
|
||||
this.index_Settings(e)
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染发送图片
|
||||
async index_Settings (e) {
|
||||
let data = {}
|
||||
const special = ['deltime', 'renderScale']
|
||||
for (let key in Config.Notice) {
|
||||
if (special.includes(key)) {
|
||||
data[key] = Number(Config.Notice[key])
|
||||
} else {
|
||||
data[key] = getStatus(Config.Notice[key])
|
||||
}
|
||||
}
|
||||
// 渲染图像
|
||||
return await puppeteer.render('admin/index', {
|
||||
...data,
|
||||
bg: await rodom()
|
||||
}, {
|
||||
e,
|
||||
scale: 1.4
|
||||
})
|
||||
}
|
||||
|
||||
// 查看涩涩设置
|
||||
async SeSe_Settings (e) {
|
||||
let set = setu.getSeSeConfig(e)
|
||||
let { proxy, pixiv, bika, Notice: { sese, sesepro, anonymous } } = Config
|
||||
let data = {
|
||||
sese: getStatus(sese),
|
||||
sesepro: getStatus(sesepro),
|
||||
anonymous: getStatus(anonymous),
|
||||
r18: getStatus(set.r18),
|
||||
cd: Number(set.cd),
|
||||
recall: set.recall ? set.recall : '无',
|
||||
switchProxy: getStatus(proxy.switchProxy),
|
||||
pixivDirectConnection: getStatus(pixiv.pixivDirectConnection),
|
||||
bikaDirectConnection: getStatus(bika.bikaDirectConnection),
|
||||
pixivImageProxy: pixiv.pixivImageProxy,
|
||||
bikaImageProxy: bika.bikaImageProxy,
|
||||
imageQuality: bika.imageQuality
|
||||
}
|
||||
// 渲染图像
|
||||
return await puppeteer.render('admin/sese', {
|
||||
...data,
|
||||
bg: await rodom()
|
||||
}, {
|
||||
e,
|
||||
scale: 1.4
|
||||
})
|
||||
}
|
||||
|
||||
// 增删查头衔屏蔽词
|
||||
async ProhibitedTitle (e) {
|
||||
// 获取现有的头衔屏蔽词
|
||||
let shieldingWords = Config.groupTitle.Shielding_words
|
||||
// 判断是否需要查看头衔屏蔽词
|
||||
if (/查看/.test(e.msg)) {
|
||||
// 返回已有的头衔屏蔽词列表
|
||||
return e.reply(`现有的头衔屏蔽词如下:${shieldingWords.join('\n')}`)
|
||||
}
|
||||
|
||||
// 获取用户输入的要增加或删除的屏蔽词
|
||||
let message = e.msg.replace(/#|(增加|减少)头衔屏蔽词/g, '').trim().split(',')
|
||||
// 判断用户是要增加还是删除屏蔽词
|
||||
let isAddition = /增加/.test(e.msg)
|
||||
let existingWords = []
|
||||
let newWords = []
|
||||
|
||||
// 遍历用户输入的屏蔽词,区分已有和新的屏蔽词
|
||||
for (let word of message) {
|
||||
if (shieldingWords.includes(word)) {
|
||||
existingWords.push(word)
|
||||
} else {
|
||||
newWords.push(word)
|
||||
}
|
||||
}
|
||||
|
||||
// 去重
|
||||
existingWords = _.compact(_.uniq(existingWords))
|
||||
newWords = _.compact(_.uniq(newWords))
|
||||
|
||||
// 判断是要增加还是删除屏蔽词
|
||||
if (isAddition) {
|
||||
// 添加新的屏蔽词
|
||||
if (!_.isEmpty(newWords)) {
|
||||
for (let word of newWords) {
|
||||
Config.modifyarr('groupTitle', 'Shielding_words', word, 'add')
|
||||
}
|
||||
e.reply(`✅ 成功添加:${newWords.join(',')}`)
|
||||
}
|
||||
// 提示已有的屏蔽词
|
||||
if (!_.isEmpty(existingWords)) {
|
||||
e.reply(`❎ 以下词已存在:${existingWords.join(',')}`)
|
||||
}
|
||||
} else {
|
||||
// 删除已有的屏蔽词
|
||||
if (!_.isEmpty(existingWords)) {
|
||||
for (let word of existingWords) {
|
||||
Config.modifyarr('groupTitle', 'Shielding_words', word, 'del')
|
||||
}
|
||||
e.reply(`✅ 成功删除:${existingWords.join(',')}`)
|
||||
}
|
||||
// 提示不在屏蔽词中的词
|
||||
if (!_.isEmpty(newWords)) {
|
||||
e.reply(`❎ 以下词未在屏蔽词中:${newWords.join(',')}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改头衔匹配模式
|
||||
async ProhibitedTitlePattern (e) {
|
||||
let data = Config.groupTitle.Match_pattern ? 0 : 1
|
||||
Config.modify('groupTitle', 'Match_pattern', data)
|
||||
e.reply(`✅ 已修改匹配模式为${data ? '精确' : '模糊'}匹配`)
|
||||
}
|
||||
}
|
||||
|
||||
async function versionInfo (e) {
|
||||
return await puppeteer.render(
|
||||
'help/version-info',
|
||||
{
|
||||
currentVersion: Version.ver,
|
||||
changelogs: Version.logs,
|
||||
elem: 'cryo'
|
||||
},
|
||||
{ e, scale: 2 }
|
||||
)
|
||||
// 随机底图
|
||||
const rodom = async function () {
|
||||
let image = fs.readdirSync('./plugins/yenai-plugin/resources/admin/imgs/bg')
|
||||
let listImg = []
|
||||
for (let val of image) {
|
||||
listImg.push(val)
|
||||
}
|
||||
let imgs = listImg.length == 1 ? listImg[0] : listImg[_.random(0, listImg.length - 1)]
|
||||
return imgs
|
||||
}
|
||||
|
||||
const getStatus = function (rote) {
|
||||
if (rote) {
|
||||
return '<div class="cfg-status" >已开启</div>'
|
||||
} else {
|
||||
return '<div class="cfg-status status-off">已关闭</div>'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查一个数值是否满足给定的限制条件,并返回经过验证的数值。
|
||||
*
|
||||
* @param {number} value - 要检查的数值。
|
||||
* @param {string} limit - 要检查的限制条件。
|
||||
* 限制条件可以是以下格式之一:
|
||||
* - "X-Y" 形式的范围限制条件,其中 X 和 Y 是表示下限和上限的数字。
|
||||
* - "<X" 或 ">X" 形式的比较限制条件,其中 X 是表示限制值的数字。
|
||||
* @returns {number} 经过验证的数值。如果给定的值超出了限制条件,则返回限制条件对应的最大值或最小值,否则返回原值。
|
||||
*/
|
||||
function checkNumberValue (value, limit) {
|
||||
// 检查是否存在限制条件
|
||||
if (!limit) {
|
||||
return value
|
||||
}
|
||||
// 解析限制条件
|
||||
const [symbol, limitValue] = limit.match(/^([<>])?(.+)$/).slice(1)
|
||||
const parsedLimitValue = parseFloat(limitValue)
|
||||
|
||||
// 检查比较限制条件
|
||||
if ((symbol === '<' && value > parsedLimitValue) || (symbol === '>' && value < parsedLimitValue)) {
|
||||
return parsedLimitValue
|
||||
}
|
||||
|
||||
// 检查范围限制条件
|
||||
if (!isNaN(value)) {
|
||||
const [lowerLimit, upperLimit] = limit.split('-').map(parseFloat)
|
||||
const clampedValue = Math.min(Math.max(value, lowerLimit || -Infinity), upperLimit || Infinity)
|
||||
return clampedValue
|
||||
}
|
||||
|
||||
// 如果不符合以上任何条件,则返回原值
|
||||
return parseFloat(value)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Bika, common, Pixiv } from '../model/index.js'
|
||||
import { Config } from '../components/index.js'
|
||||
import { Setting } from './setting.js'
|
||||
import { Admin } from './admin.js'
|
||||
// 文案
|
||||
const SWITCH_ERROR = '主人没有开放这个功能哦(*/ω\*)'
|
||||
|
||||
@@ -137,7 +137,7 @@ export class NewBika extends plugin {
|
||||
if (!imageQualityType[quality] && !Object.values(imageQualityType).includes(quality)) return e.reply(`错误参数,支持的参数为${Object.keys(imageQualityType).join(',')}`)
|
||||
let type = imageQualityType[quality] ?? quality
|
||||
Config.modify('bika', 'imageQuality', type)
|
||||
new Setting().SeSe_Settings(e)
|
||||
new Admin().SeSe_Settings(e)
|
||||
}
|
||||
|
||||
/** 图片直连 */
|
||||
@@ -148,7 +148,7 @@ export class NewBika extends plugin {
|
||||
if (now && isSwitch) return e.reply('❎ bika图片直连已处于开启状态')
|
||||
if (!now && !isSwitch) return e.reply('❎ bika图片直连已处于关闭状态')
|
||||
Config.modify('bika', 'bikaDirectConnection', isSwitch)
|
||||
new Setting().SeSe_Settings(e)
|
||||
new Admin().SeSe_Settings(e)
|
||||
}
|
||||
|
||||
async _Authentication (e) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { Config } from '../components/index.js'
|
||||
import { Pixiv, common, setu } from '../model/index.js'
|
||||
import { Setting } from './setting.js'
|
||||
import { Admin } from './admin.js'
|
||||
import { ImageRPSS } from '../tools/pixiv.js'
|
||||
// 文案
|
||||
const SWITCH_ERROR = '主人没有开放这个功能哦(*/ω\*)'
|
||||
@@ -226,14 +226,14 @@ export class NewPixiv extends plugin {
|
||||
}
|
||||
logger.mark(`${e.logFnc}切换为${proxy}`)
|
||||
Config.modify('pixiv', 'pixivImageProxy', proxy)
|
||||
new Setting().SeSe_Settings(e)
|
||||
new Admin().SeSe_Settings(e)
|
||||
}
|
||||
|
||||
/** 图片直连 */
|
||||
async directConnection (e) {
|
||||
let isSwitch = /开启/.test(e.msg)
|
||||
Config.modify('pixiv', 'pixivDirectConnection', isSwitch)
|
||||
new Setting().SeSe_Settings(e)
|
||||
new Admin().SeSe_Settings(e)
|
||||
}
|
||||
|
||||
/** 登录信息 */
|
||||
|
||||
278
apps/setting.js
278
apps/setting.js
@@ -1,278 +0,0 @@
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import fs from 'fs'
|
||||
import _ from 'lodash'
|
||||
import { Config } from '../components/index.js'
|
||||
import { setu, puppeteer } from '../model/index.js'
|
||||
const cfgType = {
|
||||
好友消息: 'privateMessage',
|
||||
群消息: 'groupMessage',
|
||||
群临时消息: 'grouptemporaryMessage',
|
||||
群撤回: 'groupRecall',
|
||||
好友撤回: 'PrivateRecall',
|
||||
// 申请通知
|
||||
好友申请: 'friendRequest',
|
||||
群邀请: 'groupInviteRequest',
|
||||
加群申请: 'addGroupApplication',
|
||||
// 信息变动
|
||||
群管理变动: 'groupAdminChange',
|
||||
// 列表变动
|
||||
好友列表变动: 'friendNumberChange',
|
||||
群聊列表变动: 'groupNumberChange',
|
||||
群成员变动: 'groupMemberNumberChange',
|
||||
// 其他通知
|
||||
闪照: 'flashPhoto',
|
||||
禁言: 'botBeenBanned',
|
||||
输入: 'input',
|
||||
|
||||
全部通知: 'notificationsAll',
|
||||
删除缓存: 'deltime',
|
||||
涩涩: 'sese',
|
||||
状态: 'state',
|
||||
涩涩pro: 'sesepro',
|
||||
匿名: 'anonymous',
|
||||
陌生人点赞: 'Strangers_love',
|
||||
// 给有问题的用户关闭定时器
|
||||
状态任务: 'statusTask',
|
||||
|
||||
代理: 'switchProxy'
|
||||
}
|
||||
|
||||
let managereg = new RegExp(`^#椰奶设置(${Object.keys(cfgType).join('|')})(开启|关闭)$`)
|
||||
export class Setting extends plugin {
|
||||
constructor () {
|
||||
super({
|
||||
name: '椰奶配置',
|
||||
event: 'message',
|
||||
priority: 100,
|
||||
rule: [
|
||||
{
|
||||
reg: managereg,
|
||||
fnc: 'ConfigManage',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#椰奶设置(删除缓存时间|渲染精度)(\\d+)秒?$',
|
||||
fnc: 'ConfigNumber',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#椰奶设置$',
|
||||
fnc: 'index_Settings',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#椰奶(sese|涩涩)设置$',
|
||||
fnc: 'SeSe_Settings',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#椰奶(启用|禁用)全部通知$',
|
||||
fnc: 'SetAll',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#(增加|减少|查看)头衔屏蔽词.*$',
|
||||
fnc: 'NoTitle',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#切换头衔屏蔽词匹配(模式)?$',
|
||||
fnc: 'NoTitlepattern',
|
||||
permission: 'master'
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
// 更改配置
|
||||
async ConfigManage (e) {
|
||||
// 解析消息
|
||||
let regRet = managereg.exec(e.msg)
|
||||
let index = regRet[1]
|
||||
let yes = regRet[2] == '开启'
|
||||
|
||||
// 单独处理
|
||||
if (index == '涩涩pro' && yes) Config.modify('whole', 'sese', yes)
|
||||
|
||||
if (index == '涩涩' && !yes) Config.modify('whole', 'sesepro', yes)
|
||||
// 特殊处理
|
||||
if (index == '代理') {
|
||||
Config.modify('proxy', 'switchProxy', yes)
|
||||
} else {
|
||||
Config.modify('whole', cfgType[index], yes)
|
||||
}
|
||||
let specialSese = ['涩涩', '涩涩pro', '代理', '匿名']
|
||||
if (specialSese.includes(index)) {
|
||||
return this.SeSe_Settings(e)
|
||||
}
|
||||
// 处理
|
||||
|
||||
this.index_Settings(e)
|
||||
return true
|
||||
}
|
||||
|
||||
// 设置删除缓存时间
|
||||
async ConfigNumber (e) {
|
||||
let number = e.msg.match(/\d+/)
|
||||
number = Number(number[0])
|
||||
let type = ''
|
||||
if (/渲染精度/.test(e.msg)) {
|
||||
if (number < 50) number = 50
|
||||
if (number > 200) number = 200
|
||||
type = 'renderScale'
|
||||
} else {
|
||||
if (number < 120) number = 120
|
||||
type = 'deltime'
|
||||
}
|
||||
Config.modify('whole', type, number)
|
||||
|
||||
this.index_Settings(e)
|
||||
}
|
||||
|
||||
// 修改全部设置
|
||||
async SetAll (e) {
|
||||
let yes = /启用/.test(e.msg)
|
||||
// 设置的任务
|
||||
let type = [
|
||||
'privateMessage',
|
||||
'groupMessage',
|
||||
'grouptemporaryMessage',
|
||||
'groupRecall',
|
||||
'PrivateRecall',
|
||||
'friendRequest',
|
||||
'groupInviteRequest',
|
||||
'addGroupApplication',
|
||||
'groupAdminChange',
|
||||
'friendNumberChange',
|
||||
'groupNumberChange',
|
||||
'groupMemberNumberChange',
|
||||
'flashPhoto',
|
||||
'botBeenBanned',
|
||||
'input'
|
||||
]
|
||||
|
||||
for (let i in cfgType) {
|
||||
if (!type.includes(cfgType[i])) continue
|
||||
Config.modify('whole', cfgType[i], yes)
|
||||
}
|
||||
|
||||
this.index_Settings(e)
|
||||
return true
|
||||
}
|
||||
|
||||
// 渲染发送图片
|
||||
async index_Settings (e) {
|
||||
let data = {}
|
||||
const special = ['deltime', 'renderScale']
|
||||
for (let key in Config.Notice) {
|
||||
if (special.includes(key)) {
|
||||
data[key] = Number(Config.Notice[key])
|
||||
} else {
|
||||
data[key] = getStatus(Config.Notice[key])
|
||||
}
|
||||
}
|
||||
// 渲染图像
|
||||
return await puppeteer.render('admin/index', {
|
||||
...data,
|
||||
bg: await rodom()
|
||||
}, {
|
||||
e,
|
||||
scale: 1.4
|
||||
})
|
||||
}
|
||||
|
||||
// 查看涩涩设置
|
||||
async SeSe_Settings (e) {
|
||||
let set = setu.getSeSeConfig(e)
|
||||
let { proxy, pixiv, bika, Notice: { sese, sesepro, anonymous } } = Config
|
||||
let data = {
|
||||
sese: getStatus(sese),
|
||||
sesepro: getStatus(sesepro),
|
||||
anonymous: getStatus(anonymous),
|
||||
r18: getStatus(set.r18),
|
||||
cd: Number(set.cd),
|
||||
recall: set.recall ? set.recall : '无',
|
||||
switchProxy: getStatus(proxy.switchProxy),
|
||||
pixivDirectConnection: getStatus(pixiv.pixivDirectConnection),
|
||||
bikaDirectConnection: getStatus(bika.bikaDirectConnection),
|
||||
pixivImageProxy: pixiv.pixivImageProxy,
|
||||
bikaImageProxy: bika.bikaImageProxy,
|
||||
imageQuality: bika.imageQuality
|
||||
}
|
||||
// 渲染图像
|
||||
return await puppeteer.render('admin/sese', {
|
||||
...data,
|
||||
bg: await rodom()
|
||||
}, {
|
||||
e,
|
||||
scale: 1.4
|
||||
})
|
||||
}
|
||||
|
||||
// 增删查头衔屏蔽词
|
||||
async NoTitle (e) {
|
||||
let data = Config.groupTitle.Shielding_words
|
||||
if (/查看/.test(e.msg)) {
|
||||
return e.reply(`现有的头衔屏蔽词如下:${data.join('\n')}`)
|
||||
}
|
||||
let msg = e.msg.replace(/#|(增加|减少)头衔屏蔽词/g, '').trim().split(',')
|
||||
let type = /增加/.test(e.msg)
|
||||
let no = []; let yes = []
|
||||
for (let i of msg) {
|
||||
if (data.includes(i)) {
|
||||
no.push(i)
|
||||
} else {
|
||||
yes.push(i)
|
||||
}
|
||||
}
|
||||
no = _.compact(_.uniq(no))
|
||||
yes = _.compact(_.uniq(yes))
|
||||
if (type) {
|
||||
if (!_.isEmpty(yes)) {
|
||||
for (let i of yes) {
|
||||
Config.modifyarr('groupTitle', 'Shielding_words', i, 'add')
|
||||
}
|
||||
e.reply(`✅ 成功添加:${yes.join(',')}`)
|
||||
}
|
||||
if (!_.isEmpty(no)) {
|
||||
e.reply(`❎ 以下词已存在:${no.join(',')}`)
|
||||
}
|
||||
} else {
|
||||
if (!_.isEmpty(no)) {
|
||||
for (let i of no) {
|
||||
Config.modifyarr('groupTitle', 'Shielding_words', i, 'del')
|
||||
}
|
||||
e.reply(`✅ 成功删除:${no.join(',')}`)
|
||||
}
|
||||
if (!_.isEmpty(yes)) {
|
||||
e.reply(`❎ 以下词未在屏蔽词中:${yes.join(',')}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改头衔匹配模式
|
||||
async NoTitlepattern (e) {
|
||||
let data = Config.groupTitle.Match_pattern ? 0 : 1
|
||||
Config.modify('groupTitle', 'Match_pattern', data)
|
||||
e.reply(`✅ 已修改匹配模式为${data ? '精确' : '模糊'}匹配`)
|
||||
}
|
||||
}
|
||||
|
||||
// 随机底图
|
||||
const rodom = async function () {
|
||||
let image = fs.readdirSync('./plugins/yenai-plugin/resources/admin/imgs/bg')
|
||||
let listImg = []
|
||||
for (let val of image) {
|
||||
listImg.push(val)
|
||||
}
|
||||
let imgs = listImg.length == 1 ? listImg[0] : listImg[_.random(0, listImg.length - 1)]
|
||||
return imgs
|
||||
}
|
||||
|
||||
const getStatus = function (rote) {
|
||||
if (rote) {
|
||||
return '<div class="cfg-status" >已开启</div>'
|
||||
} else {
|
||||
return '<div class="cfg-status status-off">已关闭</div>'
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { Config } from '../components/index.js'
|
||||
import { setu, common } from '../model/index.js'
|
||||
import { Setting } from './setting.js'
|
||||
import { Admin } from './admin.js'
|
||||
const SWITCH_ERROR = '主人没有开放这个功能哦(*/ω\*)'
|
||||
|
||||
let NumReg = '[一壹二两三四五六七八九十百千万亿\\d]+'
|
||||
@@ -128,14 +128,14 @@ export class SeSe extends plugin {
|
||||
num = common.translateChinaNum(num[0])
|
||||
let type = /撤回间隔/.test(e.msg)
|
||||
setu.setGroupRecallTimeAndCd(e.group_id, num, type)
|
||||
new Setting().SeSe_Settings(e)
|
||||
new Admin().SeSe_Settings(e)
|
||||
}
|
||||
|
||||
// 开启r18
|
||||
async setsese (e) {
|
||||
let isopen = !!/开启/.test(e.msg)
|
||||
setu.setR18(e.group_id, isopen)
|
||||
new Setting().SeSe_Settings(e)
|
||||
new Admin().SeSe_Settings(e)
|
||||
}
|
||||
|
||||
// 艾特设置cd
|
||||
|
||||
52
apps/version.js
Normal file
52
apps/version.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { update } from '../../other/update.js'
|
||||
import { Version, Plugin_Name } from '../components/index.js'
|
||||
import { puppeteer } from '../model/index.js'
|
||||
export class NewVersion extends plugin {
|
||||
constructor () {
|
||||
super({
|
||||
name: '椰奶版本信息',
|
||||
event: 'message',
|
||||
priority: 400,
|
||||
rule: [
|
||||
{
|
||||
reg: '^#?椰奶(插件)?版本$',
|
||||
fnc: 'plugin_version'
|
||||
},
|
||||
{
|
||||
reg: '^#?椰奶(插件)?更新日志$',
|
||||
fnc: 'update_log'
|
||||
}
|
||||
]
|
||||
})
|
||||
this.key = 'yenai:restart'
|
||||
}
|
||||
|
||||
async plugin_version () {
|
||||
return versionInfo(this.e)
|
||||
}
|
||||
|
||||
async update_log () {
|
||||
// eslint-disable-next-line new-cap
|
||||
let Update_Plugin = new update()
|
||||
Update_Plugin.e = this.e
|
||||
Update_Plugin.reply = this.reply
|
||||
|
||||
if (Update_Plugin.getPlugin(Plugin_Name)) {
|
||||
this.e.reply(await Update_Plugin.getLog(Plugin_Name))
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
async function versionInfo (e) {
|
||||
return await puppeteer.render(
|
||||
'help/version-info',
|
||||
{
|
||||
currentVersion: Version.ver,
|
||||
changelogs: Version.logs,
|
||||
elem: 'cryo'
|
||||
},
|
||||
{ e, scale: 2 }
|
||||
)
|
||||
}
|
||||
@@ -14,11 +14,11 @@ export default new class newCommon {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 判断权限
|
||||
* @param {*} e
|
||||
* @param {'master'|'admin'|'owner'|'all'} permission 权限
|
||||
* @param {'admin'|'owner'|'all'} role 需要的权限
|
||||
* @return {Boolean}
|
||||
* 判断用户权限
|
||||
* @param {*} e - 接收到的事件对象
|
||||
* @param {'master'|'admin'|'owner'|'all'} [permission='all'] - 命令所需的权限
|
||||
* @param {'admin'|'owner'|'all'} [role='all'] - 用户的权限
|
||||
* @return {boolean} - 是否具有权限
|
||||
*/
|
||||
Authentication (e, permission = 'all', role = 'all') {
|
||||
if (role == 'owner' && !e.group.is_owner) {
|
||||
@@ -58,10 +58,12 @@ export default new class newCommon {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 秒转换返回对象
|
||||
* @param {Number} time 秒数
|
||||
* @param {boolean} repair 是否需要补零
|
||||
*/
|
||||
* 将给定的秒数转换为日,时,分和秒,并返回一个对象。
|
||||
*
|
||||
* @param {number} time - 要转换的秒数
|
||||
* @param {boolean} repair - 是否修复不足 10 的时,分,秒数
|
||||
* @returns {{day: number, hour: (string|number), minute: (string|number), second: (string|number)}} - 包含转换结果的对象
|
||||
*/
|
||||
getsecond (time, repair) {
|
||||
let second = parseInt(time)
|
||||
let minute = 0
|
||||
@@ -93,21 +95,22 @@ export default new class newCommon {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: //发送转发消息
|
||||
* @param {*} e oicq
|
||||
* @param {Array} message 发送的消息
|
||||
* @param {Object} data 发送的消息
|
||||
* @param {Number} data.recallMsg 撤回时间
|
||||
* @param {Object} data.info 转发发送人信息
|
||||
* @param {String} data.info.nickname 转发发送人昵称
|
||||
* @param {Number} data.info.user_id 转发发送人QQ
|
||||
* @param {String} data.fkmsg 风控消息不传则默认消息
|
||||
* @param {Boolean} data.isxml 是否处理卡片
|
||||
* @param {Boolean} data.isxmlMsg 是否处理卡片显示消息
|
||||
* @param {Boolean} data.oneMsg 是否只有一条消息
|
||||
* @param {Boolean | import('icqq').Anonymous} data.anony 匿名消息
|
||||
* @return {Promise<import('icqq').MessageRet>} 消息发送结果
|
||||
*/
|
||||
* 发送转发消息
|
||||
* @async
|
||||
* @param {*} e - 发送消息的目标对象
|
||||
* @param {Array<string>} message - 发送的消息数组
|
||||
* @param {Object} options - 发送消息的配置项
|
||||
* @param {Number} options.recallMsg - 撤回时间,单位秒,默认为0表示不撤回
|
||||
* @param {Object} options.info - 转发发送人信息
|
||||
* @param {String} options.info.nickname - 转发发送人昵称,默认为机器人的昵称
|
||||
* @param {Number} options.info.user_id - 转发发送人QQ,默认为机器人的QQ号
|
||||
* @param {String} options.fkmsg - 风控消息,不传则默认消息
|
||||
* @param {Boolean} options.isxml - 是否处理卡片,若为true则处理卡片
|
||||
* @param {Boolean} options.isxmlMsg - 是否处理卡片显示消息
|
||||
* @param {Boolean} options.oneMsg - 是否只有一条消息
|
||||
* @param {Boolean | import('icqq').Anonymous} options.anony - 匿名消息,若为true则发送匿名消息
|
||||
* @returns {Promise<import('icqq').MessageRet>} - 消息发送结果的Promise对象
|
||||
*/
|
||||
async getforwardMsg (e, message, {
|
||||
recallMsg = 0,
|
||||
info = {
|
||||
@@ -154,16 +157,19 @@ export default new class newCommon {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 发送消息
|
||||
* @param {*} e oicq
|
||||
* @param {Array|String} msg 消息
|
||||
* @param {Boolean} quote 是否引用回复
|
||||
* @param {Object} data 其他参数
|
||||
* @param {Number} data.recallMsg 撤回时间
|
||||
* @param {Boolean} data.fkmsg 风控消息
|
||||
* @param {Boolean | import('icqq').Anonymous} data.anony 匿名消息
|
||||
* @return {Promise<import('icqq').MessageRet>}
|
||||
*/
|
||||
* 发送消息
|
||||
*
|
||||
* @async
|
||||
* @param {*} e oicq 事件对象
|
||||
* @param {Array|String} msg 消息内容
|
||||
* @param {Boolean} quote 是否引用回复
|
||||
* @param {Object} data 其他参数
|
||||
* @param {Number} data.recallMsg 撤回时间
|
||||
* @param {Boolean} data.fkmsg 风控消息
|
||||
* @param {Boolean | import('icqq').Anonymous} data.anony 匿名消息
|
||||
* @param {Boolean | Number} data.at 是否艾特该成员
|
||||
* @returns {Promise<import('icqq').MessageRet>} 返回发送消息后的结果对象
|
||||
*/
|
||||
async reply (e, msg, quote, {
|
||||
recallMsg = 0,
|
||||
fkmsg = '',
|
||||
@@ -216,16 +222,16 @@ export default new class newCommon {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 获取配置的撤回事件和匿名发送普通消息
|
||||
* @param {*} e oicq
|
||||
* @param {Array|String} msg 消息
|
||||
* @param {Boolean} quote 是否引用回复
|
||||
* @param {Object} data 其他参数
|
||||
* @param {Number} data.recallMsg 撤回时间
|
||||
* @param {Boolean} data.fkmsg 风控消息
|
||||
* @param {Boolean | Omit<Anonymous, "flag">} data.anony 匿名消息
|
||||
* @return {Promise<MessageRet>}
|
||||
*/
|
||||
* @description: 获取配置的撤回事件和匿名发送普通消息
|
||||
* @param {*} e oicq
|
||||
* @param {Array|String} msg 消息
|
||||
* @param {Boolean} quote 是否引用回复
|
||||
* @param {Object} data 其他参数
|
||||
* @param {Number} data.recallMsg 撤回时间
|
||||
* @param {Boolean} data.fkmsg 风控消息
|
||||
* @param {Boolean | import('icqq').Anonymous} data.anony 匿名消息
|
||||
* @return {Promise<import('icqq').MessageRet>}
|
||||
*/
|
||||
async recallsendMsg (e, msg, quote, data = {}) {
|
||||
let recallMsg = setu.getRecallTime(e.group_id)
|
||||
let anony = Config.Notice.anonymous
|
||||
|
||||
@@ -31,12 +31,17 @@ export const qs = (obj) => {
|
||||
|
||||
export default new class {
|
||||
/**
|
||||
* @description: Get请求
|
||||
* @param {String} url
|
||||
* @param {Object} options 同fetch第二参数
|
||||
* @param {Object} options.params 请求参数
|
||||
* @param {fetch[BodyMixin]} options.statusCode 返回数据类型
|
||||
* @return {FetchObject}
|
||||
* 发送HTTP GET请求并返回响应
|
||||
* @async
|
||||
* @function
|
||||
* @param {string} url - 请求的URL
|
||||
* @param {Object} [options={}] - 请求的配置项
|
||||
* @param {Object} [options.params] - 请求的参数
|
||||
* @param {Object} [options.headers] - 请求的HTTP头部
|
||||
* @param {boolean} [options.closeCheckStatus=false] - 是否关闭状态检查
|
||||
* @param {'buffer'|'json'|'text'|'arrayBuffer'|'formData'|'blob'} [options.statusCode] - 期望的返回数据,如果设置了该值,则返回响应数据的特定的方法(如json()、text()等)
|
||||
* @returns {Promise<Response|*>} - HTTP响应或响应数据
|
||||
* @throws {Error} - 如果请求失败,则抛出错误
|
||||
*/
|
||||
async get (url, options = {}) {
|
||||
// 处理参数
|
||||
@@ -66,10 +71,18 @@ export default new class {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Post请求
|
||||
* @param {String} url 链接
|
||||
* @param {Object|Sring} options.data 参数
|
||||
* @param {fetch[BodyMixin]} options.statusCode 返回数据类型
|
||||
* 发送HTTP POST请求并返回响应
|
||||
* @async
|
||||
* @function
|
||||
* @param {string} url - 请求的URL
|
||||
* @param {Object} [options={}] - 请求的配置项
|
||||
* @param {Object} [options.params] - 请求的参数
|
||||
* @param {Object} [options.headers] - 请求的HTTP头部
|
||||
* @param {Object} [options.data] - 请求的数据
|
||||
* @param {boolean} [options.closeCheckStatus=false] - 是否关闭状态检查
|
||||
* @param {'buffer'|'json'|'text'|'arrayBuffer'|'formData'|'blob'} [options.statusCode] - 期望的返回数据,如果设置了该值,则返回响应数据的特定的方法(如json()、text()等)
|
||||
* @returns {Promise<Response|*>} - HTTP响应或响应数据
|
||||
* @throws {Error} - 如果请求失败,则抛出错误
|
||||
*/
|
||||
async post (url, options = {}) {
|
||||
options.method = 'POST'
|
||||
@@ -188,7 +201,7 @@ export default new class {
|
||||
* @param {Boolean} cache 是否缓存
|
||||
* @param {Number} timeout 超时时间
|
||||
* @param {Object} headers 请求头
|
||||
* @return {segment.image} 构造图片消息
|
||||
* @return {import('icqq').ImageElem} 构造图片消息
|
||||
*/
|
||||
async proxyRequestImg (url, { cache, timeout, headers } = {}) {
|
||||
if (!this.getAgent()) return segment.image(url, cache, timeout, headers)
|
||||
|
||||
Reference in New Issue
Block a user