fix: 修复危险声明&调整工具类&补充部分类型

This commit is contained in:
ningmengchongshui 2024-06-09 18:21:33 +08:00
parent 6ff3bf46f8
commit fb84dfa73a
21 changed files with 208 additions and 125 deletions

View File

@ -23,6 +23,8 @@
"art-template": "^4.13.2",
"chalk": "^5.3.0",
"chokidar": "^3.6.0",
"express": "^4.19.2",
"express-art-template": "^1.0.1",
"https-proxy-agent": "7.0.4",
"icqq": "^0.6.10",
"image-size": "^1.1.1",
@ -36,35 +38,35 @@
"oicq": "^2.3.1",
"pm2": "^5.3.1",
"puppeteer": "*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"redis": "^4.6.13",
"sequelize": "^6.37.1",
"sqlite3": "5.1.6",
"yaml": "^2.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"express": "^4.19.2",
"express-art-template": "^1.0.1"
"yaml": "^2.4.1"
},
"devDependencies": {
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-multi-entry": "^6.0.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.3",
"@types/inquirer": "^9.0.7",
"@types/lodash": "^4.14.200",
"@types/node": "^20.8.5",
"@types/node-schedule": "^2.1.7",
"@types/react-dom": "^18.2.22",
"@types/redis": "^4.0.11",
"@types/ws": "^8.5.7",
"eslint": "^8.57.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-multi-entry": "^6.0.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.3",
"@types/react-dom": "^18.2.22",
"@types/lodash": "^4.14.200",
"@types/node": "^20.8.5",
"@types/redis": "^4.0.11",
"@types/ws": "^8.5.7",
"nodemon": "^3.0.1",
"prettier": "^3.0.3",
"rollup": "^4.16.4",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"prettier": "^3.0.3"
"typescript": "^5.0.4"
},
"imports": {
"#miao": "./plugins/miao-plugin/components/index.js",

View File

@ -3,11 +3,11 @@
*
* **********
*/
import './lib/config/init.js'
import './config/init.js'
/**
*
*/
import cfg from './lib/config/config.js'
import cfg from './config/config.js'
/**
*
*/

View File

@ -1,16 +1,17 @@
import fs from 'fs'
import inquirer from 'inquirer'
import cfg from './config.js'
import common from '../common/common.js'
import { sleep } from '../utils/common.js'
import chalk from 'chalk'
/**
* qq配置文件 `config/bot/qq.yaml`
* Git Bash npm命令会无法选择列表
* @returns
*/
export default async function createQQ () {
export default async function createQQ() {
/** 跳过登录ICQQ */
if(cfg.bot.skip_login) return
if (cfg.bot.skip_login) return
/**
*
@ -24,8 +25,8 @@ export default async function createQQ () {
*
*/
console.log(`欢迎使用${chalk.green('Miao-Yunzai v' + cfg.package.version)}\n请按提示输入完成QQ配置`)
/**
*
*/
@ -34,7 +35,7 @@ export default async function createQQ () {
type: 'Input',
message: '请输入机器人QQ号(建议用小号)',
name: 'QQ',
validate (value) {
validate(value) {
if (/^[1-9][0-9]{4,14}$/.test(value)) return true
return '请输入正确的QQ号'
}
@ -52,13 +53,13 @@ export default async function createQQ () {
choices: ['Tim', 'iPad', '安卓手机', '安卓手表', 'MacOS', 'aPad'],
filter: (val) => {
switch (val) {
case 'Tim':return 6
case 'iPad':return 5
case 'MacOS':return 4
case '安卓手机':return 1
case '安卓手表':return 3
case 'aPad':return 2
default:return 6
case 'Tim': return 6
case 'iPad': return 5
case 'MacOS': return 4
case '安卓手机': return 1
case '安卓手表': return 3
case 'aPad': return 2
default: return 6
}
}
}
@ -134,5 +135,5 @@ export default async function createQQ () {
/**
*
*/
await common.sleep(2000)
await sleep(2000)
}

View File

@ -1,5 +1,5 @@
import cfg from "./config.js"
import common from "../common/common.js"
import { sleep } from "../utils/common.js"
import { createClient } from "redis"
import { exec } from "node:child_process"
@ -26,7 +26,7 @@ export default async function redisInit() {
const cmd = "redis-server --save 900 1 --save 300 10 --daemonize yes" + await aarch64()
logger.info("正在启动 Redis...")
await execSync(cmd)
await common.sleep(1000)
await sleep(1000)
try {
client = createClient({ url: redisUrl })
@ -55,7 +55,7 @@ export default async function redisInit() {
*
* @returns
*/
async function aarch64() {
export async function aarch64() {
if (process.platform == "win32")
return ""
/** 判断arch */
@ -78,7 +78,7 @@ async function aarch64() {
* @param cmd
* @returns
*/
function execSync (cmd) {
export function execSync(cmd) {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
resolve({ error, stdout, stderr })

View File

@ -1,5 +1,5 @@
import common from '../lib/common/common.js'
import cfg from '../lib/config/config.js'
import * as common from '../utils/common.js'
import cfg from '../config/config.js'
import Handler from '../lib/plugins/handler.js'
import {

View File

@ -1,5 +1,5 @@
import EventListener from '../listener/listener.js'
import common from '../common/common.js'
import { sleep } from '../../utils/common.js'
import inquirer from 'inquirer'
import lodash from 'lodash'
import fetch from 'node-fetch'
@ -17,7 +17,7 @@ export default class loginEvent extends EventListener {
/**
*
*/
constructor () {
constructor() {
/**
*
@ -33,13 +33,13 @@ export default class loginEvent extends EventListener {
*
* @param event
*/
async execute (event) {}
async execute(event) { }
/**
* ip下进行
* @param event
*/
async qrcode (event) {
async qrcode(event) {
logger.mark(`请使用登录当前QQ的手机${logger.green('扫码')}完成登录,如果显示二维码过期,可以按${logger.green('回车键Enter')}刷新,重新输入密码请执行命令:${logger.green('node app login')}`)
// logger.info('等待扫码中...')
@ -53,7 +53,7 @@ export default class loginEvent extends EventListener {
console.log('\n')
logger.info(logger.green('扫码成功,开始登录...'))
console.log('\n')
await common.sleep(1000)
await sleep(1000)
this.client.qrcodeLogin()
clearInterval(interval)
}
@ -69,7 +69,7 @@ export default class loginEvent extends EventListener {
if (!inSlider) {
clearInterval(interval)
console.log(' 重新刷新二维码...\n\n')
await common.sleep(1000)
await sleep(1000)
this.client.fetchQrcode()
}
})
@ -80,7 +80,7 @@ export default class loginEvent extends EventListener {
* 使PC浏览器已经无效
* @param event
*/
async slider (event) {
async slider(event) {
inSlider = true
console.log(`\n\n------------------${logger.green('↓↓滑动验证链接↓↓')}----------------------\n`)
console.log(logger.green(event.url))
@ -98,7 +98,7 @@ export default class loginEvent extends EventListener {
}
])
await common.sleep(200)
await sleep(200)
let ticket
if (ret.type == '0.自动获取ticket') {
@ -116,7 +116,7 @@ export default class loginEvent extends EventListener {
type: 'Input',
message: '请输入ticket:',
name: 'ticket',
validate (value) {
validate(value) {
if (!value) return 'ticket不能为空'
if (value.toLowerCase() == 'ticket') return '请输入获取的ticket'
if (value == event.url) return '请勿输入滑动验证链接'
@ -134,7 +134,7 @@ export default class loginEvent extends EventListener {
* @param url
* @returns
*/
async getTicket (url) {
async getTicket(url) {
let req = `https://hlhs-nb.cn/captcha/slider?key=${Bot.uin}`
await fetch(req, {
method: 'POST',
@ -151,7 +151,7 @@ export default class loginEvent extends EventListener {
})
res = await res.json()
if (res.data?.ticket) return res.data.ticket
await common.sleep(3000)
await sleep(3000)
}
}
@ -160,7 +160,7 @@ export default class loginEvent extends EventListener {
* @param url
* @returns
*/
async requestCode (url) {
async requestCode(url) {
let txhelper = {
url: url.replace('ssl.captcha.qq.com', 'txhelper.glitch.me')
}
@ -176,7 +176,7 @@ export default class loginEvent extends EventListener {
console.log(`\n请打开滑动验证app输入请求码${logger.green('【' + txhelper.code + '】')},然后完成滑动验证\n`)
await common.sleep(200)
await sleep(200)
await inquirer.prompt({
type: 'Input',
message: '验证完成后按回车确认,等待在操作中...',
@ -202,7 +202,7 @@ export default class loginEvent extends EventListener {
*
* @param event
*/
async device (event) {
async device(event) {
global.inputTicket = false
console.log(`\n\n------------------${logger.green('↓↓设备锁验证↓↓')}----------------------\n`)
const ret = await inquirer.prompt([
@ -214,7 +214,7 @@ export default class loginEvent extends EventListener {
}
])
await common.sleep(200)
await sleep(200)
if (ret.type == '1.网页扫码验证') {
console.log('\n' + logger.green(event.url) + '\n')
@ -224,7 +224,7 @@ export default class loginEvent extends EventListener {
} else {
console.log('\n')
this.client.sendSmsCode()
await common.sleep(200)
await sleep(200)
logger.info(`验证码已发送:${event.phone}\n`)
let res = await inquirer.prompt({ type: 'Input', message: '请输入短信验证码:', name: 'sms' })
await this.client.submitSmsCode(res.sms)
@ -235,7 +235,7 @@ export default class loginEvent extends EventListener {
*
* @param event
*/
error (event) {
error(event) {
if (Number(event.code) === 1) logger.error('QQ密码错误运行命令重新登录node app login')
if (global.inputTicket && event.code == 237) {
logger.error(`${logger.red('ticket')}输入错误或者已失效,已停止运行,请重新登录验证`)

View File

@ -1,6 +1,6 @@
import EventListener from '../listener/listener.js'
import fetch from 'node-fetch'
import cfg from '../config/config.js'
import cfg from '../../config/config.js'
/**
* 线

View File

@ -1,6 +1,6 @@
import EventListener from '../listener/listener.js'
import cfg from '../config/config.js'
import common from '../common/common.js'
import cfg from '../../config/config.js'
import { relpyPrivate } from '../../utils/common.js'
/**
* 线
@ -10,8 +10,8 @@ export default class onlineEvent extends EventListener {
/**
*
*/
constructor () {
constructor() {
/**
*
*/
@ -25,7 +25,7 @@ export default class onlineEvent extends EventListener {
*
* @param e
*/
async execute (e) {
async execute(e) {
logger.mark('----^_^----')
logger.mark(logger.green(`Miao-Yunzai 上线成功 版本v${cfg.package.version}`))
logger.mark(logger.green('https://github.com/yoimiya-kokomi/Miao-Yunzai'))
@ -41,7 +41,7 @@ export default class onlineEvent extends EventListener {
*
* @returns
*/
async loginMsg () {
async loginMsg() {
if (!cfg.bot.online_msg) return
if (!cfg.masterQQ || !cfg.masterQQ[0]) return
let key = `Yz:loginMsg:${Bot.uin}`
@ -52,6 +52,6 @@ export default class onlineEvent extends EventListener {
redis.set(key, '1', { EX: cfg.bot.online_msg_exp })
setTimeout(() => common.relpyPrivate(cfg.masterQQ[0], msg), 1000)
setTimeout(() => relpyPrivate(cfg.masterQQ[0], msg), 1000)
}
}
}

View File

@ -1,6 +1,6 @@
import fs from 'node:fs/promises'
import lodash from 'lodash'
import cfg from '../config/config.js'
import cfg from '../../config/config.js'
import schedule from 'node-schedule'
import { segment } from 'icqq'
import chokidar from 'chokidar'
@ -81,6 +81,8 @@ class PluginsLoader {
return ret
}
pluginCount = null
/**
*
* @param isRefresh

View File

@ -42,7 +42,7 @@ export default class BaseModel {
* @param time
* @returns
*/
_cacheThis(model, id, time = 10 * 60) {
_cacheThis(model?: any, id?: any, time = 10 * 60) {
const uuid = this._uuid || `${model}:${id}`
this._uuid = uuid
if (uuid) {

View File

@ -22,7 +22,7 @@ export default class DailyCache extends BaseModel {
* @param game
* @returns
*/
constructor(uid: string | number, game = 'config') {
constructor(uid: number | string, game = 'config') {
super()
const storeKey = DailyCache.getStoreKey(uid, game)
// 检查实例缓存
@ -43,7 +43,7 @@ export default class DailyCache extends BaseModel {
* * servKey (mys/hoyolab)servCache
* @returns {DailyCache}
*/
static create(uid, game = 'config') {
static create(uid: number | string, game = 'config') {
return new DailyCache(uid, game)
}

View File

@ -46,6 +46,14 @@ const tables = {
* ***********
*/
export default class MysUser extends BaseModel {
gsUids = []
srUids = []
ltuid = null
uids: any = []
/**
*
* @param ltuid
@ -386,7 +394,7 @@ export default class MysUser extends BaseModel {
let res = null
let msg = 'error'
for (let serv of ['mys', 'hoyolab']) {
let roleRes = await this.getGameRole(serv)
const roleRes = await this.getGameRole(serv)
if (roleRes?.retcode === 0) {
res = roleRes
if (serv === 'hoyolab') {
@ -431,18 +439,18 @@ export default class MysUser extends BaseModel {
* @returns
*/
async getGameRole(serv = 'mys') {
let ck = this.ck
let url = {
const ck = this.ck
const url = {
mys: 'https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie',
hoyolab:
'https://sg-public-api.hoyolab.com/binding/api/getUserGameRolesByCookie'
}
let res = await fetch(url[serv], { method: 'get', headers: { Cookie: ck } })
const res = await fetch(url[serv], {
method: 'get',
headers: { Cookie: ck }
})
if (!res.ok) return false
res = await res.json()
return res
return await res.json()
}
/**
@ -468,10 +476,11 @@ export default class MysUser extends BaseModel {
}
})
if (!res.ok) return res
res = await res.json()
return res
return await res.json()
}
cache = null
/**
*
* @param game
@ -496,11 +505,17 @@ export default class MysUser extends BaseModel {
if (this.db && !db) {
return
}
// tudo
// ???
db = db && db !== true ? db : await MysUserDB.find(this.ltuid, true)
this.db = db
this.setCkData(db)
}
type = null
device = null
/**
* ck数据
* @param data
@ -516,6 +531,8 @@ export default class MysUser extends BaseModel {
})
}
db = null
/**
*
*/
@ -557,6 +574,8 @@ export default class MysUser extends BaseModel {
return this.uids[game]?.length > 0
}
ck = null
/**
* MysUser缓存记录
* @returns

View File

@ -129,6 +129,10 @@ export default class NoteUser extends BaseModel {
})
}
db = null
qq = null
/**
*
* @param db
@ -148,6 +152,8 @@ export default class NoteUser extends BaseModel {
await this.save()
}
mysUsers = null
/**
* MysUser对象
*/
@ -336,6 +342,8 @@ export default class NoteUser extends BaseModel {
this.save()
}
_games = null
/**
*
* @param game
@ -375,7 +383,7 @@ export default class NoteUser extends BaseModel {
setMainUid(uid = '', game = 'gs', save = true) {
this._map = false
game = this.gameKey(game)
if (uid < 100 || !uid) {
if (Number(uid) < 100 || !uid) {
let uids = this.getUidList(game)
uid = (uids?.[uid] || uids?.[0])?.uid || ''
}
@ -417,6 +425,10 @@ export default class NoteUser extends BaseModel {
return await this.delMysUser(ltuid)
}
mysUsers = []
_map = null
/**
*
* @param mysUser

View File

@ -1,6 +1,6 @@
import md5 from 'md5'
import fetch from 'node-fetch'
import cfg from '../lib/config/config.js'
import cfg from '../config/config.js'
import apiTool from './apiTool.js'
let HttpsProxyAgent = ''

View File

@ -15,6 +15,14 @@ import DailyCache from './DailyCache.js'
*/
export default class MysInfo {
static tips = '请先#绑定Cookie\n发送【Cookie帮助】查看配置教程'
uid = null
e = null
userId = null
ckInfo = null
auth = null
gtest = null
mysButton = null
/**
*
* @param e
@ -54,6 +62,12 @@ export default class MysInfo {
]
this.gtest = false
/**
* ********
* tudo
* *****
*/
this.mysButton = segment.button([
{ text: '米游社', link: 'https://miyoushe.com' }
])
@ -598,6 +612,8 @@ export default class MysInfo {
return res
}
ckUser = null
/**
* ck
* @returns

View File

@ -10,15 +10,17 @@ import path from 'node:path'
* @param msg
* @param uin bot发送Bot
*/
async function relpyPrivate (userId, msg, uin = Bot.uin) {
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)
})
return await Bot[uin]
.pickUser(userId)
.sendMsg(msg)
.catch(err => {
logger.mark(err)
})
}
}
@ -26,8 +28,8 @@ async function relpyPrivate (userId, msg, uin = Bot.uin) {
*
* @param ms
*/
function sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms))
}
/**
@ -36,7 +38,7 @@ function sleep (ms) {
* @param savePath
* @param param
*/
async function downFile (fileUrl, savePath, param = {}) {
export async function downFile(fileUrl: string, savePath: string, param = {}) {
try {
mkdirs(path.dirname(savePath))
logger.debug(`[下载文件] ${fileUrl}`)
@ -51,11 +53,11 @@ async function downFile (fileUrl, savePath, param = {}) {
}
/**
*
* @param dirname
* @returns
*
* @param dirname
* @returns
*/
function mkdirs (dirname) {
export function mkdirs(dirname: string) {
if (fs.existsSync(dirname)) {
return true
} else {
@ -73,68 +75,96 @@ function mkdirs (dirname) {
* @param dec
* @param msgsscr
*/
async function makeForwardMsg (e, msg = [], dec = '', msgsscr = false) {
if (!Array.isArray(msg)) {
msg = [msg]
}
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
let id = msgsscr ? e.user_id : Bot.uin
//
const Id = msgsscr ? e.user_id : Bot.uin
// 是群聊
if (e.isGroup) {
try {
let info = await e.bot.getGroupMemberInfo(e.group_id, id)
name = info.card || info.nickname
} catch (err) { }
}
let userInfo = {
user_id: id,
nickname: name
}
let forwardMsg = []
for (const message of msg) {
if (!message) {
continue
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({
...userInfo,
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') {
let detail = forwardMsg.data?.meta?.detail
if (detail) {
detail.news = [{ text: 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) { }
} catch (err) {
console.error(err)
}
return forwardMsg
}
/**
*
*/
export default { sleep, relpyPrivate, downFile, makeForwardMsg }

View File

@ -1,3 +1,4 @@
export * from './config.js'
export * from './puppeteer.js'
export * from './types.js'
export * from './common.js'