This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
110 lines (90 loc) · 3.14 KB
/
index.js
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
import fs from 'fs'
import { exec } from "child_process"
let ret = []
let apps = {}
let _path = process.cwd() + '/plugins/ZyyGio-Plugin'
if (!fs.existsSync(_path)) {
_path = process.cwd() + '/plugins/Zyy-GM-plugin'
}
if (!fs.existsSync(_path + '/data')) {
fs.mkdirSync(_path + '/data')
}
if (!fs.existsSync(_path + '/data/group')) {
fs.mkdirSync(_path + '/data/group')
}
if (!fs.existsSync(_path + '/data/user')) {
fs.mkdirSync(_path + '/data/user')
}
if (!fs.existsSync(_path + '/data/alluid')) {
fs.mkdirSync(_path + '/data/alluid')
}
if (!fs.existsSync(_path + '/config')) {
fs.mkdirSync(_path + '/config')
}
const configfiles = (fs.readdirSync(`${_path}/default_config`))
.filter(file => !(fs.readdirSync(`${_path}/config`))
.includes(file) && !'请勿修改此文件夹下的任何文件.txt'.includes(file))
configfiles.forEach(file => {
fs.copyFileSync(`${_path}/default_config/${file}`, `${_path}/config/${file}`)
logger.mark(`GIO插件:缺少文件...创建完成(${file})`)
})
if (!global.segment) {
global.segment = (await import("oicq")).segment
}
console.log('\x1b[36m%s\x1b[0m', '-----------------------------')
console.log('\x1b[36m%s\x1b[0m', 'GM插件0.0.5初始化~')
console.log('\x1b[36m%s\x1b[0m', 'Hi~这里是Zyy.小钰!')
console.log('\x1b[2m%s\x1b[0m', '---------------------')
//加载插件
const files = fs.readdirSync(`${_path}/apps`).filter(file => file.endsWith('.js'))
files.forEach((file) => {
ret.push(import(`./apps/${file}`))
})
ret = await Promise.allSettled(ret)
for (let i in files) {
let name = files[i].replace('.js', '')
if (ret[i].status != 'fulfilled') {
logger.error(`载入插件错误:${logger.red(name)}`)
logger.error(ret[i].reason)
continue
}
apps[name] = ret[i].value[Object.keys(ret[i].value)[0]]
}
console.log('\x1b[36m%s\x1b[0m', '插件加载完成啦~')
console.log('\x1b[36m%s\x1b[0m', '祝旅行者在提瓦特玩得开心哦~')
console.log('\x1b[36m%s\x1b[0m', '-----------------------------')
// 当前的远程仓库地址
exec('git config --get remote.origin.url', { cwd: `${_path}` }, (err, stdout, stderr) => {
if (err) {
console.error(err)
return
}
// 检测当前的远程仓库地址是否等于指定地址
const gitee = [
'https://gitee.com/Zyy955/Zyy-GM-plugin',
'https://gitee.com/ZYY-Yu/Zyy-GM-plugin'
]
const github = [
'https://github.com/Zyy955/Zyy-GM-plugin',
'https://github.com/ZYY-Yu/Zyy-GM-plugin'
]
if (gitee.includes(stdout.trim())) {
exec("git remote set-url origin https://gitee.com/Zyy955/ZyyGio-Plugin.git", { cwd: `${_path}` }, (err, stdout, stderr) => {
if (err) {
console.error(err)
return
}
logger.mark('GIO插件:检测到旧的 Gitee 仓库源,已修改为最新的 Gitee 仓库!')
})
}
else if (github.includes(stdout.trim())) {
exec("git remote set-url origin https://github.com/Zyy955/ZyyGio-Plugin.git", { cwd: `${_path}` }, (err, stdout, stderr) => {
if (err) {
console.error(err)
return
}
logger.mark('GIO插件:检测到旧的 Github 仓库源,已修改为最新的 Github 仓库!')
})
}
})
export { apps }