From 8fc66505104ec89bfa306b8816b9b6d6185bb034 Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Sun, 9 Jun 2024 23:02:31 +0800 Subject: [PATCH] fix: login --- src/bot.ts | 7 +++++++ src/core/events/login.ts | 10 +++++----- src/core/loader.ts | 2 +- src/core/plugins/loader.ts | 33 +++++++++++++++++++++++---------- src/global.d.ts | 2 +- src/local.js | 2 +- 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index f8b7f68..1ff553f 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -17,6 +17,13 @@ import ListenerLoader from './core/loader.js' */ import { Client } from 'icqq' +import { plugin } from './core/plugin.js' + +/** + * global + */ +global.plugin = plugin + /** * */ diff --git a/src/core/events/login.ts b/src/core/events/login.ts index 69e2cba..e8175ae 100644 --- a/src/core/events/login.ts +++ b/src/core/events/login.ts @@ -71,7 +71,7 @@ export default class loginEvent extends EventListener { */ inquirer .prompt({ - // type: 'input', + type: 'input', message: '回车刷新二维码,等待扫码中...\n', name: 'enter' }) @@ -134,7 +134,7 @@ export default class loginEvent extends EventListener { if (!ticket) { let res = await inquirer.prompt({ - // type: 'input', + type: 'input', message: '请输入ticket:', name: 'ticket', validate(value) { @@ -211,7 +211,7 @@ export default class loginEvent extends EventListener { // await inquirer.prompt({ - // type: 'input', + type: 'input', message: '验证完成后按回车确认,等待在操作中...', name: 'enter' }) @@ -261,7 +261,7 @@ export default class loginEvent extends EventListener { console.log('\n' + logger.green(event.url) + '\n') console.log('请打开上面链接,完成验证后按回车') await inquirer.prompt({ - // type: 'input', + type: 'input', message: '等待操作中...', name: 'enter' }) @@ -272,7 +272,7 @@ export default class loginEvent extends EventListener { await sleep(200) logger.info(`验证码已发送:${event.phone}\n`) let res = await inquirer.prompt({ - // type: 'input', + type: 'input', message: '请输入短信验证码:', name: 'sms' }) diff --git a/src/core/loader.ts b/src/core/loader.ts index 4518dd4..2ebaf25 100644 --- a/src/core/loader.ts +++ b/src/core/loader.ts @@ -16,7 +16,7 @@ class ListenerLoader { const files = fs .readdirSync('./src/core/events') - .filter(file => file.endsWith('.js')) + .filter(file => /(.ts|.js)$/.test(file)) for (let File of files) { try { diff --git a/src/core/plugins/loader.ts b/src/core/plugins/loader.ts index f9abfe4..e9666a3 100644 --- a/src/core/plugins/loader.ts +++ b/src/core/plugins/loader.ts @@ -5,7 +5,7 @@ import schedule from 'node-schedule' import { segment } from 'icqq' import chokidar from 'chokidar' import moment from 'moment' -import path from 'node:path' +import path, { join } from 'node:path' import Runtime from './runtime.js' import Handler from './handler.js' @@ -17,12 +17,16 @@ class PluginsLoader { priority = [] handler = {} task = [] - dir = 'plugins' + + // + dir = join(process.cwd(),'plugins') /** * 命令冷却cd */ groupGlobalCD = {} + + // singleCD = {} /** @@ -43,7 +47,6 @@ class PluginsLoader { */ srReg = /^#?(\*|星铁|星轨|穹轨|星穹|崩铁|星穹铁道|崩坏星穹铁道|铁道)+/ - /** * * @returns @@ -55,21 +58,31 @@ class PluginsLoader { if (val.isFile()) continue const tmp = { name: val.name, - path: `../../${this.dir}/${val.name}`, + path: join(this.dir,val.name), } try { - if (await fs.stat(`${this.dir}/${val.name}/index.js`)) { - tmp.path = `${tmp.path}/index.js` + const dir = join(tmp.path,'index.js') + if (await fs.stat(dir)) { + tmp.path = dir ret.push(tmp) continue } - } catch (err) { } + } catch (err) { + // + } - const apps = await fs.readdir(`${this.dir}/${val.name}`, { withFileTypes: true }) + // + + const dir = join(this.dir,val.name) + + const apps = await fs.readdir(dir, { withFileTypes: true }) + + // for (const app of apps) { if (!app.isFile()) continue - if (!app.name.endsWith('.js')) continue + // .js .ts + if (!/^(.js|.ts)$/.test(app.name)) continue ret.push({ name: `${tmp.name}/${app.name}`, path: `${tmp.path}/${app.name}`, @@ -121,7 +134,7 @@ class PluginsLoader { */ async importPlugin(file, packageErr?:any) { try { - let app = await import(file.path) + let app = await import(`file://${file.path}`) if (app.apps) app = { ...app.apps } const pluginArray = [] lodash.forEach(app, p => diff --git a/src/global.d.ts b/src/global.d.ts index cda6d34..c8b0366 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -9,6 +9,6 @@ declare global { var redis: RedisClientType var Bot: typeof Yunzai.prototype var segment: typeof se - var plugin: typeof p.prototype + var plugin: typeof p var logger: any } diff --git a/src/local.js b/src/local.js index 4af413f..d3a6bd3 100644 --- a/src/local.js +++ b/src/local.js @@ -1,2 +1,2 @@ -export { Common, Date } from '#miao' +export { Common, Data } from '#miao' export { Character, Weapon } from '#miao.models'