alemonjs 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -9
- package/bin/main.js +17 -0
- package/lib/alemon/dealmsg.js +66 -18
- package/lib/alemon/puppeteer.js +9 -16
- package/lib/config/index.js +1 -1
- package/lib/config/login.js +21 -82
- package/lib/config/pup.js +75 -0
- package/lib/config/types.js +1 -10
- package/lib/default/login/discord.js +16 -0
- package/lib/default/login/kook.js +5 -0
- package/lib/default/login/ntqq.js +17 -0
- package/lib/default/login/qq.js +16 -0
- package/lib/default/login/villa.js +13 -0
- package/lib/default/mysql.js +7 -0
- package/lib/default/pup.js +15 -0
- package/lib/default/redis.js +6 -0
- package/lib/default/server.js +4 -0
- package/lib/default/types.js +16 -0
- package/lib/define/api.js +23 -0
- package/lib/define/child_process.js +10 -0
- package/lib/define/command.js +22 -0
- package/lib/define/index.js +7 -0
- package/lib/define/main.js +198 -0
- package/lib/{map.js → define/map.js} +8 -6
- package/lib/define/plugin.js +25 -0
- package/lib/define/types.js +1 -0
- package/lib/discord/login.js +18 -62
- package/lib/index.js +22 -8
- package/lib/kook/login.js +7 -39
- package/lib/ntqq/index.js +1 -1
- package/lib/ntqq/login.js +15 -62
- package/lib/ntqq/sdk/wss.js +0 -1
- package/lib/qq/index.js +13 -2
- package/lib/qq/login.js +3 -124
- package/lib/villa/login.js +11 -51
- package/package.json +61 -59
- package/types/alemon/dealmsg.d.ts +10 -0
- package/types/config/index.d.ts +1 -1
- package/types/config/pup.d.ts +7 -0
- package/types/config/types.d.ts +9 -117
- package/types/default/login/discord.d.ts +8 -0
- package/types/default/login/kook.d.ts +6 -0
- package/types/default/login/ntqq.d.ts +16 -0
- package/types/default/login/qq.d.ts +12 -0
- package/types/default/login/villa.d.ts +14 -0
- package/types/default/mysql.d.ts +8 -0
- package/types/default/pup.d.ts +3 -0
- package/types/default/redis.d.ts +7 -0
- package/types/default/server.d.ts +5 -0
- package/types/default/types.d.ts +300 -0
- package/types/define/api.d.ts +30 -0
- package/types/define/child_process.d.ts +1 -0
- package/types/define/command.d.ts +1 -0
- package/types/define/index.d.ts +7 -0
- package/types/define/main.d.ts +20 -0
- package/types/{map.d.ts → define/map.d.ts} +3 -1
- package/types/define/plugin.d.ts +4 -0
- package/types/define/types.d.ts +111 -0
- package/types/index.d.ts +16 -2
- package/lib/bot.js +0 -66
- package/lib/config/toml.js +0 -25
- package/types/bot.d.ts +0 -20
- package/types/config/toml.d.ts +0 -12
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { compilationTools } from 'alemon-rollup';
|
|
2
|
+
import PupOptions from '../default/pup.js';
|
|
3
|
+
import { rebotMap } from './map.js';
|
|
4
|
+
import { nodeScripts } from './child_process.js';
|
|
5
|
+
import { ClientAPIByQQ as ClientByNTQQ } from '../ntqq/sdk/index.js';
|
|
6
|
+
import { createApp, loadInit, setBotConfigByKey, setLanchConfig, getPupPath, getBotConfigByKey, setAppRegex } from '../index.js';
|
|
7
|
+
import { command } from './command.js';
|
|
8
|
+
// 设置ntqq独立鉴权路径
|
|
9
|
+
export const setAuthenticationByNtqq = ClientByNTQQ.setAuthentication;
|
|
10
|
+
let appDir = 'application';
|
|
11
|
+
/**
|
|
12
|
+
* 应用模块集成
|
|
13
|
+
* @param AppName
|
|
14
|
+
* @param name
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export function ApplicationTools(AppName, name = 'apps') {
|
|
18
|
+
return compilationTools({
|
|
19
|
+
aInput: `${appDir}/${AppName}/${name}/**/*.ts`,
|
|
20
|
+
aOutput: `${appDir}/${AppName}/apps.js`
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
let OptionsCache;
|
|
24
|
+
/**
|
|
25
|
+
* 得到载入配置
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export function getAlemonConfig() {
|
|
29
|
+
return OptionsCache;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 机器人配置
|
|
33
|
+
* @param Options
|
|
34
|
+
*/
|
|
35
|
+
export async function defineAlemonConfig(Options) {
|
|
36
|
+
if (!Options)
|
|
37
|
+
return;
|
|
38
|
+
OptionsCache = Options;
|
|
39
|
+
/**
|
|
40
|
+
* *******
|
|
41
|
+
* pup配置
|
|
42
|
+
* *******
|
|
43
|
+
*/
|
|
44
|
+
const pCig = { ...PupOptions, ...getPupPath() };
|
|
45
|
+
// 设置旧的值
|
|
46
|
+
setBotConfigByKey('puppeteer', pCig);
|
|
47
|
+
if (Options?.puppeteer) {
|
|
48
|
+
// 存在 替换新的值
|
|
49
|
+
setBotConfigByKey('puppeteer', Options?.puppeteer);
|
|
50
|
+
}
|
|
51
|
+
const pData = getBotConfigByKey('puppeteer');
|
|
52
|
+
await setLanchConfig(pData);
|
|
53
|
+
/**
|
|
54
|
+
* *********
|
|
55
|
+
* mysql配置
|
|
56
|
+
* *********
|
|
57
|
+
*/
|
|
58
|
+
if (Options?.mysql) {
|
|
59
|
+
setBotConfigByKey('mysql', Options.mysql);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* *********
|
|
63
|
+
* redis配置
|
|
64
|
+
* *********
|
|
65
|
+
*/
|
|
66
|
+
if (Options?.redis) {
|
|
67
|
+
setBotConfigByKey('redis', Options.redis);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* *********
|
|
71
|
+
* serer配置
|
|
72
|
+
* *********
|
|
73
|
+
*/
|
|
74
|
+
if (Options?.server) {
|
|
75
|
+
setBotConfigByKey('server', Options.server);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* **********
|
|
79
|
+
* 启动转换器
|
|
80
|
+
* **********
|
|
81
|
+
*/
|
|
82
|
+
const arr = [];
|
|
83
|
+
/**
|
|
84
|
+
* *********
|
|
85
|
+
* 启动机器人
|
|
86
|
+
* *********
|
|
87
|
+
*/
|
|
88
|
+
if (Options?.login) {
|
|
89
|
+
/**
|
|
90
|
+
* ********
|
|
91
|
+
* 配置载入
|
|
92
|
+
* *******
|
|
93
|
+
*/
|
|
94
|
+
if (Options.login?.discord) {
|
|
95
|
+
setBotConfigByKey('discord', Options.login.discord);
|
|
96
|
+
}
|
|
97
|
+
if (Options.login?.qq) {
|
|
98
|
+
setBotConfigByKey('qq', Options.login.qq);
|
|
99
|
+
}
|
|
100
|
+
if (Options.login?.ntqq) {
|
|
101
|
+
setBotConfigByKey('ntqq', Options.login.ntqq);
|
|
102
|
+
}
|
|
103
|
+
if (Options.login?.kook) {
|
|
104
|
+
setBotConfigByKey('kook', Options.login.kook);
|
|
105
|
+
}
|
|
106
|
+
if (Options.login?.villa) {
|
|
107
|
+
setBotConfigByKey('villa', Options.login.villa);
|
|
108
|
+
}
|
|
109
|
+
for (const item in Options.login) {
|
|
110
|
+
if (arr.indexOf(item) != -1)
|
|
111
|
+
continue;
|
|
112
|
+
if (!rebotMap[item])
|
|
113
|
+
continue;
|
|
114
|
+
arr.push(item);
|
|
115
|
+
await rebotMap[item]();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!Options?.login || Object.keys(Options?.login ?? {}).length == 0) {
|
|
119
|
+
console.info('[LOGIN] 无登录配置');
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* ************
|
|
123
|
+
* 迟缓插件加载
|
|
124
|
+
* ************
|
|
125
|
+
*/
|
|
126
|
+
let mount = false;
|
|
127
|
+
if (Options?.app?.component || Options?.app?.module) {
|
|
128
|
+
mount = true;
|
|
129
|
+
}
|
|
130
|
+
const address = Options?.plugin?.directory ?? 'application';
|
|
131
|
+
appDir = address;
|
|
132
|
+
/**
|
|
133
|
+
* ************
|
|
134
|
+
* 设置扫描规则
|
|
135
|
+
* ***********
|
|
136
|
+
*/
|
|
137
|
+
if (Options?.plugin?.RegexOpen || Options?.plugin?.RegexClose) {
|
|
138
|
+
setAppRegex({
|
|
139
|
+
RegexOpen: Options?.plugin?.RegexOpen,
|
|
140
|
+
RegexClose: Options?.plugin?.RegexClose
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* ************
|
|
145
|
+
* 扫描插件
|
|
146
|
+
* ************
|
|
147
|
+
*/
|
|
148
|
+
await loadInit({
|
|
149
|
+
mount: mount,
|
|
150
|
+
address: address == undefined ? '/application' : `/${address}`
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* ************
|
|
154
|
+
* 编译独立插件
|
|
155
|
+
* ************
|
|
156
|
+
*/
|
|
157
|
+
if (mount) {
|
|
158
|
+
const app = createApp(Options?.app?.name ?? 'bot');
|
|
159
|
+
if (Options?.app?.regJSon?.address) {
|
|
160
|
+
app.setHelp(Options?.app?.regJSon?.address ?? '/public/defset');
|
|
161
|
+
}
|
|
162
|
+
if (Options?.app?.module) {
|
|
163
|
+
const word = await compilationTools({
|
|
164
|
+
aInput: Options?.app?.module?.input ?? 'src/apps/**/*.ts',
|
|
165
|
+
aOutput: Options?.app?.module?.input ?? '.apps/index.js'
|
|
166
|
+
});
|
|
167
|
+
app.component(word);
|
|
168
|
+
}
|
|
169
|
+
if (Options?.app?.component) {
|
|
170
|
+
for await (const item of Options.app.component) {
|
|
171
|
+
app.component(item);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
app.mount('#app');
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* **********
|
|
178
|
+
* 附加执行
|
|
179
|
+
* **********
|
|
180
|
+
*/
|
|
181
|
+
if (Options?.command) {
|
|
182
|
+
for await (const item of Options.command) {
|
|
183
|
+
await command(item);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* ***************
|
|
188
|
+
* 附加脚本
|
|
189
|
+
* ***************
|
|
190
|
+
*/
|
|
191
|
+
if (Options?.scripts) {
|
|
192
|
+
for await (const item of Options.scripts) {
|
|
193
|
+
const name = item?.name ?? 'node';
|
|
194
|
+
nodeScripts(name, item?.file, item?.ars ?? []);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* **********
|
|
2
3
|
* 启动机器人
|
|
4
|
+
* **********
|
|
3
5
|
*/
|
|
4
|
-
export const
|
|
6
|
+
export const rebotMap = {
|
|
5
7
|
qq: async () => {
|
|
6
|
-
const { createAlemonByQQ: qq } = await import('
|
|
8
|
+
const { createAlemonByQQ: qq } = await import('../qq/index.js');
|
|
7
9
|
return qq().catch(err => {
|
|
8
10
|
console.error(err);
|
|
9
11
|
console.error('QQ机器人启动失败~');
|
|
@@ -11,7 +13,7 @@ export const createAlemon = {
|
|
|
11
13
|
});
|
|
12
14
|
},
|
|
13
15
|
villa: async () => {
|
|
14
|
-
const { createAlemonByVilla: villa } = await import('
|
|
16
|
+
const { createAlemonByVilla: villa } = await import('../villa/index.js');
|
|
15
17
|
return villa().catch(err => {
|
|
16
18
|
console.error(err);
|
|
17
19
|
console.error('Villa机器人启动失败~');
|
|
@@ -19,7 +21,7 @@ export const createAlemon = {
|
|
|
19
21
|
});
|
|
20
22
|
},
|
|
21
23
|
kook: async () => {
|
|
22
|
-
const { createAlemonByKOOK: kook } = await import('
|
|
24
|
+
const { createAlemonByKOOK: kook } = await import('../kook/index.js');
|
|
23
25
|
return kook().catch(err => {
|
|
24
26
|
console.error(err);
|
|
25
27
|
console.error('KOOK机器人启动失败~');
|
|
@@ -27,7 +29,7 @@ export const createAlemon = {
|
|
|
27
29
|
});
|
|
28
30
|
},
|
|
29
31
|
discord: async () => {
|
|
30
|
-
const { createAlemonByDiscord: dc } = await import('
|
|
32
|
+
const { createAlemonByDiscord: dc } = await import('../discord/index.js');
|
|
31
33
|
return dc().catch(err => {
|
|
32
34
|
console.error(err);
|
|
33
35
|
console.error('Discord机器人启动失败~');
|
|
@@ -35,7 +37,7 @@ export const createAlemon = {
|
|
|
35
37
|
});
|
|
36
38
|
},
|
|
37
39
|
ntqq: async () => {
|
|
38
|
-
const { createAlemonByNtqq: ntqq } = await import('
|
|
40
|
+
const { createAlemonByNtqq: ntqq } = await import('../ntqq/index.js');
|
|
39
41
|
return ntqq().catch(err => {
|
|
40
42
|
console.error(err);
|
|
41
43
|
console.error('Ntqq机器人启动失败~');
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 同步挂载文件
|
|
3
|
+
*/
|
|
4
|
+
export function copyAppsFile() {
|
|
5
|
+
/**
|
|
6
|
+
* 得到插件目录
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 检测是否有插件
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* 检测是否有指定目录
|
|
13
|
+
* assets
|
|
14
|
+
* pages
|
|
15
|
+
* plugins
|
|
16
|
+
* server
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* publick/.AppName/assets
|
|
20
|
+
* publick/.AppName/pages
|
|
21
|
+
* publick/.AppName/plugins
|
|
22
|
+
* publick/.AppName/server
|
|
23
|
+
* 有则 重加载 无则忽略
|
|
24
|
+
*/
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/discord/login.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import prompts from 'prompts';
|
|
2
1
|
import { GatewayIntentBits } from 'discord.js';
|
|
3
|
-
import { setBotConfigByKey, getBotConfigByKey
|
|
2
|
+
import { setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
|
|
4
3
|
/**
|
|
5
4
|
* 登录配置
|
|
6
5
|
* @param Bcf
|
|
@@ -11,69 +10,26 @@ export async function checkRobotByDiscord() {
|
|
|
11
10
|
/**
|
|
12
11
|
* 读取配置
|
|
13
12
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
setBotConfigByKey('discord', config);
|
|
30
|
-
return true;
|
|
13
|
+
const config = getBotConfigByKey('discord');
|
|
14
|
+
if ((config ?? '') !== '' && (config.token ?? '') !== '') {
|
|
15
|
+
if (!config.intents) {
|
|
16
|
+
config.intents = [
|
|
17
|
+
GatewayIntentBits.DirectMessageReactions,
|
|
18
|
+
GatewayIntentBits.DirectMessageTyping,
|
|
19
|
+
GatewayIntentBits.DirectMessages,
|
|
20
|
+
GatewayIntentBits.GuildMessageReactions,
|
|
21
|
+
GatewayIntentBits.GuildMessageTyping,
|
|
22
|
+
GatewayIntentBits.GuildMessages,
|
|
23
|
+
GatewayIntentBits.Guilds,
|
|
24
|
+
GatewayIntentBits.MessageContent // 消息内容
|
|
25
|
+
];
|
|
31
26
|
}
|
|
27
|
+
setBotConfigByKey('discord', config);
|
|
28
|
+
return true;
|
|
32
29
|
}
|
|
33
30
|
console.info('[LOGIN]', '-----------------------');
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, 60000);
|
|
37
|
-
const { token } = await prompts([
|
|
38
|
-
{
|
|
39
|
-
type: 'password',
|
|
40
|
-
name: 'token',
|
|
41
|
-
message: 'BotToken: ',
|
|
42
|
-
validate: value => value !== '' && typeof value === 'string' ? true : 'BotToken: '
|
|
43
|
-
}
|
|
44
|
-
]);
|
|
45
|
-
if (!token) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
clearTimeout(timeoutId);
|
|
49
|
-
/**
|
|
50
|
-
* 默认公域机器人
|
|
51
|
-
*/
|
|
52
|
-
const intents = [
|
|
53
|
-
GatewayIntentBits.DirectMessageReactions,
|
|
54
|
-
GatewayIntentBits.DirectMessageTyping,
|
|
55
|
-
GatewayIntentBits.DirectMessages,
|
|
56
|
-
GatewayIntentBits.GuildMessageReactions,
|
|
57
|
-
GatewayIntentBits.GuildMessageTyping,
|
|
58
|
-
GatewayIntentBits.GuildMessages,
|
|
59
|
-
GatewayIntentBits.Guilds,
|
|
60
|
-
GatewayIntentBits.MessageContent // 消息内容
|
|
61
|
-
];
|
|
62
|
-
// 得到已变更的配置
|
|
63
|
-
const db = getBotConfigByKey('discord');
|
|
64
|
-
// 得到配置
|
|
65
|
-
const data = getToml();
|
|
66
|
-
data.discord = {
|
|
67
|
-
...db,
|
|
68
|
-
// 覆盖新配置
|
|
69
|
-
token,
|
|
70
|
-
intents
|
|
71
|
-
};
|
|
72
|
-
// 写入配置
|
|
73
|
-
writeToml(data);
|
|
74
|
-
// 设置配置
|
|
75
|
-
setBotConfigByKey('discord', data.discord);
|
|
76
|
-
return true;
|
|
31
|
+
console.info('[LOGIN]', 'DISCORD配置加载失败~');
|
|
32
|
+
process.exit();
|
|
77
33
|
}
|
|
78
34
|
// GatewayIntentBits.AutoModerationConfiguration, // 自动调节配置
|
|
79
35
|
// GatewayIntentBits.AutoModerationExecution, // 自动调节执行
|
package/lib/index.js
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
if (process.argv.slice(2).includes('discord') &&
|
|
2
|
-
!process.argv.slice(2).includes('
|
|
2
|
+
!process.argv.slice(2).includes('no')) {
|
|
3
3
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
/**
|
|
6
|
+
* *******************
|
|
7
|
+
* 核心处理&公共方法
|
|
8
|
+
* *******************
|
|
9
|
+
*/
|
|
8
10
|
export * from './alemon/index.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* *******************
|
|
13
|
+
* 初始化
|
|
14
|
+
* *******************
|
|
15
|
+
*/
|
|
16
|
+
export * from './define/index.js';
|
|
17
|
+
/**
|
|
18
|
+
* **********
|
|
19
|
+
* 配置管理
|
|
20
|
+
* **********
|
|
21
|
+
*/
|
|
12
22
|
export * from './config/index.js';
|
|
13
|
-
|
|
23
|
+
/**
|
|
24
|
+
* *********
|
|
25
|
+
* 监听退出
|
|
26
|
+
* *********
|
|
27
|
+
*/
|
|
14
28
|
process.on('SIGINT', signals => {
|
|
15
29
|
console.info(signals);
|
|
16
30
|
if (process.pid) {
|
package/lib/kook/login.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { setBotConfigByKey, getBotConfigByKey, getToml, writeToml } from '../config/index.js';
|
|
1
|
+
import { setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* 登录配置
|
|
5
4
|
* @param Bcf
|
|
@@ -10,43 +9,12 @@ export async function checkRobotByKOOK() {
|
|
|
10
9
|
/**
|
|
11
10
|
* 读取配置
|
|
12
11
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
12
|
+
const config = getBotConfigByKey('kook');
|
|
13
|
+
if ((config ?? '') !== '' && (config.token ?? '') !== '') {
|
|
14
|
+
setBotConfigByKey('kook', config);
|
|
15
|
+
return true;
|
|
19
16
|
}
|
|
20
17
|
console.info('[LOGIN]', '-----------------------');
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}, 60000);
|
|
24
|
-
const { token } = await prompts([
|
|
25
|
-
{
|
|
26
|
-
type: 'password',
|
|
27
|
-
name: 'token',
|
|
28
|
-
message: 'BotToken: ',
|
|
29
|
-
validate: (value) => value !== '' && typeof value === 'string' ? true : '机器人 token: '
|
|
30
|
-
}
|
|
31
|
-
]).catch((err) => {
|
|
32
|
-
console.error(err);
|
|
33
|
-
process.exit();
|
|
34
|
-
});
|
|
35
|
-
if (!token)
|
|
36
|
-
return false;
|
|
37
|
-
clearTimeout(timeoutId);
|
|
38
|
-
// 得到已变更的配置
|
|
39
|
-
const db = getBotConfigByKey('kook');
|
|
40
|
-
// 得到配置
|
|
41
|
-
const data = getToml();
|
|
42
|
-
data.kook = {
|
|
43
|
-
...db,
|
|
44
|
-
// 覆盖新配置
|
|
45
|
-
token
|
|
46
|
-
};
|
|
47
|
-
// 写入配置
|
|
48
|
-
writeToml(data);
|
|
49
|
-
// 设置配置
|
|
50
|
-
setBotConfigByKey('kook', data.kook);
|
|
51
|
-
return true;
|
|
18
|
+
console.info('[LOGIN]', 'KOOK配置加载失败~');
|
|
19
|
+
process.exit();
|
|
52
20
|
}
|
package/lib/ntqq/index.js
CHANGED
package/lib/ntqq/login.js
CHANGED
|
@@ -1,72 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { NtQQEventsEnum
|
|
1
|
+
import { setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
|
|
2
|
+
import { NtQQEventsEnum } from '../default/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* 登录配置
|
|
5
5
|
* @param Bcf
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
8
|
export async function checkRobotByQQ() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
];
|
|
19
|
-
}
|
|
20
|
-
setBotConfigByKey('ntqq', config);
|
|
21
|
-
return true;
|
|
9
|
+
const config = getBotConfigByKey('ntqq');
|
|
10
|
+
if ((config ?? '') !== '' &&
|
|
11
|
+
(config.appID ?? '') !== '' &&
|
|
12
|
+
(config.token ?? '') !== '') {
|
|
13
|
+
if (!config.intents) {
|
|
14
|
+
config.intents = [
|
|
15
|
+
NtQQEventsEnum.GROUP_AT_MESSAGE_CREATE,
|
|
16
|
+
NtQQEventsEnum.C2C_MESSAGE_CREATE
|
|
17
|
+
];
|
|
22
18
|
}
|
|
19
|
+
setBotConfigByKey('ntqq', config);
|
|
20
|
+
return true;
|
|
23
21
|
}
|
|
24
22
|
console.info('[LOGIN]', '-----------------------');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}, 60000);
|
|
28
|
-
const { appID, token } = await prompts([
|
|
29
|
-
{
|
|
30
|
-
type: 'password',
|
|
31
|
-
name: 'appID',
|
|
32
|
-
message: 'BotAppID: ',
|
|
33
|
-
validate: value => value !== '' && typeof value === 'string' ? true : '机器人 appID: '
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
type: 'password',
|
|
37
|
-
name: 'token',
|
|
38
|
-
message: 'BotToken: ',
|
|
39
|
-
validate: value => value !== '' && typeof value === 'string' ? true : '机器人 token: '
|
|
40
|
-
}
|
|
41
|
-
]).catch((err) => {
|
|
42
|
-
console.error(err);
|
|
43
|
-
process.exit();
|
|
44
|
-
});
|
|
45
|
-
if (!appID || !token) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
clearTimeout(timeoutId);
|
|
49
|
-
/**
|
|
50
|
-
* 默认公域机器人
|
|
51
|
-
*/
|
|
52
|
-
const intents = [
|
|
53
|
-
NtQQEventsEnum.GROUP_AT_MESSAGE_CREATE,
|
|
54
|
-
NtQQEventsEnum.C2C_MESSAGE_CREATE
|
|
55
|
-
];
|
|
56
|
-
// 得到已变更的配置
|
|
57
|
-
const db = getBotConfigByKey('ntqq');
|
|
58
|
-
// 得到配置
|
|
59
|
-
const data = getToml();
|
|
60
|
-
data.ntqq = {
|
|
61
|
-
...db,
|
|
62
|
-
// 覆盖新配置
|
|
63
|
-
appID,
|
|
64
|
-
token,
|
|
65
|
-
intents
|
|
66
|
-
};
|
|
67
|
-
// 写入配置
|
|
68
|
-
writeToml(data);
|
|
69
|
-
// 设置配置
|
|
70
|
-
setBotConfigByKey('ntqq', data.ntqq);
|
|
71
|
-
return true;
|
|
23
|
+
console.info('[LOGIN]', 'ntqq配置加载失败~');
|
|
24
|
+
process.exit();
|
|
72
25
|
}
|
package/lib/ntqq/sdk/wss.js
CHANGED
package/lib/qq/index.js
CHANGED
|
@@ -19,7 +19,11 @@ export async function createAlemonByQQ() {
|
|
|
19
19
|
/**
|
|
20
20
|
* 创建 clientApiByQQ
|
|
21
21
|
*/
|
|
22
|
-
global.clientApiByQQ = createOpenAPI(
|
|
22
|
+
global.clientApiByQQ = createOpenAPI({
|
|
23
|
+
appID: cfg.appID,
|
|
24
|
+
token: cfg.token,
|
|
25
|
+
sandbox: cfg.sandbox ?? false
|
|
26
|
+
});
|
|
23
27
|
/**
|
|
24
28
|
* 设置 qq-channal 配置
|
|
25
29
|
*/
|
|
@@ -33,7 +37,14 @@ export async function createAlemonByQQ() {
|
|
|
33
37
|
/**
|
|
34
38
|
* 创建 websocket
|
|
35
39
|
*/
|
|
36
|
-
const WebsocketClient = createWebsocket(
|
|
40
|
+
const WebsocketClient = createWebsocket({
|
|
41
|
+
appID: cfg.appID,
|
|
42
|
+
token: cfg.token,
|
|
43
|
+
sandbox: cfg.sandbox,
|
|
44
|
+
// shards?:[],
|
|
45
|
+
intents: cfg.intents
|
|
46
|
+
// maxRetry:
|
|
47
|
+
});
|
|
37
48
|
/**
|
|
38
49
|
* 创建 conversation
|
|
39
50
|
*/
|