feat: 调整
This commit is contained in:
parent
e1f53b1cc6
commit
61b099ce81
|
@ -10,11 +10,20 @@ import { CONFIG_DEFAULT_PATH, CONFIG_INIT_PATH } from './system.js'
|
|||
* ********
|
||||
*/
|
||||
class Cfg {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
config = {}
|
||||
|
||||
/** 监听文件 */
|
||||
/**
|
||||
* 监听文件
|
||||
*/
|
||||
watcher = { config: {}, defSet: {} }
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
this.initCfg()
|
||||
}
|
||||
|
|
|
@ -52,8 +52,10 @@ function createLog() {
|
|||
const commandLogger = log4js.getLogger('command')
|
||||
const errorLogger = log4js.getLogger('error')
|
||||
|
||||
/** 调整error日志等级 */
|
||||
|
||||
/**
|
||||
* 调整error日志等级
|
||||
*/
|
||||
const logger = {
|
||||
trace() {
|
||||
defaultLogger.trace.call(defaultLogger, ...arguments)
|
||||
|
@ -100,7 +102,9 @@ export default function setLog() {
|
|||
})
|
||||
}
|
||||
|
||||
/** 全局变量 logger */
|
||||
/**
|
||||
* 全局变量 logger
|
||||
*/
|
||||
global.logger = createLog() as any
|
||||
|
||||
logger.chalk = chalk
|
||||
|
|
|
@ -4,9 +4,24 @@ import PluginsLoader from './plugins.loader.js'
|
|||
*
|
||||
*/
|
||||
export default class EventListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
prefix = ''
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
event = null
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
once = false
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
plugins = PluginsLoader
|
||||
/**
|
||||
* 事件监听
|
||||
|
|
|
@ -13,8 +13,17 @@ import Handler from './plugins/handler.js'
|
|||
* 加载插件
|
||||
*/
|
||||
class PluginsLoader {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
priority = []
|
||||
/**
|
||||
*
|
||||
*/
|
||||
handler = {}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
task = []
|
||||
|
||||
//
|
||||
|
@ -25,7 +34,9 @@ class PluginsLoader {
|
|||
*/
|
||||
groupGlobalCD = {}
|
||||
|
||||
//
|
||||
/**
|
||||
*
|
||||
*/
|
||||
singleCD = {}
|
||||
|
||||
/**
|
||||
|
@ -33,9 +44,21 @@ class PluginsLoader {
|
|||
*/
|
||||
watcher = {}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
eventMap = {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
message: ['post_type', 'message_type', 'sub_type'],
|
||||
/**
|
||||
*
|
||||
*/
|
||||
notice: ['post_type', 'notice_type', 'sub_type'],
|
||||
/**
|
||||
*
|
||||
*/
|
||||
request: ['post_type', 'request_type', 'sub_type']
|
||||
}
|
||||
|
||||
|
@ -89,6 +112,9 @@ class PluginsLoader {
|
|||
return ret
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
pluginCount = null
|
||||
|
||||
/**
|
||||
|
@ -436,8 +462,14 @@ class PluginsLoader {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
e.logText = ''
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (e.message_type === 'private' || e.notice_type === 'friend') {
|
||||
e.isPrivate = true
|
||||
|
||||
|
@ -453,6 +485,9 @@ class PluginsLoader {
|
|||
e.logText = `[私聊][${e.sender.nickname}(${e.user_id})]`
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (e.message_type === 'group' || e.notice_type === 'group') {
|
||||
e.isGroup = true
|
||||
if (e.sender) {
|
||||
|
@ -480,6 +515,9 @@ class PluginsLoader {
|
|||
e.isGuild = true
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (
|
||||
e.user_id &&
|
||||
cfg.masterQQ.includes(String(e.user_id) || String(e.user_id))
|
||||
|
@ -487,7 +525,9 @@ class PluginsLoader {
|
|||
e.isMaster = true
|
||||
}
|
||||
|
||||
/** 只关注主动at msg处理 */
|
||||
/**
|
||||
* 只关注主动at msg处理
|
||||
*/
|
||||
if (e.msg && e.isGroup) {
|
||||
let groupCfg = cfg.getGroup(e.group_id)
|
||||
let alias = groupCfg.botAlias
|
||||
|
@ -509,7 +549,13 @@ class PluginsLoader {
|
|||
* @param e
|
||||
*/
|
||||
reply(e) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (e.reply) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
e.replyNew = e.reply
|
||||
|
||||
/**
|
||||
|
@ -581,7 +627,13 @@ class PluginsLoader {
|
|||
this.count(e, msg)
|
||||
return msgRes
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
} else {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
e.reply = async (msg = '', _ = false, __ = {}) => {
|
||||
if (!msg) return false
|
||||
this.count(e, msg)
|
||||
|
@ -609,16 +661,37 @@ class PluginsLoader {
|
|||
* @param msg
|
||||
*/
|
||||
count(e, msg) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let screenshot = false
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (msg && msg?.file && Buffer.isBuffer(msg?.file)) {
|
||||
screenshot = true
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
this.saveCount('sendMsg')
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (screenshot) this.saveCount('screenshot')
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (e.group_id) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
this.saveCount('sendMsg', e.group_id)
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (screenshot) this.saveCount('screenshot', e.group_id)
|
||||
}
|
||||
}
|
||||
|
@ -629,20 +702,53 @@ class PluginsLoader {
|
|||
* @param groupId
|
||||
*/
|
||||
saveCount(type, groupId = '') {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let key = 'Yz:count:'
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (groupId) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
key += `group:${groupId}:`
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let dayKey = `${key}${type}:day:${moment().format('MMDD')}`
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let monthKey = `${key}${type}:month:${Number(moment().month()) + 1}`
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let totalKey = `${key}${type}:total`
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
redis.incr(dayKey)
|
||||
/**
|
||||
*
|
||||
*/
|
||||
redis.incr(monthKey)
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (!groupId) redis.incr(totalKey)
|
||||
/**
|
||||
*
|
||||
*/
|
||||
redis.expire(dayKey, 3600 * 24 * 30)
|
||||
/**
|
||||
*
|
||||
*/
|
||||
redis.expire(monthKey, 3600 * 24 * 30)
|
||||
}
|
||||
|
||||
|
@ -650,8 +756,17 @@ class PluginsLoader {
|
|||
*
|
||||
*/
|
||||
delCount() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let key = 'Yz:count:'
|
||||
/**
|
||||
*
|
||||
*/
|
||||
redis.set(`${key}sendMsg:total`, '0')
|
||||
/**
|
||||
*
|
||||
*/
|
||||
redis.set(`${key}screenshot:total`, '0')
|
||||
}
|
||||
|
||||
|
@ -660,18 +775,31 @@ class PluginsLoader {
|
|||
* @param task
|
||||
*/
|
||||
collectTask(task) {
|
||||
for (const i of Array.isArray(task) ? task : [task])
|
||||
/**
|
||||
*
|
||||
*/
|
||||
for (const i of Array.isArray(task) ? task : [task]) {
|
||||
if (i?.cron && i?.name) {
|
||||
this.task.push(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建定时任务
|
||||
*/
|
||||
createTask() {
|
||||
for (const i of this.task)
|
||||
/**
|
||||
*
|
||||
*/
|
||||
for (const i of this.task) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
i.job = schedule.scheduleJob(i?.cron, async () => {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
try {
|
||||
if (i.log == true) logger.mark(`开始定时任务:${i.name}`)
|
||||
await i.fnc()
|
||||
|
@ -682,6 +810,7 @@ class PluginsLoader {
|
|||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查命令冷却cd
|
||||
|
@ -691,24 +820,48 @@ class PluginsLoader {
|
|||
checkLimit(e) {
|
||||
/** 禁言中 */
|
||||
if (e.isGroup && e?.group?.mute_left > 0) return false
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (!e.message || e.isPrivate) return true
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let config = cfg.getGroup(e.group_id)
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (config.groupGlobalCD && this.groupGlobalCD[e.group_id]) {
|
||||
return false
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (config.singleCD && this.singleCD[`${e.group_id}.${e.user_id}`]) {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let { msgThrottle } = this
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let msgId = e.user_id + ':' + e.raw_message
|
||||
if (msgThrottle[msgId]) {
|
||||
return false
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
msgThrottle[msgId] = true
|
||||
/**
|
||||
*
|
||||
*/
|
||||
setTimeout(() => {
|
||||
delete msgThrottle[msgId]
|
||||
}, 200)
|
||||
|
@ -722,9 +875,18 @@ class PluginsLoader {
|
|||
* @returns
|
||||
*/
|
||||
setLimit(e) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (!e.message || e.isPrivate) return
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let config = cfg.getGroup(e.group_id)
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (config.groupGlobalCD) {
|
||||
this.groupGlobalCD[e.group_id] = true
|
||||
setTimeout(() => {
|
||||
|
@ -780,6 +942,9 @@ class PluginsLoader {
|
|||
* @returns
|
||||
*/
|
||||
checkBlack(e) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const other = cfg.getOther()
|
||||
|
||||
/** 黑名单qq */
|
||||
|
@ -866,13 +1031,17 @@ class PluginsLoader {
|
|||
const watcher = chokidar.watch(file)
|
||||
const key = `${dirName}/${appName}`
|
||||
|
||||
/** 监听修改 */
|
||||
/**
|
||||
* 监听修改
|
||||
*/
|
||||
watcher.on('change', () => {
|
||||
logger.mark(`[修改插件][${dirName}][${appName}]`)
|
||||
this.changePlugin(key)
|
||||
})
|
||||
|
||||
/** 监听删除 */
|
||||
/**
|
||||
* 监听删除
|
||||
*/
|
||||
watcher.on('unlink', () => {
|
||||
logger.mark(`[卸载插件][${dirName}][${appName}]`)
|
||||
/** 停止更新监听 */
|
||||
|
@ -895,20 +1064,35 @@ class PluginsLoader {
|
|||
watchDir(dirName) {
|
||||
if (this.watcher[dirName]) return
|
||||
const watcher = chokidar.watch(`./${this.dir}/${dirName}/`)
|
||||
/** 热更新 */
|
||||
|
||||
/**
|
||||
* 热更新
|
||||
*/
|
||||
setTimeout(() => {
|
||||
/** 新增文件 */
|
||||
/**
|
||||
* 新增文件
|
||||
*/
|
||||
watcher.on('add', async PluPath => {
|
||||
const appName = path.basename(PluPath)
|
||||
if (!appName.endsWith('.js')) return
|
||||
/**
|
||||
*/
|
||||
if (!/^(.js|.ts)$/.test(appName)) return
|
||||
logger.mark(`[新增插件][${dirName}][${appName}]`)
|
||||
const key = `${dirName}/${appName}`
|
||||
/**
|
||||
*
|
||||
*/
|
||||
await this.importPlugin({
|
||||
name: key,
|
||||
path: `../../${this.dir}/${key}?${moment().format('X')}`
|
||||
})
|
||||
/** 优先级排序 */
|
||||
/**
|
||||
* 优先级排序
|
||||
*/
|
||||
this.priority = lodash.orderBy(this.priority, ['priority'], ['asc'])
|
||||
/**
|
||||
*
|
||||
*/
|
||||
this.watch(dirName, appName)
|
||||
})
|
||||
}, 10000)
|
||||
|
|
|
@ -20,16 +20,24 @@ export const PluginSuperDefine: {
|
|||
* 消息
|
||||
*/
|
||||
export class Messages {
|
||||
count = 0
|
||||
rule: {
|
||||
#count = 0
|
||||
#rule: {
|
||||
reg: RegExp
|
||||
fnc: string
|
||||
}[] = []
|
||||
|
||||
#init = PluginSuperDefine
|
||||
|
||||
/**
|
||||
* 初始化配置
|
||||
* @param init
|
||||
*/
|
||||
constructor(init?: typeof PluginSuperDefine) {
|
||||
this.#init = init
|
||||
for (const key in init) {
|
||||
if (Object.prototype.hasOwnProperty.call(this.#init, key)) {
|
||||
this.#init[key] = init[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,10 +46,10 @@ export class Messages {
|
|||
* @param fnc
|
||||
*/
|
||||
response(reg: RegExp, fnc: MessageCallBackType) {
|
||||
this.count++
|
||||
const propName = `prop_${this.count}`
|
||||
this.#count++
|
||||
const propName = `prop_${this.#count}`
|
||||
this[propName] = fnc
|
||||
this.rule.push({
|
||||
this.#rule.push({
|
||||
reg,
|
||||
fnc: propName
|
||||
})
|
||||
|
@ -55,9 +63,10 @@ export class Messages {
|
|||
constructor() {
|
||||
super({
|
||||
...App.#init,
|
||||
rule: App.rule
|
||||
rule: App.#rule
|
||||
})
|
||||
for (const key of App.rule) {
|
||||
for (const key of App.#rule) {
|
||||
// 确认存在该函数
|
||||
if (App[key.fnc] instanceof Function) {
|
||||
this[key.fnc] = App[key.fnc].bind(App)
|
||||
}
|
||||
|
@ -75,12 +84,12 @@ export class Events {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
count = 0
|
||||
#count = 0
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
data: {
|
||||
#data: {
|
||||
[key: string]: typeof plugin
|
||||
} = {}
|
||||
|
||||
|
@ -89,14 +98,14 @@ export class Events {
|
|||
* @param val
|
||||
*/
|
||||
use(val: typeof plugin) {
|
||||
this.count++
|
||||
this.data[this.count] = val
|
||||
this.#count++
|
||||
this.#data[this.#count] = val
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
get ok() {
|
||||
return this.data
|
||||
return this.#data
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,23 @@
|
|||
import { Common } from '../../miao.js'
|
||||
import { EventType } from './types.js'
|
||||
|
||||
const stateArr = {}
|
||||
const State = {}
|
||||
const SymbolTimeout = Symbol('Timeout')
|
||||
const SymbolResolve = Symbol('Resolve')
|
||||
|
||||
export class plugin {
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
name = 'your-plugin'
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
dsc = '无'
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
task = null
|
||||
rule: {
|
||||
reg?: RegExp | string
|
||||
fnc: string
|
||||
|
@ -17,7 +27,6 @@ export class plugin {
|
|||
}[] = []
|
||||
event = 'message'
|
||||
priority = 9999
|
||||
task = null
|
||||
namespace = null
|
||||
handler = null
|
||||
e: EventType
|
||||
|
@ -53,12 +62,21 @@ export class plugin {
|
|||
task,
|
||||
rule
|
||||
}: {
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
name?: typeof this.name
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
dsc?: typeof this.dsc
|
||||
namespace?: typeof this.namespace
|
||||
priority?: typeof this.priority
|
||||
handler?: typeof this.handler
|
||||
event?: typeof this.event
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
task?: typeof this.task
|
||||
rule?: typeof this.rule
|
||||
}) {
|
||||
|
@ -92,6 +110,7 @@ export class plugin {
|
|||
* @param quote 是否引用回复
|
||||
* @param data.recallMsg 群聊是否撤回消息,0-120秒,0不撤回
|
||||
* @param data.at 是否at用户
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
reply(msg = '', quote = false, data = {}) {
|
||||
if (!this.e?.reply || !msg) return false
|
||||
|
@ -99,14 +118,20 @@ export class plugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* ******
|
||||
* tudo
|
||||
* 异常写法
|
||||
* *****
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
group_id: number
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
groupId: number
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
user_id: number
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
userId: number
|
||||
|
||||
/**
|
||||
|
@ -135,17 +160,17 @@ export class plugin {
|
|||
timeout = '操作超时已取消'
|
||||
) {
|
||||
const key = this.conKey(isGroup)
|
||||
if (!stateArr[key]) stateArr[key] = {}
|
||||
stateArr[key][type] = this.e
|
||||
if (!State[key]) State[key] = {}
|
||||
State[key][type] = this.e
|
||||
if (time)
|
||||
stateArr[key][type][SymbolTimeout] = setTimeout(() => {
|
||||
if (stateArr[key][type]) {
|
||||
const resolve = stateArr[key][type][SymbolResolve]
|
||||
delete stateArr[key][type]
|
||||
State[key][type][SymbolTimeout] = setTimeout(() => {
|
||||
if (State[key][type]) {
|
||||
const resolve = State[key][type][SymbolResolve]
|
||||
delete State[key][type]
|
||||
resolve ? resolve(false) : this.reply(timeout, true)
|
||||
}
|
||||
}, time * 1000)
|
||||
return stateArr[key][type]
|
||||
return State[key][type]
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,8 +180,8 @@ export class plugin {
|
|||
* @returns
|
||||
*/
|
||||
getContext(type: string, isGroup?: boolean) {
|
||||
if (type) return stateArr[this.conKey(isGroup)]?.[type]
|
||||
return stateArr[this.conKey(isGroup)]
|
||||
if (type) return State[this.conKey(isGroup)]?.[type]
|
||||
return State[this.conKey(isGroup)]
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,9 +191,9 @@ export class plugin {
|
|||
*/
|
||||
finish(type: string, isGroup?: boolean) {
|
||||
const key = this.conKey(isGroup)
|
||||
if (stateArr[key]?.[type]) {
|
||||
clearTimeout(stateArr[key][type][SymbolTimeout])
|
||||
delete stateArr[key][type]
|
||||
if (State[key]?.[type]) {
|
||||
clearTimeout(State[key][type][SymbolTimeout])
|
||||
delete State[key][type]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,7 +219,7 @@ export class plugin {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated 已废弃
|
||||
* @param plugin
|
||||
* @param tpl
|
||||
* @param data
|
||||
|
|
|
@ -10,7 +10,7 @@ Data.createDir('/data/db', 'root')
|
|||
/**
|
||||
* DB自定义
|
||||
*/
|
||||
const sequelize = new Sequelize({
|
||||
export const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: join(process.cwd(), '/data/db/data.db'),
|
||||
logging: false
|
||||
|
@ -34,8 +34,3 @@ export default class BaseModel extends Model {
|
|||
model.COLUMNS = columns
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export { sequelize }
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import BaseModel from './BaseModel.js'
|
||||
|
||||
const { Types } = BaseModel
|
||||
import { DataTypes } from 'sequelize'
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -8,22 +7,22 @@ const { Types } = BaseModel
|
|||
const COLUMNS = {
|
||||
// 用户ID,qq为数字
|
||||
ltuid: {
|
||||
type: Types.INTEGER,
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true
|
||||
},
|
||||
|
||||
// MysUser类型,mys / hoyolab
|
||||
type: {
|
||||
type: Types.STRING,
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'mys',
|
||||
notNull: true
|
||||
},
|
||||
|
||||
// CK
|
||||
ck: Types.STRING,
|
||||
device: Types.STRING,
|
||||
ck: DataTypes.STRING,
|
||||
device: DataTypes.STRING,
|
||||
uids: {
|
||||
type: Types.STRING,
|
||||
type: DataTypes.STRING,
|
||||
get() {
|
||||
let data = this.getDataValue('uids')
|
||||
let ret = {}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
import BaseModel from './BaseModel.js'
|
||||
import lodash from 'lodash'
|
||||
import MysUtil from '../mys/MysUtil.js'
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const { Types } = BaseModel
|
||||
import { DataTypes } from 'sequelize'
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -13,26 +9,26 @@ const { Types } = BaseModel
|
|||
const COLUMNS = {
|
||||
// 用户ID,qq为数字
|
||||
id: {
|
||||
type: Types.STRING,
|
||||
type: DataTypes.STRING,
|
||||
autoIncrement: false,
|
||||
primaryKey: true
|
||||
},
|
||||
|
||||
type: {
|
||||
type: Types.STRING,
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'qq',
|
||||
notNull: true
|
||||
},
|
||||
|
||||
// 昵称
|
||||
name: Types.STRING,
|
||||
name: DataTypes.STRING,
|
||||
|
||||
// 头像
|
||||
face: Types.STRING,
|
||||
face: DataTypes.STRING,
|
||||
|
||||
ltuids: Types.STRING,
|
||||
ltuids: DataTypes.STRING,
|
||||
games: {
|
||||
type: Types.STRING,
|
||||
type: DataTypes.STRING,
|
||||
get() {
|
||||
let data = this.getDataValue('games')
|
||||
let ret = {}
|
||||
|
@ -54,7 +50,7 @@ const COLUMNS = {
|
|||
this.setDataValue('games', JSON.stringify(data))
|
||||
}
|
||||
},
|
||||
data: Types.STRING
|
||||
data: DataTypes.STRING
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,23 +1,18 @@
|
|||
import { DataTypes } from 'sequelize'
|
||||
import BaseModel from './BaseModel.js'
|
||||
import lodash from 'lodash'
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const { Types } = BaseModel
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const COLUMNS = {
|
||||
// 用户ID,qq为数字
|
||||
userId: {
|
||||
type: Types.STRING
|
||||
type: DataTypes.STRING
|
||||
},
|
||||
game: Types.STRING,
|
||||
uid: Types.STRING,
|
||||
game: DataTypes.STRING,
|
||||
uid: DataTypes.STRING,
|
||||
data: {
|
||||
type: Types.STRING,
|
||||
type: DataTypes.STRING,
|
||||
get() {
|
||||
let data = this.getDataValue('data')
|
||||
let ret = {}
|
||||
|
|
|
@ -54,21 +54,26 @@ type ChalkInstanceType = {
|
|||
|
||||
declare global {
|
||||
/**
|
||||
* @deprecated 不推荐使用
|
||||
* @deprecated 不推荐使用,未来将废弃
|
||||
*/
|
||||
var redis: RedisClientType
|
||||
/**
|
||||
* @deprecated 不推荐使用
|
||||
*
|
||||
* @deprecated 不推荐使用,未来将废弃
|
||||
*/
|
||||
var Bot: typeof Yunzai.prototype
|
||||
/**
|
||||
* @deprecated 不推荐使用
|
||||
* @deprecated 不推荐使用,未来将废弃
|
||||
*/
|
||||
var segment: typeof se
|
||||
/**
|
||||
* @deprecated 不推荐使用
|
||||
* @deprecated 不推荐使用,未来将废弃
|
||||
*/
|
||||
var plugin: typeof p
|
||||
/**
|
||||
* 统一化的打印对象
|
||||
* 构造颜色请使用 logger.chalk
|
||||
*/
|
||||
var logger: LoggerType &
|
||||
ChalkInstanceType & {
|
||||
chalk: ChalkInstance
|
||||
|
|
|
@ -3,9 +3,19 @@
|
|||
*/
|
||||
import MysUtil from './MysUtil.js'
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const cacheMap = {}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const reFn = {}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export default class BaseModel {
|
||||
_uuid = null
|
||||
|
||||
|
|
|
@ -3,11 +3,19 @@ import BaseModel from './BaseModel.js'
|
|||
import MysUtil from './MysUtil.js'
|
||||
import { REDIS_ROOT_KEY } from '../config/system.js'
|
||||
|
||||
//
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const servs = ['mys', 'hoyolab']
|
||||
// 超时时间不必精确,直接定24小时即可
|
||||
|
||||
/**
|
||||
* 超时时间不必精确,直接定24小时即可
|
||||
*/
|
||||
const EX = 3600 * 24
|
||||
//
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const redisKeyRoot = REDIS_ROOT_KEY
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,16 +5,14 @@
|
|||
* 一个MysUser对应一个有效CK
|
||||
* 一个MysUser可能有多个MysUid关联记录
|
||||
*/
|
||||
import lodash from 'lodash'
|
||||
import fetch from 'node-fetch'
|
||||
import DailyCache from './DailyCache.js'
|
||||
import BaseModel from './BaseModel.js'
|
||||
import NoteUser from './NoteUser.js'
|
||||
import MysApi from './mysApi.js'
|
||||
import MysUtil from './MysUtil.js'
|
||||
import lodash from 'lodash'
|
||||
import fetch from 'node-fetch'
|
||||
|
||||
import { MysUserDB } from '../db/index.js'
|
||||
|
||||
import { Data } from '../miao.js'
|
||||
|
||||
const tables = {
|
||||
|
|
|
@ -11,7 +11,7 @@ const games = [
|
|||
/**
|
||||
*
|
||||
*/
|
||||
const MysUtil = {
|
||||
export default {
|
||||
/**
|
||||
* 获取标准ltuid
|
||||
* @param data
|
||||
|
@ -87,8 +87,3 @@ const MysUtil = {
|
|||
await Data.forEach(['mys', 'hoyolab'], fn)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export default MysUtil
|
||||
|
|
|
@ -14,6 +14,13 @@ import { Data } from '../miao.js'
|
|||
* *******************
|
||||
*/
|
||||
export default class NoteUser extends BaseModel {
|
||||
db = null
|
||||
|
||||
qq = null
|
||||
|
||||
mysUsers = null
|
||||
|
||||
_map = null
|
||||
/**
|
||||
*
|
||||
* @param qq
|
||||
|
@ -129,10 +136,6 @@ export default class NoteUser extends BaseModel {
|
|||
})
|
||||
}
|
||||
|
||||
db = null
|
||||
|
||||
qq = null
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
* @param db
|
||||
|
@ -152,8 +155,6 @@ export default class NoteUser extends BaseModel {
|
|||
await this.save()
|
||||
}
|
||||
|
||||
mysUsers = null
|
||||
|
||||
/**
|
||||
* 初始化MysUser对象
|
||||
*/
|
||||
|
@ -425,8 +426,6 @@ export default class NoteUser extends BaseModel {
|
|||
return await this.delMysUser(ltuid)
|
||||
}
|
||||
|
||||
_map = null
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mysUser
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
mys 存在循环引用
|
||||
|
||||
(!) Circular dependencies
|
||||
src/mys/apiTool.ts -> src/mys/mysApi.ts -> src/mys/apiTool.ts
|
||||
src/mys/gsCfg.ts -> src/mys/mysInfo.ts -> src/mys/gsCfg.ts
|
||||
src/mys/NoteUser.ts -> src/mys/MysUser.ts -> src/mys/NoteUser.ts
|
|
@ -7,14 +7,12 @@ import mysInfo from './mysInfo.js'
|
|||
import MysUser from './MysUser.js'
|
||||
import MysUtil from './MysUtil.js'
|
||||
import NoteUser from './NoteUser.js'
|
||||
export {
|
||||
apiTool,
|
||||
BaseModel,
|
||||
DailyCache,
|
||||
gsCfg,
|
||||
mysApi,
|
||||
mysInfo,
|
||||
MysUser,
|
||||
MysUtil,
|
||||
NoteUser
|
||||
}
|
||||
export const ApiTool = apiTool
|
||||
export const GSCfg = gsCfg
|
||||
export const MysApi = mysApi
|
||||
export const MysInfo = mysInfo
|
||||
export { BaseModel, DailyCache, MysUser, MysUtil, NoteUser }
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
export { apiTool, gsCfg, mysApi, mysInfo }
|
||||
|
|
|
@ -3,6 +3,9 @@ import fetch from 'node-fetch'
|
|||
import cfg from '../config/config.js'
|
||||
import apiTool from './apiTool.js'
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
let HttpsProxyAgent = null
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import MysApi from './mysApi.js'
|
||||
|
||||
// tudo
|
||||
import GsCfg from './gsCfg.js'
|
||||
|
||||
import lodash from 'lodash'
|
||||
import MysApi from './mysApi.js'
|
||||
import GsCfg from './gsCfg.js'
|
||||
import NoteUser from './NoteUser.js'
|
||||
import MysUser from './MysUser.js'
|
||||
import DailyCache from './DailyCache.js'
|
||||
|
@ -15,14 +12,23 @@ import DailyCache from './DailyCache.js'
|
|||
*/
|
||||
export default class MysInfo {
|
||||
static tips = '请先#绑定Cookie\n发送【Cookie帮助】查看配置教程'
|
||||
/**
|
||||
* 当前查询原神uid
|
||||
*/
|
||||
uid = null
|
||||
e = null
|
||||
userId = null
|
||||
/**
|
||||
* 当前ck信息
|
||||
*/
|
||||
ckInfo = null
|
||||
auth = null
|
||||
gtest = null
|
||||
mysButton = null
|
||||
|
||||
/**
|
||||
* ck对应MysUser对象
|
||||
*/
|
||||
ckUser = null
|
||||
/**
|
||||
*
|
||||
* @param e
|
||||
|
@ -32,9 +38,7 @@ export default class MysInfo {
|
|||
this.e = e
|
||||
this.userId = String(e.user_id)
|
||||
}
|
||||
/** 当前查询原神uid */
|
||||
this.uid = ''
|
||||
/** 当前ck信息 */
|
||||
this.ckInfo = {
|
||||
ck: '',
|
||||
uid: '',
|
||||
|
@ -42,7 +46,6 @@ export default class MysInfo {
|
|||
ltuid: '',
|
||||
type: ''
|
||||
}
|
||||
// ck对应MysUser对象
|
||||
this.ckUser = null
|
||||
this.auth = [
|
||||
'dailyNote',
|
||||
|
@ -60,9 +63,7 @@ export default class MysInfo {
|
|||
'action_cardList',
|
||||
'avatarInfo'
|
||||
]
|
||||
|
||||
this.gtest = false
|
||||
|
||||
/**
|
||||
* ********
|
||||
* tudo
|
||||
|
@ -619,8 +620,6 @@ export default class MysInfo {
|
|||
return res
|
||||
}
|
||||
|
||||
ckUser = null
|
||||
|
||||
/**
|
||||
* 删除失效ck
|
||||
* @returns
|
||||
|
|
|
@ -47,6 +47,7 @@ export function mkdirs(dirname: string) {
|
|||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,9 @@ import { renderToString } from 'react-dom/server'
|
|||
import { mkdirSync, writeFileSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export type ComponentCreateOpsionType = {
|
||||
html_head?: string
|
||||
html_name?: string
|
||||
|
@ -18,6 +21,9 @@ export type ComponentCreateOpsionType = {
|
|||
*/
|
||||
export class Component {
|
||||
#dir = ''
|
||||
/**
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
this.#dir = join(process.cwd(), 'html')
|
||||
mkdirSync(this.#dir, {
|
||||
|
|
Loading…
Reference in New Issue