lintonxue00 commited on
Commit
56e7a75
1 Parent(s): 21b51d7

Upload index.js

Browse files
Files changed (1) hide show
  1. 不知道/回收站/index.js +78 -0
不知道/回收站/index.js ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Version } from './components/index.js'
2
+ import chalk from 'chalk'
3
+ import fs from 'node:fs'
4
+ import YAML from 'yaml'
5
+ import { checkPackage } from './components/CheckPackage.js'
6
+ import { sendToMaster } from './components/Common.js'
7
+
8
+ await init()
9
+
10
+ /** 初始化事件 */
11
+ async function init() {
12
+ //检测有没有配置文件
13
+ const configPath = process.cwd().replace(/\\/g, "/") + '/plugins/WeLM-plugin/'
14
+ let path = configPath + 'config/'
15
+ let pathDef = configPath + 'defSet/'
16
+ const files = fs.readdirSync(pathDef).filter(file => file.endsWith('.yaml'))
17
+ for (let file of files) {
18
+ if (!fs.existsSync(`${path}${file}`)) {
19
+ fs.copyFileSync(`${pathDef}${file}`, `${path}${file}`)
20
+ }
21
+ }
22
+ }
23
+
24
+ await firstGuide()
25
+
26
+ async function firstGuide() {
27
+ let Guide = (await YAML.parse(fs.readFileSync(`./plugins/WeLM-plugin/config/config.yaml`,'utf8'))).Guide
28
+ if (Guide != "yes") {
29
+ sendToMaster('欢迎您使用WeLM自定义对话插件! \n本插件帮助文档: https://gitee.com/shuciqianye/yunzai-custom-dialogue-welm \n数据物价, 请充分了解本插件功能与用户条约后再使用! \n感谢您的支持!!!')
30
+ let res = fs.readFileSync('./plugins/WeLM-plugin/config/config.yaml', "utf8")
31
+ let str = `${res}`
32
+ var reg = new RegExp(`Guide: "(.*?)"`);
33
+ var config = str.replace(reg, `Guide: "yes"`);
34
+ fs.writeFileSync('./plugins/WeLM-plugin/config/config.yaml', config, "utf8");
35
+ }
36
+ }
37
+
38
+ const settings = await YAML.parse(fs.readFileSync(`./plugins/WeLM-plugin/config/config.yaml`,'utf8'))
39
+
40
+ //输出提示
41
+ logger.info('----✩•‿• ʜᴀᴠᴇ ᴀ ɢᴏᴏᴅ ᴛɪᴍᴇ☄︎♡----')
42
+ logger.info(`WeLM对话插件初始化(・ω< )★`)
43
+ logger.info(`当前版本: ${chalk.rgb(150, 50, 100)(Version.version)}`)
44
+ logger.info(`作者: ${chalk.rgb(0, 255, 0)('JD')} ${logger.red('兰罗摩')} ${logger.blue('书辞千楪Sama')}`)
45
+ logger.info(`当前API-Token: "${chalk.rgb(103, 93, 189)(settings.APIToken)}"`)
46
+ logger.info('-------------------------------')
47
+
48
+ let passed = await checkPackage()
49
+ if (!passed) {
50
+ throw 'Missing necessary dependencies'
51
+ }
52
+
53
+ //加载插件
54
+ const files = fs.readdirSync('./plugins/WeLM-plugin/apps').filter(file => file.endsWith('.js'))
55
+
56
+ let ret = []
57
+
58
+ files.forEach((file) => {
59
+ ret.push(import(`./apps/${file}`))
60
+ })
61
+
62
+
63
+ ret = await Promise.allSettled(ret)
64
+
65
+ let apps = {}
66
+ for (let i in files) {
67
+ let name = files[i].replace('.js', '')
68
+
69
+ if (ret[i].status != 'fulfilled') {
70
+ logger.error(`载入插件错误:${logger.red(name)}`)
71
+ logger.error(ret[i].reason)
72
+ continue
73
+ }
74
+ apps[name] = ret[i].value[Object.keys(ret[i].value)[0]]
75
+ }
76
+
77
+
78
+ export { apps }