fix: 补充类型
This commit is contained in:
parent
9da3312f43
commit
c7e3b94161
|
@ -1,6 +1,8 @@
|
||||||
import YAML from 'yaml'
|
import YAML from 'yaml'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import chokidar from 'chokidar'
|
import chokidar from 'chokidar'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
import { CONFIG_DEFAULT_PATH, CONFIG_INIT_PATH } from './system.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ********
|
* ********
|
||||||
|
@ -13,17 +15,17 @@ class Cfg {
|
||||||
/** 监听文件 */
|
/** 监听文件 */
|
||||||
watcher = { config: {}, defSet: {} }
|
watcher = { config: {}, defSet: {} }
|
||||||
|
|
||||||
constructor () {
|
constructor() {
|
||||||
this.initCfg()
|
this.initCfg()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化配置
|
* 初始化配置
|
||||||
*/
|
*/
|
||||||
initCfg () {
|
initCfg() {
|
||||||
let path = 'config/config/'
|
const path = CONFIG_INIT_PATH
|
||||||
let pathDef = 'config/default_config/'
|
const pathDef = CONFIG_DEFAULT_PATH
|
||||||
const files = fs.readdirSync(pathDef).filter(file => file.endsWith('.yaml'))
|
const files = fs.readdirSync(pathDef).filter(file => file.endsWith('.yaml'))
|
||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
if (!fs.existsSync(`${path}${file}`)) {
|
if (!fs.existsSync(`${path}${file}`)) {
|
||||||
|
@ -37,45 +39,45 @@ class Cfg {
|
||||||
/**
|
/**
|
||||||
* 机器人qq号
|
* 机器人qq号
|
||||||
*/
|
*/
|
||||||
get qq () {
|
get qq() {
|
||||||
return Number(this.getConfig('qq').qq)
|
return Number(this.getConfig('qq').qq)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 密码
|
* 密码
|
||||||
*/
|
*/
|
||||||
get pwd () {
|
get pwd() {
|
||||||
return this.getConfig('qq').pwd
|
return this.getConfig('qq').pwd
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* icqq配置
|
* icqq配置
|
||||||
*/
|
*/
|
||||||
get bot () {
|
get bot() {
|
||||||
let bot = this.getConfig('bot')
|
let bot = this.getConfig('bot')
|
||||||
let defbot = this.getdefSet('bot')
|
let defbot = this.getdefSet('bot')
|
||||||
bot = { ...defbot, ...bot }
|
const Config = { ...defbot, ...bot }
|
||||||
bot.platform = this.getConfig('qq').platform
|
Config.platform = this.getConfig('qq').platform
|
||||||
/** 设置data目录,防止pm2运行时目录不对 */
|
/**
|
||||||
bot.data_dir = process.cwd() + '/data/icqq/' + this.qq || ''
|
* 设置data目录,防止pm2运行时目录不对
|
||||||
|
*/
|
||||||
if (!bot.ffmpeg_path) delete bot.ffmpeg_path
|
Config.data_dir = join(process.cwd(), `/data/icqq/${this.qq}`)
|
||||||
if (!bot.ffprobe_path) delete bot.ffprobe_path
|
if (!Config.ffmpeg_path) delete Config.ffmpeg_path
|
||||||
|
if (!Config.ffprobe_path) delete Config.ffprobe_path
|
||||||
return bot
|
return Config
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
get other () {
|
get other() {
|
||||||
return this.getConfig('other')
|
return this.getConfig('other')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
get redis () {
|
get redis() {
|
||||||
return this.getConfig('redis')
|
return this.getConfig('redis')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,25 +98,29 @@ class Cfg {
|
||||||
/**
|
/**
|
||||||
* 主人qq
|
* 主人qq
|
||||||
*/
|
*/
|
||||||
get masterQQ () {
|
get masterQQ() {
|
||||||
let masterQQ = this.getConfig('other').masterQQ || []
|
const masterQQ = this.getConfig('other')?.masterQQ || []
|
||||||
|
|
||||||
if (Array.isArray(masterQQ)) {
|
if (Array.isArray(masterQQ)) {
|
||||||
masterQQ.forEach(qq => { qq = String(qq) })
|
return masterQQ.forEach(qq => { qq = String(qq) })
|
||||||
} else {
|
} else {
|
||||||
masterQQ = [String(masterQQ)]
|
return [String(masterQQ)]
|
||||||
}
|
}
|
||||||
return masterQQ
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_package = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* package.json
|
* package.json
|
||||||
*/
|
*/
|
||||||
get package () {
|
get package() {
|
||||||
if (this._package) return this._package
|
if (this._package) return this._package
|
||||||
|
try {
|
||||||
this._package = JSON.parse(fs.readFileSync('package.json', 'utf8'))
|
const data = fs.readFileSync('package.json', 'utf8')
|
||||||
return this._package
|
this._package = JSON.parse(data)
|
||||||
|
return this._package
|
||||||
|
} catch {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,9 +128,9 @@ class Cfg {
|
||||||
* @param groupId
|
* @param groupId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getGroup (groupId = '') {
|
getGroup(groupId = '') {
|
||||||
let config = this.getConfig('group')
|
const config = this.getConfig('group')
|
||||||
let defCfg = this.getdefSet('group')
|
const defCfg = this.getdefSet('group')
|
||||||
if (config[groupId]) {
|
if (config[groupId]) {
|
||||||
return { ...defCfg.default, ...config.default, ...config[groupId] }
|
return { ...defCfg.default, ...config.default, ...config[groupId] }
|
||||||
}
|
}
|
||||||
|
@ -135,9 +141,9 @@ class Cfg {
|
||||||
* other配置
|
* other配置
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getOther () {
|
getOther() {
|
||||||
let def = this.getdefSet('other')
|
const def = this.getdefSet('other')
|
||||||
let config = this.getConfig('other')
|
const config = this.getConfig('other')
|
||||||
return { ...def, ...config }
|
return { ...def, ...config }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,27 +151,27 @@ class Cfg {
|
||||||
* notice配置
|
* notice配置
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getNotice () {
|
getNotice() {
|
||||||
let def = this.getdefSet('notice')
|
const def = this.getdefSet('notice')
|
||||||
let config = this.getConfig('notice')
|
const config = this.getConfig('notice')
|
||||||
return { ...def, ...config }
|
return { ...def, ...config }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 得到默认配置
|
||||||
* @param name 配置文件名称
|
* @param name 配置文件名称
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getdefSet (name) {
|
getdefSet(name: string) {
|
||||||
return this.getYaml('default_config', name)
|
return this.getYaml('default_config', name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户配置
|
* 得到生成式配置
|
||||||
* @param name
|
* @param name
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
getConfig (name) {
|
getConfig(name: string) {
|
||||||
return this.getYaml('config', name)
|
return this.getYaml('config', name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +180,7 @@ class Cfg {
|
||||||
* @param type 默认跑配置-defSet,用户配置-config
|
* @param type 默认跑配置-defSet,用户配置-config
|
||||||
* @param name 名称
|
* @param name 名称
|
||||||
*/
|
*/
|
||||||
getYaml (type, name) {
|
getYaml(type, name) {
|
||||||
let file = `config/${type}/${name}.yaml`
|
let file = `config/${type}/${name}.yaml`
|
||||||
let key = `${type}.${name}`
|
let key = `${type}.${name}`
|
||||||
if (this.config[key]) return this.config[key]
|
if (this.config[key]) return this.config[key]
|
||||||
|
@ -195,13 +201,11 @@ class Cfg {
|
||||||
* @param type
|
* @param type
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
watch (file, name, type = 'default_config') {
|
watch(file:string, name:string, type = 'default_config') {
|
||||||
let key = `${type}.${name}`
|
const key = `${type}.${name}`
|
||||||
|
|
||||||
if (this.watcher[key]) return
|
if (this.watcher[key]) return
|
||||||
|
|
||||||
const watcher = chokidar.watch(file)
|
const watcher = chokidar.watch(file)
|
||||||
watcher.on('change', path => {
|
watcher.on('change', () => {
|
||||||
delete this.config[key]
|
delete this.config[key]
|
||||||
if (typeof Bot == 'undefined') return
|
if (typeof Bot == 'undefined') return
|
||||||
logger.mark(`[修改配置文件][${type}][${name}]`)
|
logger.mark(`[修改配置文件][${type}][${name}]`)
|
||||||
|
@ -209,7 +213,6 @@ class Cfg {
|
||||||
this[`change_${name}`]()
|
this[`change_${name}`]()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.watcher[key] = watcher
|
this.watcher[key] = watcher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,21 +220,19 @@ class Cfg {
|
||||||
*
|
*
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
change_qq () {
|
change_qq() {
|
||||||
if (process.argv.includes('login') || !this.qq) return
|
if (process.argv.includes('login') || !this.qq) return
|
||||||
logger.info('修改机器人QQ或密码,请手动重启')
|
logger.info('修改机器人QQ或密码,请手动重启')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 修改日志等级
|
||||||
*/
|
*/
|
||||||
async change_bot () {
|
async change_bot() {
|
||||||
/** 修改日志等级 */
|
const log = await import('./log.js')
|
||||||
let log = await import('./log.js')
|
|
||||||
log.default()
|
log.default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -239,4 +240,4 @@ class Cfg {
|
||||||
*
|
*
|
||||||
* ***
|
* ***
|
||||||
*/
|
*/
|
||||||
export default new Cfg()
|
export default new Cfg()
|
|
@ -1,100 +1,170 @@
|
||||||
|
import fs, { promises } from "node:fs"
|
||||||
|
import yaml from "yaml"
|
||||||
|
import { BOT_NAME } from "./system.js"
|
||||||
import createQQ from "./qq.js"
|
import createQQ from "./qq.js"
|
||||||
import setLog from "./log.js"
|
import setLog from "./log.js"
|
||||||
import redisInit from "./redis.js"
|
import redisInit from "./redis.js"
|
||||||
import { checkRun } from "./check.js"
|
import { checkRun } from "./check.js"
|
||||||
import fs from "node:fs"
|
import { join } from "node:path"
|
||||||
import yaml from "yaml"
|
|
||||||
|
|
||||||
/** 设置标题 */
|
|
||||||
process.title = "Miao-Yunzai"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
async function UpdateTitle() {
|
export async function UpdateTitle() {
|
||||||
// 添加一些多余的标题内容
|
/**
|
||||||
let title = "Miao-Yunzai"
|
* 添加一些多余的标题内容
|
||||||
let qq = await fs.promises.readFile("./config/config/qq.yaml", 'utf-8').then(yaml.parse).catch(() => null)
|
*/
|
||||||
|
let title = BOT_NAME
|
||||||
|
|
||||||
|
//
|
||||||
|
const qq = await promises.readFile("./config/config/qq.yaml", 'utf-8').then(yaml.parse).catch(() => null)
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
if (qq) {
|
if (qq) {
|
||||||
title += `@${qq.qq || ""}`
|
title += `@${qq.qq || ""}`
|
||||||
switch (qq.platform) {
|
switch (qq.platform) {
|
||||||
case 1:
|
case 1:{
|
||||||
title += " 安卓手机"
|
title += " 安卓手机"
|
||||||
break
|
break
|
||||||
case 2:
|
}
|
||||||
|
case 2:{
|
||||||
title += " aPad"
|
title += " aPad"
|
||||||
break
|
break
|
||||||
case 3:
|
}
|
||||||
|
case 3:{
|
||||||
title += " 安卓手表"
|
title += " 安卓手表"
|
||||||
break
|
break
|
||||||
case 4:
|
}
|
||||||
|
case 4:{
|
||||||
title += " MacOS"
|
title += " MacOS"
|
||||||
break
|
break
|
||||||
case 5:
|
}
|
||||||
|
case 5:{
|
||||||
title += " iPad"
|
title += " iPad"
|
||||||
break
|
break
|
||||||
case 6:
|
}
|
||||||
|
case 6:{
|
||||||
title += " Tim"
|
title += " Tim"
|
||||||
break
|
break
|
||||||
default:
|
}
|
||||||
|
default:{
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** 设置标题 */
|
|
||||||
|
/**
|
||||||
|
* 设置标题
|
||||||
|
*/
|
||||||
process.title = title
|
process.title = title
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置时区 */
|
/**
|
||||||
|
* 初始化事件
|
||||||
|
*/
|
||||||
|
export async function checkInit() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查node_modules
|
||||||
|
*/
|
||||||
|
if (!fs.existsSync(join(process.cwd(), "./node_modules"))) {
|
||||||
|
console.log("未安装依赖。。。。")
|
||||||
|
console.log("请先运行命令:pnpm install -P 安装依赖")
|
||||||
|
process.exit()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查node_modules/icqq
|
||||||
|
*/
|
||||||
|
if(!fs.existsSync(join(process.cwd(), "./node_modules/icqq"))){
|
||||||
|
console.log("未安装icqq。。。。")
|
||||||
|
console.log("请先运行命令:pnpm install -P 安装依赖")
|
||||||
|
process.exit()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查qq.yaml
|
||||||
|
*/
|
||||||
|
await createQQ()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志设置
|
||||||
|
*/
|
||||||
|
setLog()
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
logger.mark(`${BOT_NAME} 启动中...`)
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
await redisInit()
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
await checkRun()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新标题
|
||||||
|
*/
|
||||||
|
await UpdateTitle()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置标题
|
||||||
|
*/
|
||||||
|
process.title = BOT_NAME
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置时区
|
||||||
|
*/
|
||||||
process.env.TZ = "Asia/Shanghai"
|
process.env.TZ = "Asia/Shanghai"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
process.on("SIGHUP", () => process.exit())
|
process.on("SIGHUP", () => process.exit())
|
||||||
|
|
||||||
/** 捕获未处理的错误 */
|
/**
|
||||||
|
* 捕获未处理的错误
|
||||||
|
*/
|
||||||
process.on("uncaughtException", error => {
|
process.on("uncaughtException", error => {
|
||||||
if (typeof logger == "undefined") console.log(error)
|
if (typeof logger == "undefined") console.log(error)
|
||||||
else logger.error(error)
|
else logger.error(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 捕获未处理的Promise错误 */
|
|
||||||
process.on("unhandledRejection", (error, promise) => {
|
/**
|
||||||
|
* 捕获未处理的Promise错误
|
||||||
|
*/
|
||||||
|
process.on("unhandledRejection", (error) => {
|
||||||
if (typeof logger == "undefined") console.log(error)
|
if (typeof logger == "undefined") console.log(error)
|
||||||
else logger.error(error)
|
else logger.error(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 退出事件 */
|
/**
|
||||||
process.on("exit", async code => {
|
* 退出事件
|
||||||
if (typeof redis != "undefined" && typeof test == "undefined")
|
*/
|
||||||
|
process.on("exit", async () => {
|
||||||
|
if (typeof redis != "undefined") {
|
||||||
await redis.save()
|
await redis.save()
|
||||||
|
}
|
||||||
if (typeof logger == "undefined")
|
if (typeof logger == "undefined") {
|
||||||
console.log("Miao-Yunzai 已停止运行")
|
console.log(`${BOT_NAME} 已停止运行`)
|
||||||
else
|
}
|
||||||
logger.mark(logger.magenta("Miao-Yunzai 已停止运行"))
|
else {
|
||||||
|
logger.mark(logger.magenta(`${BOT_NAME} 已停止运行`))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await checkInit()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化事件
|
* 初始化
|
||||||
*/
|
*/
|
||||||
async function checkInit() {
|
await checkInit()
|
||||||
/** 检查node_modules */
|
|
||||||
if (!fs.existsSync("./node_modules") || !fs.existsSync("./node_modules/icqq")) {
|
|
||||||
console.log("请先运行命令:pnpm install -P 安装依赖")
|
|
||||||
process.exit()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 检查qq.yaml */
|
|
||||||
await createQQ()
|
|
||||||
|
|
||||||
/** 日志设置 */
|
|
||||||
setLog()
|
|
||||||
|
|
||||||
logger.mark("Miao-Yunzai 启动中...")
|
|
||||||
|
|
||||||
await redisInit()
|
|
||||||
|
|
||||||
await checkRun()
|
|
||||||
|
|
||||||
//** 更新标题 */
|
|
||||||
await UpdateTitle()
|
|
||||||
}
|
|
|
@ -1,8 +1,9 @@
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import inquirer from 'inquirer'
|
import inquirer from 'inquirer'
|
||||||
|
import chalk from 'chalk'
|
||||||
|
import { BOT_NAME, CONFIG_DEFAULT_PATH, CONFIG_INIT_PATH } from './system.js'
|
||||||
import cfg from './config.js'
|
import cfg from './config.js'
|
||||||
import { sleep } from '../utils/common.js'
|
import { sleep } from '../utils/common.js'
|
||||||
import chalk from 'chalk'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建qq配置文件 `config/bot/qq.yaml`
|
* 创建qq配置文件 `config/bot/qq.yaml`
|
||||||
|
@ -20,11 +21,10 @@ export default async function createQQ() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
console.log(`欢迎使用${chalk.green('Miao-Yunzai v' + cfg.package.version)}\n请按提示输入完成QQ配置`)
|
console.log(`欢迎使用${chalk.green(`${BOT_NAME} v` + cfg.package.version)}\n请按提示输入完成QQ配置`)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,8 +99,11 @@ export default async function createQQ() {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
let file = './config/config/'
|
const file = `./${CONFIG_INIT_PATH}`
|
||||||
let fileDef = './config/default_config/'
|
|
||||||
|
const fileDef = `./${CONFIG_DEFAULT_PATH}`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let qq = fs.readFileSync(`${fileDef}qq.yaml`, 'utf8')
|
let qq = fs.readFileSync(`${fileDef}qq.yaml`, 'utf8')
|
||||||
|
|
||||||
|
@ -136,4 +139,4 @@ export default async function createQQ() {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
await sleep(2000)
|
await sleep(2000)
|
||||||
}
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
// 机器人名称
|
||||||
|
export const BOT_NAME = 'Miao-Yunzai'
|
||||||
|
// 生成式配置
|
||||||
|
export const CONFIG_INIT_PATH = 'config/config/'
|
||||||
|
// 默认配置
|
||||||
|
export const CONFIG_DEFAULT_PATH = 'config/default_config/'
|
||||||
|
// redis root
|
||||||
|
export const REDIS_ROOT_KEY = 'Yz:cache:'
|
|
@ -0,0 +1,126 @@
|
||||||
|
/**
|
||||||
|
* ************
|
||||||
|
* 关于bot处理,属于core
|
||||||
|
* ************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送私聊消息,仅给好友发送
|
||||||
|
* @param userId qq号
|
||||||
|
* @param msg 消息
|
||||||
|
* @param uin 指定bot发送,默认为Bot
|
||||||
|
*/
|
||||||
|
export async function relpyPrivate(userId, msg, uin = Bot.uin) {
|
||||||
|
userId = Number(userId)
|
||||||
|
let friend = Bot.fl.get(userId)
|
||||||
|
if (friend) {
|
||||||
|
logger.mark(`发送好友消息[${friend.nickname}](${userId})`)
|
||||||
|
return await Bot[uin]
|
||||||
|
.pickUser(userId)
|
||||||
|
.sendMsg(msg)
|
||||||
|
.catch(err => {
|
||||||
|
logger.mark(err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作转发消息
|
||||||
|
* @param e 消息事件
|
||||||
|
* @param msg 消息数组
|
||||||
|
* @param dec 转发描述
|
||||||
|
* @param msgsscr 转发信息是否伪装
|
||||||
|
*/
|
||||||
|
export async function makeForwardMsg(
|
||||||
|
e: any,
|
||||||
|
msg: any[] | string = [],
|
||||||
|
dec: string = '',
|
||||||
|
msgsscr = false
|
||||||
|
) {
|
||||||
|
// 不是数组
|
||||||
|
if (!Array.isArray(msg)) msg = [msg]
|
||||||
|
|
||||||
|
//
|
||||||
|
let name = msgsscr ? e.sender.card || e.user_id : Bot.nickname
|
||||||
|
|
||||||
|
//
|
||||||
|
const Id = msgsscr ? e.user_id : Bot.uin
|
||||||
|
|
||||||
|
// 是群聊
|
||||||
|
if (e.isGroup) {
|
||||||
|
try {
|
||||||
|
const Info = await e.bot.getGroupMemberInfo(e.group_id, Id)
|
||||||
|
name = Info.card || Info.nickname
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let forwardMsg:
|
||||||
|
| {
|
||||||
|
user_id: number
|
||||||
|
nickname: string
|
||||||
|
message: any
|
||||||
|
}[]
|
||||||
|
| {
|
||||||
|
data: any
|
||||||
|
} = []
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
for (const message of msg) {
|
||||||
|
if (!message) continue
|
||||||
|
forwardMsg.push({
|
||||||
|
user_id: Id,
|
||||||
|
nickname: name,
|
||||||
|
message: message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作转发内容
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (e?.group?.makeForwardMsg) {
|
||||||
|
// ?
|
||||||
|
forwardMsg = await e.group.makeForwardMsg(forwardMsg)
|
||||||
|
} else if (e?.friend?.makeForwardMsg) {
|
||||||
|
// ?
|
||||||
|
forwardMsg = await e.friend.makeForwardMsg(forwardMsg)
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
return msg.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (dec) {
|
||||||
|
/**
|
||||||
|
* 处理描述
|
||||||
|
*/
|
||||||
|
if (typeof forwardMsg.data === 'object') {
|
||||||
|
const Detail = forwardMsg.data?.meta?.detail
|
||||||
|
if (Detail) {
|
||||||
|
Detail.news = [{ text: dec }]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
forwardMsg.data = forwardMsg.data
|
||||||
|
.replace(/\n/g, '')
|
||||||
|
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
|
||||||
|
.replace(/___+/, `<title color="#777777" size="26">${dec}</title>`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return forwardMsg
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
import EventListener from '../listener/listener.js'
|
import EventListener from '../listener/listener.js'
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
import cfg from '../../config/config.js'
|
import cfg from '../../config/config.js'
|
||||||
|
import { BOT_NAME } from '../../config/system.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听下线事件
|
* 监听下线事件
|
||||||
|
@ -25,7 +26,7 @@ export default class offlineEvent extends EventListener {
|
||||||
async execute (e) {
|
async execute (e) {
|
||||||
logger.mark('掉线了')
|
logger.mark('掉线了')
|
||||||
let config = cfg.getConfig('notice')
|
let config = cfg.getConfig('notice')
|
||||||
let title = `Miao-Yunzai(${Bot.nickname})已离线,请关注`
|
let title = `${BOT_NAME}(${Bot.nickname})已离线,请关注`
|
||||||
if (config.iyuu) {
|
if (config.iyuu) {
|
||||||
await fetch(`https://iyuu.cn/${config.iyuu}.send?text=${title}&desp=${e.message}`)
|
await fetch(`https://iyuu.cn/${config.iyuu}.send?text=${title}&desp=${e.message}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import EventListener from '../listener/listener.js'
|
import EventListener from '../listener/listener.js'
|
||||||
import cfg from '../../config/config.js'
|
import cfg from '../../config/config.js'
|
||||||
import { relpyPrivate } from '../../utils/common.js'
|
import { relpyPrivate } from '../../core/common.js'
|
||||||
|
import { BOT_NAME } from '../../config/system.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听上线事件
|
* 监听上线事件
|
||||||
|
@ -27,7 +28,7 @@ export default class onlineEvent extends EventListener {
|
||||||
*/
|
*/
|
||||||
async execute(e) {
|
async execute(e) {
|
||||||
logger.mark('----^_^----')
|
logger.mark('----^_^----')
|
||||||
logger.mark(logger.green(`Miao-Yunzai 上线成功 版本v${cfg.package.version}`))
|
logger.mark(logger.green(`${BOT_NAME} 上线成功 版本v${cfg.package.version}`))
|
||||||
logger.mark(logger.green('https://github.com/yoimiya-kokomi/Miao-Yunzai'))
|
logger.mark(logger.green('https://github.com/yoimiya-kokomi/Miao-Yunzai'))
|
||||||
// logger.mark('-----------')
|
// logger.mark('-----------')
|
||||||
/** 加载插件 */
|
/** 加载插件 */
|
||||||
|
@ -48,7 +49,7 @@ export default class onlineEvent extends EventListener {
|
||||||
|
|
||||||
if (await redis.get(key)) return
|
if (await redis.get(key)) return
|
||||||
|
|
||||||
let msg = `欢迎使用【Miao-Yunzai v${cfg.package.version}】\n【#帮助】查看指令说明\n【#状态】查看运行状态\n【#日志】查看运行日志\n【#更新】拉取 Github 更新\n【#全部更新】更新全部插件\n【#更新日志】查看更新日志\n【#重启】重新启动\n【#配置ck】配置公共查询 Cookie`
|
let msg = `欢迎使用【${BOT_NAME} v${cfg.package.version}】\n【#帮助】查看指令说明\n【#状态】查看运行状态\n【#日志】查看运行日志\n【#更新】拉取 Github 更新\n【#全部更新】更新全部插件\n【#更新日志】查看更新日志\n【#重启】重新启动\n【#配置ck】配置公共查询 Cookie`
|
||||||
|
|
||||||
redis.set(key, '1', { EX: cfg.bot.online_msg_exp })
|
redis.set(key, '1', { EX: cfg.bot.online_msg_exp })
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import BaseModel from './BaseModel.js'
|
import BaseModel from './BaseModel.js'
|
||||||
import MysUtil from './MysUtil.js'
|
import MysUtil from './MysUtil.js'
|
||||||
|
import { REDIS_ROOT_KEY } from '../config/system.js'
|
||||||
|
|
||||||
|
//
|
||||||
const servs = ['mys', 'hoyolab']
|
const servs = ['mys', 'hoyolab']
|
||||||
// 超时时间不必精确,直接定24小时即可
|
// 超时时间不必精确,直接定24小时即可
|
||||||
const EX = 3600 * 24
|
const EX = 3600 * 24
|
||||||
const redisKeyRoot = 'Yz:cache:'
|
//
|
||||||
|
const redisKeyRoot = REDIS_ROOT_KEY
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ************
|
* ************
|
||||||
|
|
|
@ -62,7 +62,7 @@ export default class MysUser extends BaseModel {
|
||||||
constructor(ltuid) {
|
constructor(ltuid) {
|
||||||
super()
|
super()
|
||||||
if (!ltuid) {
|
if (!ltuid) {
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
// 检查实例缓存
|
// 检查实例缓存
|
||||||
let self = this._getThis('mys', ltuid)
|
let self = this._getThis('mys', ltuid)
|
||||||
|
@ -520,7 +520,7 @@ export default class MysUser extends BaseModel {
|
||||||
* 设置ck数据
|
* 设置ck数据
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
setCkData(data = {}) {
|
setCkData(data: { ck: string; type: string; device: string; uids?: any }) {
|
||||||
this.ck = data.ck || this.ck || ''
|
this.ck = data.ck || this.ck || ''
|
||||||
this.type = data.type || this.type || 'mys'
|
this.type = data.type || this.type || 'mys'
|
||||||
this.device = data.device || this.device || MysUtil.getDeviceGuid()
|
this.device = data.device || this.device || MysUtil.getDeviceGuid()
|
||||||
|
|
|
@ -425,15 +425,13 @@ export default class NoteUser extends BaseModel {
|
||||||
return await this.delMysUser(ltuid)
|
return await this.delMysUser(ltuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
mysUsers = []
|
|
||||||
|
|
||||||
_map = null
|
_map = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param mysUser
|
* @param mysUser
|
||||||
*/
|
*/
|
||||||
async delMysUser(mysUser = '') {
|
async delMysUser(mysUser: any = '') {
|
||||||
let ltuid = mysUser.ltuid || mysUser
|
let ltuid = mysUser.ltuid || mysUser
|
||||||
if (ltuid && this.mysUsers[ltuid]) {
|
if (ltuid && this.mysUsers[ltuid]) {
|
||||||
let mys = this.mysUsers[ltuid]
|
let mys = this.mysUsers[ltuid]
|
||||||
|
@ -484,7 +482,7 @@ export default class NoteUser extends BaseModel {
|
||||||
// TODO: 若checkRet中返回了不同的uid,进行CK保存更新
|
// TODO: 若checkRet中返回了不同的uid,进行CK保存更新
|
||||||
// 失效
|
// 失效
|
||||||
let mysUser = await MysUser.create(ck)
|
let mysUser = await MysUser.create(ck)
|
||||||
if (mysUser) {
|
if (mysUser && checkRet) {
|
||||||
let status = checkRet.status
|
let status = checkRet.status
|
||||||
if (status === 0 || status === 1) {
|
if (status === 0 || status === 1) {
|
||||||
// status为1时无法查询天赋,但仍可查询角色,保留CK
|
// status为1时无法查询天赋,但仍可查询角色,保留CK
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default class apiTool {
|
||||||
* @param {区服} server
|
* @param {区服} server
|
||||||
* @param {是否为星穹铁道或其他游戏? type(bool or string)} isSr
|
* @param {是否为星穹铁道或其他游戏? type(bool or string)} isSr
|
||||||
*/
|
*/
|
||||||
constructor(uid: string | null, server, isSr: boolean = false) {
|
constructor(uid: string | null, server: string, isSr: boolean = false) {
|
||||||
uid && (this.uid = uid)
|
uid && (this.uid = uid)
|
||||||
typeof isSr != 'undefined' && (this.uid = uid)
|
typeof isSr != 'undefined' && (this.uid = uid)
|
||||||
server && (this.server = server)
|
server && (this.server = server)
|
||||||
|
|
|
@ -261,6 +261,10 @@ class GsCfg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nameID = new Map()
|
||||||
|
|
||||||
|
sr_nameID = new Map()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 仅供内部调用
|
* 仅供内部调用
|
||||||
* @returns
|
* @returns
|
||||||
|
@ -270,6 +274,7 @@ class GsCfg {
|
||||||
|
|
||||||
this.nameID = new Map()
|
this.nameID = new Map()
|
||||||
this.sr_nameID = new Map()
|
this.sr_nameID = new Map()
|
||||||
|
|
||||||
let nameArr = this.getdefSet('role', 'name')
|
let nameArr = this.getdefSet('role', 'name')
|
||||||
let sr_nameArr = this.getdefSet('role', 'sr_name')
|
let sr_nameArr = this.getdefSet('role', 'sr_name')
|
||||||
let nameArrUser = this.getConfig('role', 'name')
|
let nameArrUser = this.getConfig('role', 'name')
|
||||||
|
@ -303,7 +308,7 @@ class GsCfg {
|
||||||
* @param isSr
|
* @param isSr
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
_roleNameToID(keyword, isSr) {
|
_roleNameToID(keyword, isSr?: boolean) {
|
||||||
if (isSr) this.isSr = isSr
|
if (isSr) this.isSr = isSr
|
||||||
if (!isNaN(keyword)) keyword = Number(keyword)
|
if (!isNaN(keyword)) keyword = Number(keyword)
|
||||||
this._getAbbr()
|
this._getAbbr()
|
||||||
|
|
|
@ -3,8 +3,28 @@ import fetch from 'node-fetch'
|
||||||
import cfg from '../config/config.js'
|
import cfg from '../config/config.js'
|
||||||
import apiTool from './apiTool.js'
|
import apiTool from './apiTool.js'
|
||||||
|
|
||||||
let HttpsProxyAgent = ''
|
let HttpsProxyAgent = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
export default class MysApi {
|
export default class MysApi {
|
||||||
|
uid = null
|
||||||
|
cookie = null
|
||||||
|
isSr = null
|
||||||
|
server = null
|
||||||
|
apiTool = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5分钟缓存
|
||||||
|
*/
|
||||||
|
cacheCd = 300
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
_device = null
|
||||||
|
option = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uid 游戏uid
|
* @param uid 游戏uid
|
||||||
* @param cookie 米游社cookie
|
* @param cookie 米游社cookie
|
||||||
|
@ -278,17 +298,14 @@ export default class MysApi {
|
||||||
let proxyAddress = cfg.bot.proxyAddress
|
let proxyAddress = cfg.bot.proxyAddress
|
||||||
if (!proxyAddress) return null
|
if (!proxyAddress) return null
|
||||||
if (proxyAddress === 'http://0.0.0.0:0') return null
|
if (proxyAddress === 'http://0.0.0.0:0') return null
|
||||||
|
|
||||||
if (!/os_|official/.test(this.server)) return null
|
if (!/os_|official/.test(this.server)) return null
|
||||||
|
|
||||||
if (HttpsProxyAgent === '') {
|
//
|
||||||
HttpsProxyAgent = await import('https-proxy-agent').catch(err => {
|
if (HttpsProxyAgent == null) {
|
||||||
|
const data = await import('https-proxy-agent').catch(err => {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
})
|
})
|
||||||
|
HttpsProxyAgent = data ? data.HttpsProxyAgent : undefined
|
||||||
HttpsProxyAgent = HttpsProxyAgent
|
|
||||||
? HttpsProxyAgent.HttpsProxyAgent
|
|
||||||
: undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HttpsProxyAgent) {
|
if (HttpsProxyAgent) {
|
||||||
|
|
|
@ -4,26 +4,6 @@ import fetch from 'node-fetch'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送私聊消息,仅给好友发送
|
|
||||||
* @param userId qq号
|
|
||||||
* @param msg 消息
|
|
||||||
* @param uin 指定bot发送,默认为Bot
|
|
||||||
*/
|
|
||||||
export async function relpyPrivate(userId, msg, uin = Bot.uin) {
|
|
||||||
userId = Number(userId)
|
|
||||||
let friend = Bot.fl.get(userId)
|
|
||||||
if (friend) {
|
|
||||||
logger.mark(`发送好友消息[${friend.nickname}](${userId})`)
|
|
||||||
return await Bot[uin]
|
|
||||||
.pickUser(userId)
|
|
||||||
.sendMsg(msg)
|
|
||||||
.catch(err => {
|
|
||||||
logger.mark(err)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 休眠函数
|
* 休眠函数
|
||||||
* @param ms 毫秒
|
* @param ms 毫秒
|
||||||
|
@ -67,104 +47,3 @@ export function mkdirs(dirname: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 制作转发消息
|
|
||||||
* @param e 消息事件
|
|
||||||
* @param msg 消息数组
|
|
||||||
* @param dec 转发描述
|
|
||||||
* @param msgsscr 转发信息是否伪装
|
|
||||||
*/
|
|
||||||
export async function makeForwardMsg(
|
|
||||||
e: any,
|
|
||||||
msg: any[] | string = [],
|
|
||||||
dec: string = '',
|
|
||||||
msgsscr = false
|
|
||||||
) {
|
|
||||||
// 不是数组
|
|
||||||
if (!Array.isArray(msg)) msg = [msg]
|
|
||||||
|
|
||||||
//
|
|
||||||
let name = msgsscr ? e.sender.card || e.user_id : Bot.nickname
|
|
||||||
|
|
||||||
//
|
|
||||||
const Id = msgsscr ? e.user_id : Bot.uin
|
|
||||||
|
|
||||||
// 是群聊
|
|
||||||
if (e.isGroup) {
|
|
||||||
try {
|
|
||||||
const Info = await e.bot.getGroupMemberInfo(e.group_id, Id)
|
|
||||||
name = Info.card || Info.nickname
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let forwardMsg:
|
|
||||||
| {
|
|
||||||
user_id: number
|
|
||||||
nickname: string
|
|
||||||
message: any
|
|
||||||
}[]
|
|
||||||
| {
|
|
||||||
data: any
|
|
||||||
} = []
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
for (const message of msg) {
|
|
||||||
if (!message) continue
|
|
||||||
forwardMsg.push({
|
|
||||||
user_id: Id,
|
|
||||||
nickname: name,
|
|
||||||
message: message
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 制作转发内容
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (e?.group?.makeForwardMsg) {
|
|
||||||
// ?
|
|
||||||
forwardMsg = await e.group.makeForwardMsg(forwardMsg)
|
|
||||||
} else if (e?.friend?.makeForwardMsg) {
|
|
||||||
// ?
|
|
||||||
forwardMsg = await e.friend.makeForwardMsg(forwardMsg)
|
|
||||||
} else {
|
|
||||||
//
|
|
||||||
return msg.join('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (dec) {
|
|
||||||
/**
|
|
||||||
* 处理描述
|
|
||||||
*/
|
|
||||||
if (typeof forwardMsg.data === 'object') {
|
|
||||||
const Detail = forwardMsg.data?.meta?.detail
|
|
||||||
if (Detail) {
|
|
||||||
Detail.news = [{ text: dec }]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
forwardMsg.data = forwardMsg.data
|
|
||||||
.replace(/\n/g, '')
|
|
||||||
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
|
|
||||||
.replace(/___+/, `<title color="#777777" size="26">${dec}</title>`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return forwardMsg
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue