forked from chinoyui/meme-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
114 lines (93 loc) · 3.29 KB
/
Copy pathindex.js
File metadata and controls
114 lines (93 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import fs from 'node:fs/promises'
import path from 'node:path'
import axios from 'axios'
import chalk from 'chalk'
import { Version } from '#components'
import { Utils } from '#models'
const startTime = Date.now()
let apps
let responseData = '加载失败'
try {
const response = await axios.get(
`https://api.wuliya.cn/api/count?name=${Version.Plugin_Name}&type=json`,
{ timeout: 500 }
)
responseData = response.data.data
} catch (error) {
logger.warn('⚠️ 访问统计数据失败,超时或网络错误')
}
try {
await Utils.Tools.init()
logger.info(chalk.bold.cyan(`[${Version.Plugin_AliasName}] 🎉 表情包数据初始化成功!`))
} catch (error) {
logger.error(chalk.bold.red(`[${Version.Plugin_AliasName}] 💥 表情包数据初始化失败!错误详情:${error.message}`))
}
try {
const files = (await fs.readdir(`${Version.Plugin_Path}/apps`))
.filter(file => file.endsWith('.js'))
const ret = await Promise.allSettled(
files.map(async (file) => {
const filePath = path.resolve(`${Version.Plugin_Path}/apps/${file}`)
const startModuleTime = Date.now()
try {
const module = await import(`file://${filePath}`)
const endModuleTime = Date.now()
const loadTime = endModuleTime - startModuleTime
logger.debug(
chalk.rgb(0, 255, 255)(`[${Version.Plugin_AliasName}]`) +
chalk.green(` 🚀 ${file.replace('.js', '')}`) +
chalk.rgb(255, 223, 0)(` 加载时间: ${loadTime} ms`)
)
return module
} catch (error) {
logger.error(
chalk.bgRgb(255, 0, 0).white.bold(' ❌ 载入插件错误:') +
chalk.redBright(` ${file.replace('.js', '')} `) +
' 🚫'
)
logger.debug(chalk.red(`📄 错误详情: ${error.message}`))
return null
}
})
)
apps = {}
files.forEach((file, i) => {
const name = file.replace('.js', '')
if (ret[i].status !== 'fulfilled' || !ret[i].value) {
return
}
apps[name] = ret[i].value[Object.keys(ret[i].value)[0]]
})
const endTime = Date.now()
const loadTime = endTime - startTime
let loadTimeColor = chalk.green.bold
if (loadTime < 500) {
loadTimeColor = chalk.rgb(144, 238, 144).bold
} else if (loadTime < 1000) {
loadTimeColor = chalk.rgb(255, 215, 0).bold
} else {
loadTimeColor = chalk.red.bold
}
logger.info(chalk.bold.rgb(0, 255, 0)('========= 🌟🌟🌟 ========='))
logger.info(
chalk.bold.blue('📦 当前运行环境: ') +
chalk.bold.white(`${Version.Bot_Name}`) +
chalk.gray(' | ') +
chalk.bold.green('🏷️ 运行版本: ') +
chalk.bold.white(`${Version.Bot_Version}`) +
chalk.gray(' | ') +
chalk.bold.yellow('📊 运行插件总访问/运行次数: ') +
chalk.bold.cyan(responseData)
)
logger.info(
chalk.bold.rgb(255, 215, 0)(`✨ ${Version.Plugin_AliasName} `) +
chalk.bold.rgb(255, 165, 0).italic(Version.Plugin_Version) +
chalk.rgb(255, 215, 0).bold(' 载入成功 ^_^')
)
logger.info(loadTimeColor(`⏱️ 载入耗时:${loadTime} ms`))
logger.info(chalk.cyan.bold('💬 雾里的小窝: 272040396'))
logger.info(chalk.green.bold('========================='))
} catch (error) {
logger.error(chalk.red.bold(`❌ 初始化失败: ${error}`))
}
export { apps }