📝 优化文件结构
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { common, QQApi } from '../model/index.js'
|
||||
import { Version } from '../components/index.js'
|
||||
import _ from 'lodash'
|
||||
import moment from 'moment'
|
||||
import { status } from '../constants/other.js'
|
||||
import yaml from 'yaml'
|
||||
import fs from 'node:fs'
|
||||
import yaml from 'yaml'
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { Version } from '../components/index.js'
|
||||
import { status } from '../constants/other.js'
|
||||
import { common, QQApi } from '../model/index.js'
|
||||
import { sleep } from '../tools/index.js'
|
||||
|
||||
/** API请求错误文案 */
|
||||
const API_ERROR = '❎ 出错辣,请稍后重试'
|
||||
|
||||
@@ -458,7 +460,7 @@ export class Assistant extends plugin {
|
||||
.then(() => e.reply('✅ ' + i + ' 群聊消息已送达'))
|
||||
.catch((err) =>
|
||||
common.handleException(e, err, { MsgTemplate: `❎ ${i} 发送失败\n错误信息为:{error}` }))
|
||||
await common.sleep(5000)
|
||||
await sleep(5000)
|
||||
}
|
||||
}
|
||||
return false
|
||||
@@ -480,7 +482,7 @@ export class Assistant extends plugin {
|
||||
|
||||
if (quits == e.group_id) {
|
||||
e.reply('✅ 3秒后退出本群聊')
|
||||
await common.sleep(3000)
|
||||
await sleep(3000)
|
||||
}
|
||||
|
||||
await this.Bot.pickGroup(quits).quit()
|
||||
@@ -798,7 +800,7 @@ export class Assistant extends plugin {
|
||||
logger.info(`${e.logFnc}执行撤回消息`)
|
||||
await target.recallMsg(source.message_id)
|
||||
}
|
||||
await common.sleep(300)
|
||||
await sleep(300)
|
||||
let recallcheck = await this.Bot.getMsg(source.message_id)
|
||||
if (recallcheck && recallcheck.message_id == source.message_id) {
|
||||
let msg
|
||||
|
||||
@@ -3,8 +3,7 @@ import moment from 'moment'
|
||||
import { Config } from '../../components/index.js'
|
||||
import { Time_unit } from '../../constants/other.js'
|
||||
import { GroupAdmin as Ga, GroupBannedWords, QQApi, common, puppeteer } from '../../model/index.js'
|
||||
import cronValidate from '../../tools/cronValidate.js'
|
||||
import translateChinaNum from '../../tools/translateChinaNum.js'
|
||||
import { cronValidate, translateChinaNum } from '../../tools/index.js'
|
||||
|
||||
// API请求错误文案
|
||||
const API_ERROR = '❎ 出错辣,请稍后重试'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Config } from '../../components/index.js'
|
||||
import { common, GroupAdmin as Ga } from '../../model/index.js'
|
||||
import _ from 'lodash'
|
||||
import { sleep } from '../../tools/index.js'
|
||||
// 全局
|
||||
let temp = {}
|
||||
const ops = ['+', '-']
|
||||
@@ -92,7 +93,7 @@ export class NewGroupVerify extends plugin {
|
||||
}
|
||||
for (let item of list) {
|
||||
await verify(item.user_id, e.group_id, e)
|
||||
await common.sleep(2000)
|
||||
await sleep(2000)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +138,7 @@ Bot.on?.('notice.group.increase', async (e) => {
|
||||
if (e.user_id == (e.bot ?? Bot).uin) return
|
||||
if (Config.masterQQ.includes(e.user_id)) return
|
||||
|
||||
await common.sleep(DelayTime * 1000)
|
||||
await sleep(DelayTime * 1000)
|
||||
await verify(e.user_id, e.group_id, e)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import _ from 'lodash'
|
||||
import { common } from '../model/index.js'
|
||||
import moment from 'moment'
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { common } from '../model/index.js'
|
||||
import { sleep } from '../tools/index.js'
|
||||
|
||||
const ROLE_MAP = {
|
||||
admin: '群管理',
|
||||
owner: '群主',
|
||||
@@ -94,7 +96,7 @@ export class NewHandle extends plugin {
|
||||
} else {
|
||||
fail.push(`${fail.length + 1}、${i.user_id}`)
|
||||
}
|
||||
await common.sleep(2000)
|
||||
await sleep(2000)
|
||||
}
|
||||
let msg = [
|
||||
`本次共${yes ? '同意' : '拒绝'}${FriendAdd.length}条好友申请\n成功:${success.length}\n失败:${fail.length}`
|
||||
@@ -316,7 +318,7 @@ export class NewHandle extends plugin {
|
||||
fail.push(`${fail.length + 1}、${i.user_id}`)
|
||||
}
|
||||
}
|
||||
await common.sleep(1000)
|
||||
await sleep(1000)
|
||||
}
|
||||
let msg = [
|
||||
`本次共处理${SystemMsg.length}条群申请\n成功:${success.length}\n失败:${fail.length}\n风险:${risk.length}`
|
||||
@@ -377,7 +379,7 @@ export class NewHandle extends plugin {
|
||||
} else {
|
||||
fail.push(`${fail.length + 1}、${i.user_id}`)
|
||||
}
|
||||
await common.sleep(1000)
|
||||
await sleep(1000)
|
||||
}
|
||||
let msg = [`本次共处理${SystemMsg.length}条群邀请\n成功:${success.length}\n失败:${fail.length}`]
|
||||
if (!_.isEmpty(success)) msg.push(['以下为成功的名单:\n', success.join('\n')])
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import os from 'os'
|
||||
import _ from 'lodash'
|
||||
import fs from 'fs'
|
||||
import { common } from './index.js'
|
||||
import { Config, Data } from '../components/index.js'
|
||||
import request from '../lib/request/request.js'
|
||||
import { execSync } from '../tools/index.js'
|
||||
|
||||
export default new class {
|
||||
constructor () {
|
||||
@@ -367,7 +367,7 @@ export default new class {
|
||||
*/
|
||||
async getFastFetch (e) {
|
||||
if (process.platform == 'win32' && !/pro/.test(e.msg)) return ''
|
||||
let ret = await common.execSync('bash plugins/yenai-plugin/resources/state/state.sh')
|
||||
let ret = await execSync('bash plugins/yenai-plugin/resources/state/state.sh')
|
||||
if (ret.error) {
|
||||
e.reply(`❎ 请检查是否使用git bash启动Yunzai-bot\n错误信息:${ret.stderr}`)
|
||||
return ''
|
||||
|
||||
@@ -3,6 +3,8 @@ import { common } from '../index.js'
|
||||
import _ from 'lodash'
|
||||
import moment from 'moment'
|
||||
import request from '../../lib/request/request.js'
|
||||
import { sleep } from '../../tools/index.js'
|
||||
|
||||
/** QQ接口 */
|
||||
export default class {
|
||||
constructor (e) {
|
||||
@@ -459,7 +461,7 @@ export default class {
|
||||
data,
|
||||
statusCode: 'json'
|
||||
}))
|
||||
await common.sleep(5000)
|
||||
await sleep(5000)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
/*! !!!!!!
|
||||
以下为凶残的cron表达式验证,胆小肾虚及心脏病者慎入!!!
|
||||
不听劝告者后果自负T T
|
||||
!!!!!!!
|
||||
cron表达式为秒,分,时,日,月,周,年
|
||||
判断正误方法:错误的话返回错误信息,正确的话返回true
|
||||
*/
|
||||
// 返回错误信息用
|
||||
let message = ''
|
||||
/**
|
||||
*
|
||||
* @param cronExpression
|
||||
* ! !!!!!!
|
||||
* 以下为凶残的cron表达式验证,胆小肾虚及心脏病者慎入!!!
|
||||
* 不听劝告者后果自负T T
|
||||
* !!!!!!!
|
||||
* cron表达式为秒,分,时,日,月,周,年
|
||||
* 判断正误方法:错误的话返回错误信息,正确的话返回true
|
||||
* @param {string | true}cronExpression crom表达式
|
||||
*/
|
||||
export default function cronValidate (cronExpression) {
|
||||
// 先将cron表达式进行分割
|
||||
|
||||
29
tools/index.js
Normal file
29
tools/index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import cronValidate from './cronValidate'
|
||||
import formatDuration from './formatDuration'
|
||||
import sagiri from './sagiri'
|
||||
import translateChinaNum from './translateChinaNum.js'
|
||||
import uploadRecord from './uploadRecord.js'
|
||||
import child_process from 'child_process'
|
||||
|
||||
/**
|
||||
* 延时函数
|
||||
* @param {*} ms 时间(毫秒)
|
||||
*/
|
||||
function sleep (ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
/**
|
||||
* Promise执行exec
|
||||
* @param {string} cmd
|
||||
* @returns {*}
|
||||
*/
|
||||
async function execSync (cmd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
child_process.exec(cmd, (error, stdout, stderr) => {
|
||||
resolve({ error, stdout, stderr })
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export { cronValidate, formatDuration, sagiri, translateChinaNum, uploadRecord, sleep, execSync }
|
||||
Reference in New Issue
Block a user