alemonjs 1.0.2 → 1.0.4
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 +6 -22
- 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 +8 -0
- package/lib/config/login.js +87 -0
- package/lib/config/pup.js +75 -0
- package/lib/config/types.js +1 -0
- 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/{types.js → default/types.js} +8 -2
- 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 +205 -0
- package/lib/define/map.js +47 -0
- package/lib/define/plugin.js +25 -0
- package/lib/define/types.js +1 -0
- package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +1 -1
- package/lib/discord/index.js +1 -1
- package/lib/discord/login.js +18 -63
- package/lib/index.js +23 -7
- package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +1 -1
- package/lib/kook/index.js +1 -1
- package/lib/kook/login.js +7 -40
- package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +1 -1
- package/lib/ntqq/index.js +2 -2
- package/lib/ntqq/login.js +15 -64
- package/lib/ntqq/sdk/wss.js +0 -1
- package/lib/qq/alemon/conversation.js +1 -1
- package/lib/qq/alemon/message/MESSAGE.js +1 -1
- package/lib/qq/index.js +14 -3
- package/lib/qq/login.js +3 -125
- package/lib/villa/alemon/message/MESSAGES.js +1 -1
- package/lib/villa/index.js +1 -1
- package/lib/villa/login.js +11 -52
- package/package.json +62 -60
- package/types/alemon/dealmsg.d.ts +10 -0
- package/types/config/index.d.ts +8 -0
- package/types/config/pup.d.ts +7 -0
- package/types/config/types.d.ts +18 -0
- 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/define/map.d.ts +12 -0
- package/types/define/plugin.d.ts +4 -0
- package/types/define/types.d.ts +111 -0
- package/types/index.d.ts +17 -2
- package/lib/bot.js +0 -98
- package/lib/config.js +0 -25
- package/lib/login.js +0 -115
- package/types/bot.d.ts +0 -15
- package/types/config.d.ts +0 -12
- package/types/types.d.ts +0 -135
- /package/types/{login.d.ts → config/login.d.ts} +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
* 运行前执行
|
|
42
|
+
* **********
|
|
43
|
+
*/
|
|
44
|
+
if (Options?.command) {
|
|
45
|
+
for await (const item of Options.command) {
|
|
46
|
+
await command(item);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* *******
|
|
51
|
+
* pup配置
|
|
52
|
+
* *******
|
|
53
|
+
*/
|
|
54
|
+
const pCig = { ...PupOptions, ...getPupPath() };
|
|
55
|
+
// 设置旧的值
|
|
56
|
+
setBotConfigByKey('puppeteer', pCig);
|
|
57
|
+
if (Options?.puppeteer) {
|
|
58
|
+
// 存在 替换新的值
|
|
59
|
+
setBotConfigByKey('puppeteer', Options?.puppeteer);
|
|
60
|
+
}
|
|
61
|
+
const pData = getBotConfigByKey('puppeteer');
|
|
62
|
+
await setLanchConfig(pData);
|
|
63
|
+
/**
|
|
64
|
+
* *********
|
|
65
|
+
* mysql配置
|
|
66
|
+
* *********
|
|
67
|
+
*/
|
|
68
|
+
if (Options?.mysql) {
|
|
69
|
+
setBotConfigByKey('mysql', Options.mysql);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* *********
|
|
73
|
+
* redis配置
|
|
74
|
+
* *********
|
|
75
|
+
*/
|
|
76
|
+
if (Options?.redis) {
|
|
77
|
+
setBotConfigByKey('redis', Options.redis);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* *********
|
|
81
|
+
* serer配置
|
|
82
|
+
* *********
|
|
83
|
+
*/
|
|
84
|
+
if (Options?.server) {
|
|
85
|
+
setBotConfigByKey('server', Options.server);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* **********
|
|
89
|
+
* 启动转换器
|
|
90
|
+
* **********
|
|
91
|
+
*/
|
|
92
|
+
const arr = [];
|
|
93
|
+
/**
|
|
94
|
+
* *********
|
|
95
|
+
* 启动机器人
|
|
96
|
+
* *********
|
|
97
|
+
*/
|
|
98
|
+
if (Options?.login) {
|
|
99
|
+
/**
|
|
100
|
+
* ********
|
|
101
|
+
* 配置载入
|
|
102
|
+
* *******
|
|
103
|
+
*/
|
|
104
|
+
if (Options.login?.discord) {
|
|
105
|
+
setBotConfigByKey('discord', Options.login.discord);
|
|
106
|
+
}
|
|
107
|
+
if (Options.login?.qq) {
|
|
108
|
+
setBotConfigByKey('qq', Options.login.qq);
|
|
109
|
+
}
|
|
110
|
+
if (Options.login?.ntqq) {
|
|
111
|
+
setBotConfigByKey('ntqq', Options.login.ntqq);
|
|
112
|
+
}
|
|
113
|
+
if (Options.login?.kook) {
|
|
114
|
+
setBotConfigByKey('kook', Options.login.kook);
|
|
115
|
+
}
|
|
116
|
+
if (Options.login?.villa) {
|
|
117
|
+
setBotConfigByKey('villa', Options.login.villa);
|
|
118
|
+
}
|
|
119
|
+
for (const item in Options.login) {
|
|
120
|
+
if (arr.indexOf(item) != -1)
|
|
121
|
+
continue;
|
|
122
|
+
if (!rebotMap[item])
|
|
123
|
+
continue;
|
|
124
|
+
arr.push(item);
|
|
125
|
+
await rebotMap[item]();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.info('[LOGIN] 无登录配置');
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* ************
|
|
133
|
+
* 迟缓插件加载
|
|
134
|
+
* ************
|
|
135
|
+
*/
|
|
136
|
+
let mount = false;
|
|
137
|
+
if (Options?.app?.component || Options?.app?.module) {
|
|
138
|
+
mount = true;
|
|
139
|
+
}
|
|
140
|
+
const address = Options?.plugin?.directory ?? 'application';
|
|
141
|
+
appDir = address;
|
|
142
|
+
/**
|
|
143
|
+
* ************
|
|
144
|
+
* 设置扫描规则
|
|
145
|
+
* ***********
|
|
146
|
+
*/
|
|
147
|
+
if (Options?.plugin?.RegexOpen || Options?.plugin?.RegexClose) {
|
|
148
|
+
setAppRegex({
|
|
149
|
+
RegexOpen: Options?.plugin?.RegexOpen,
|
|
150
|
+
RegexClose: Options?.plugin?.RegexClose
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* ************
|
|
155
|
+
* 扫描插件
|
|
156
|
+
* ************
|
|
157
|
+
*/
|
|
158
|
+
await loadInit({
|
|
159
|
+
mount: mount,
|
|
160
|
+
address: address == undefined ? '/application' : `/${address}`
|
|
161
|
+
});
|
|
162
|
+
/**
|
|
163
|
+
* ************
|
|
164
|
+
* 编译独立插件
|
|
165
|
+
* ************
|
|
166
|
+
*/
|
|
167
|
+
if (mount) {
|
|
168
|
+
const app = createApp(Options?.app?.name ?? 'bot');
|
|
169
|
+
if (Options?.app?.regJSon?.address) {
|
|
170
|
+
app.setHelp(Options?.app?.regJSon?.address ?? '/public/defset');
|
|
171
|
+
}
|
|
172
|
+
if (Options?.app?.module) {
|
|
173
|
+
const word = await compilationTools({
|
|
174
|
+
aInput: Options?.app?.module?.input ?? 'src/apps/**/*.ts',
|
|
175
|
+
aOutput: Options?.app?.module?.input ?? '.apps/index.js'
|
|
176
|
+
});
|
|
177
|
+
app.component(word);
|
|
178
|
+
}
|
|
179
|
+
if (Options?.app?.component) {
|
|
180
|
+
for await (const item of Options.app.component) {
|
|
181
|
+
app.component(item);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
app.mount('#app');
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* ***************
|
|
188
|
+
* 如果是开发模式
|
|
189
|
+
* 不会执行附加脚本
|
|
190
|
+
* ***************
|
|
191
|
+
*/
|
|
192
|
+
const ars = process.argv.slice(2);
|
|
193
|
+
if (!ars.includes('off')) {
|
|
194
|
+
/**
|
|
195
|
+
* 执行附加脚本
|
|
196
|
+
*/
|
|
197
|
+
if (Options?.scripts) {
|
|
198
|
+
for await (const item of Options.scripts) {
|
|
199
|
+
const name = item?.name ?? 'node';
|
|
200
|
+
nodeScripts(name, item?.file, item?.ars ?? []);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **********
|
|
3
|
+
* 启动机器人
|
|
4
|
+
* **********
|
|
5
|
+
*/
|
|
6
|
+
export const rebotMap = {
|
|
7
|
+
qq: async () => {
|
|
8
|
+
const { createAlemonByQQ: qq } = await import('../qq/index.js');
|
|
9
|
+
return qq().catch(err => {
|
|
10
|
+
console.error(err);
|
|
11
|
+
console.error('QQ机器人启动失败~');
|
|
12
|
+
return false;
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
villa: async () => {
|
|
16
|
+
const { createAlemonByVilla: villa } = await import('../villa/index.js');
|
|
17
|
+
return villa().catch(err => {
|
|
18
|
+
console.error(err);
|
|
19
|
+
console.error('Villa机器人启动失败~');
|
|
20
|
+
return false;
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
kook: async () => {
|
|
24
|
+
const { createAlemonByKOOK: kook } = await import('../kook/index.js');
|
|
25
|
+
return kook().catch(err => {
|
|
26
|
+
console.error(err);
|
|
27
|
+
console.error('KOOK机器人启动失败~');
|
|
28
|
+
return false;
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
discord: async () => {
|
|
32
|
+
const { createAlemonByDiscord: dc } = await import('../discord/index.js');
|
|
33
|
+
return dc().catch(err => {
|
|
34
|
+
console.error(err);
|
|
35
|
+
console.error('Discord机器人启动失败~');
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
ntqq: async () => {
|
|
40
|
+
const { createAlemonByNtqq: ntqq } = await import('../ntqq/index.js');
|
|
41
|
+
return ntqq().catch(err => {
|
|
42
|
+
console.error(err);
|
|
43
|
+
console.error('Ntqq机器人启动失败~');
|
|
44
|
+
return false;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -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 {};
|
|
@@ -2,7 +2,7 @@ import { InstructionMatching } from '../../../alemon/index.js';
|
|
|
2
2
|
import { segmentDiscord } from '../segment.js';
|
|
3
3
|
import { getBotMsgByDiscord } from '../bot.js';
|
|
4
4
|
import { postImage } from '../api.js';
|
|
5
|
-
import { getBotConfigByKey } from '../../../
|
|
5
|
+
import { getBotConfigByKey } from '../../../config/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* 公共
|
|
8
8
|
* @param event
|
package/lib/discord/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Client } from 'discord.js';
|
|
|
2
2
|
import { checkRobotByDiscord } from './login.js';
|
|
3
3
|
import { callBackByDisdord } from './alemon/conversation.js';
|
|
4
4
|
import { setBotMsgByDiscord } from './alemon/bot.js';
|
|
5
|
-
import { getBotConfigByKey } from '../
|
|
5
|
+
import { getBotConfigByKey } from '../config/index.js';
|
|
6
6
|
export async function createAlemonByDiscord() {
|
|
7
7
|
/**
|
|
8
8
|
* 登录
|
package/lib/discord/login.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import prompts from 'prompts';
|
|
2
1
|
import { GatewayIntentBits } from 'discord.js';
|
|
3
|
-
import { setBotConfigByKey, getBotConfigByKey } from '../
|
|
4
|
-
import { getToml, writeToml } from '../config.js';
|
|
2
|
+
import { setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
|
|
5
3
|
/**
|
|
6
4
|
* 登录配置
|
|
7
5
|
* @param Bcf
|
|
@@ -12,69 +10,26 @@ export async function checkRobotByDiscord() {
|
|
|
12
10
|
/**
|
|
13
11
|
* 读取配置
|
|
14
12
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
setBotConfigByKey('discord', config);
|
|
31
|
-
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
|
+
];
|
|
32
26
|
}
|
|
27
|
+
setBotConfigByKey('discord', config);
|
|
28
|
+
return true;
|
|
33
29
|
}
|
|
34
30
|
console.info('[LOGIN]', '-----------------------');
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, 60000);
|
|
38
|
-
const { token } = await prompts([
|
|
39
|
-
{
|
|
40
|
-
type: 'password',
|
|
41
|
-
name: 'token',
|
|
42
|
-
message: 'BotToken: ',
|
|
43
|
-
validate: value => value !== '' && typeof value === 'string' ? true : 'BotToken: '
|
|
44
|
-
}
|
|
45
|
-
]);
|
|
46
|
-
if (!token) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
clearTimeout(timeoutId);
|
|
50
|
-
/**
|
|
51
|
-
* 默认公域机器人
|
|
52
|
-
*/
|
|
53
|
-
const intents = [
|
|
54
|
-
GatewayIntentBits.DirectMessageReactions,
|
|
55
|
-
GatewayIntentBits.DirectMessageTyping,
|
|
56
|
-
GatewayIntentBits.DirectMessages,
|
|
57
|
-
GatewayIntentBits.GuildMessageReactions,
|
|
58
|
-
GatewayIntentBits.GuildMessageTyping,
|
|
59
|
-
GatewayIntentBits.GuildMessages,
|
|
60
|
-
GatewayIntentBits.Guilds,
|
|
61
|
-
GatewayIntentBits.MessageContent // 消息内容
|
|
62
|
-
];
|
|
63
|
-
// 得到已变更的配置
|
|
64
|
-
const db = getBotConfigByKey('discord');
|
|
65
|
-
// 得到配置
|
|
66
|
-
const data = getToml();
|
|
67
|
-
data.discord = {
|
|
68
|
-
...db,
|
|
69
|
-
// 覆盖新配置
|
|
70
|
-
token,
|
|
71
|
-
intents
|
|
72
|
-
};
|
|
73
|
-
// 写入配置
|
|
74
|
-
writeToml(data);
|
|
75
|
-
// 设置配置
|
|
76
|
-
setBotConfigByKey('discord', data.discord);
|
|
77
|
-
return true;
|
|
31
|
+
console.info('[LOGIN]', 'DISCORD配置加载失败~');
|
|
32
|
+
process.exit();
|
|
78
33
|
}
|
|
79
34
|
// GatewayIntentBits.AutoModerationConfiguration, // 自动调节配置
|
|
80
35
|
// GatewayIntentBits.AutoModerationExecution, // 自动调节执行
|
package/lib/index.js
CHANGED
|
@@ -1,14 +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
|
+
*/
|
|
22
|
+
export * from './config/index.js';
|
|
23
|
+
/**
|
|
24
|
+
* *********
|
|
25
|
+
* 监听退出
|
|
26
|
+
* *********
|
|
27
|
+
*/
|
|
12
28
|
process.on('SIGINT', signals => {
|
|
13
29
|
console.info(signals);
|
|
14
30
|
if (process.pid) {
|
|
@@ -2,7 +2,7 @@ import { InstructionMatching } from '../../../alemon/index.js';
|
|
|
2
2
|
import { KOOKApiClient } from 'kook-ws';
|
|
3
3
|
import { segmentKOOK } from '../segment.js';
|
|
4
4
|
import { getBotMsgByKOOK } from '../bot.js';
|
|
5
|
-
import { getBotConfigByKey } from '../../../
|
|
5
|
+
import { getBotConfigByKey } from '../../../config/index.js';
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
* @param event
|
package/lib/kook/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { checkRobotByKOOK } from './login.js';
|
|
|
2
2
|
import { callBackByKOOK } from './alemon/conversation.js';
|
|
3
3
|
import { createClient, KOOKApiClient } from 'kook-ws';
|
|
4
4
|
import { setBotMsgByKOOK } from './alemon/bot.js';
|
|
5
|
-
import { getBotConfigByKey } from '../
|
|
5
|
+
import { getBotConfigByKey } from '../config/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* 创建实例
|
|
8
8
|
* @returns
|
package/lib/kook/login.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
|
|
3
|
-
import { getToml, writeToml } from '../config.js';
|
|
1
|
+
import { setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
|
|
4
2
|
/**
|
|
5
3
|
* 登录配置
|
|
6
4
|
* @param Bcf
|
|
@@ -11,43 +9,12 @@ export async function checkRobotByKOOK() {
|
|
|
11
9
|
/**
|
|
12
10
|
* 读取配置
|
|
13
11
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
12
|
+
const config = getBotConfigByKey('kook');
|
|
13
|
+
if ((config ?? '') !== '' && (config.token ?? '') !== '') {
|
|
14
|
+
setBotConfigByKey('kook', config);
|
|
15
|
+
return true;
|
|
20
16
|
}
|
|
21
17
|
console.info('[LOGIN]', '-----------------------');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, 60000);
|
|
25
|
-
const { token } = await prompts([
|
|
26
|
-
{
|
|
27
|
-
type: 'password',
|
|
28
|
-
name: 'token',
|
|
29
|
-
message: 'BotToken: ',
|
|
30
|
-
validate: (value) => value !== '' && typeof value === 'string' ? true : '机器人 token: '
|
|
31
|
-
}
|
|
32
|
-
]).catch((err) => {
|
|
33
|
-
console.error(err);
|
|
34
|
-
process.exit();
|
|
35
|
-
});
|
|
36
|
-
if (!token)
|
|
37
|
-
return false;
|
|
38
|
-
clearTimeout(timeoutId);
|
|
39
|
-
// 得到已变更的配置
|
|
40
|
-
const db = getBotConfigByKey('kook');
|
|
41
|
-
// 得到配置
|
|
42
|
-
const data = getToml();
|
|
43
|
-
data.kook = {
|
|
44
|
-
...db,
|
|
45
|
-
// 覆盖新配置
|
|
46
|
-
token
|
|
47
|
-
};
|
|
48
|
-
// 写入配置
|
|
49
|
-
writeToml(data);
|
|
50
|
-
// 设置配置
|
|
51
|
-
setBotConfigByKey('kook', data.kook);
|
|
52
|
-
return true;
|
|
18
|
+
console.info('[LOGIN]', 'KOOK配置加载失败~');
|
|
19
|
+
process.exit();
|
|
53
20
|
}
|
|
@@ -2,7 +2,7 @@ import { InstructionMatching } from '../../../alemon/index.js';
|
|
|
2
2
|
import { ClientAPIByQQ as Client, ClinetWeb, getWebConfig } from '../../sdk/index.js';
|
|
3
3
|
import { segmentQQ } from '../segment.js';
|
|
4
4
|
import { getBotMsgByNtqq } from '../bot.js';
|
|
5
|
-
import { getBotConfigByKey } from '../../../
|
|
5
|
+
import { getBotConfigByKey } from '../../../config/index.js';
|
|
6
6
|
import IMGS from 'image-size';
|
|
7
7
|
/**
|
|
8
8
|
* 获取ip
|
package/lib/ntqq/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkRobotByQQ } from './login.js';
|
|
2
|
-
import { getBotConfigByKey } from '../
|
|
2
|
+
import { getBotConfigByKey } from '../config/index.js';
|
|
3
3
|
import { conversation } from './alemon/conversation.js';
|
|
4
4
|
import { setBotConfig, createClient, ClientAPIByQQ, ClinetWeb, getWebConfig } from './sdk/index.js';
|
|
5
5
|
import { createWeb } from './sdk/web/client.js';
|
|
@@ -46,7 +46,7 @@ export async function createAlemonByNtqq() {
|
|
|
46
46
|
/**
|
|
47
47
|
* 创建客户端
|
|
48
48
|
*/
|
|
49
|
-
createClient(conversation);
|
|
49
|
+
createClient(conversation, cfg?.shard ?? [0, 1]);
|
|
50
50
|
/**
|
|
51
51
|
* 创建web端
|
|
52
52
|
*/
|
package/lib/ntqq/login.js
CHANGED
|
@@ -1,74 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { getToml, writeToml } from '../config.js';
|
|
4
|
-
import { NtQQEventsEnum } from '../types.js';
|
|
1
|
+
import { setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
|
|
2
|
+
import { NtQQEventsEnum } from '../default/types.js';
|
|
5
3
|
/**
|
|
6
4
|
* 登录配置
|
|
7
5
|
* @param Bcf
|
|
8
6
|
* @returns
|
|
9
7
|
*/
|
|
10
8
|
export async function checkRobotByQQ() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
];
|
|
21
|
-
}
|
|
22
|
-
setBotConfigByKey('ntqq', config);
|
|
23
|
-
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
|
+
];
|
|
24
18
|
}
|
|
19
|
+
setBotConfigByKey('ntqq', config);
|
|
20
|
+
return true;
|
|
25
21
|
}
|
|
26
22
|
console.info('[LOGIN]', '-----------------------');
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}, 60000);
|
|
30
|
-
const { appID, token } = await prompts([
|
|
31
|
-
{
|
|
32
|
-
type: 'password',
|
|
33
|
-
name: 'appID',
|
|
34
|
-
message: 'BotAppID: ',
|
|
35
|
-
validate: value => value !== '' && typeof value === 'string' ? true : '机器人 appID: '
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
type: 'password',
|
|
39
|
-
name: 'token',
|
|
40
|
-
message: 'BotToken: ',
|
|
41
|
-
validate: value => value !== '' && typeof value === 'string' ? true : '机器人 token: '
|
|
42
|
-
}
|
|
43
|
-
]).catch((err) => {
|
|
44
|
-
console.error(err);
|
|
45
|
-
process.exit();
|
|
46
|
-
});
|
|
47
|
-
if (!appID || !token) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
clearTimeout(timeoutId);
|
|
51
|
-
/**
|
|
52
|
-
* 默认公域机器人
|
|
53
|
-
*/
|
|
54
|
-
const intents = [
|
|
55
|
-
NtQQEventsEnum.GROUP_AT_MESSAGE_CREATE,
|
|
56
|
-
NtQQEventsEnum.C2C_MESSAGE_CREATE
|
|
57
|
-
];
|
|
58
|
-
// 得到已变更的配置
|
|
59
|
-
const db = getBotConfigByKey('ntqq');
|
|
60
|
-
// 得到配置
|
|
61
|
-
const data = getToml();
|
|
62
|
-
data.ntqq = {
|
|
63
|
-
...db,
|
|
64
|
-
// 覆盖新配置
|
|
65
|
-
appID,
|
|
66
|
-
token,
|
|
67
|
-
intents
|
|
68
|
-
};
|
|
69
|
-
// 写入配置
|
|
70
|
-
writeToml(data);
|
|
71
|
-
// 设置配置
|
|
72
|
-
setBotConfigByKey('ntqq', data.ntqq);
|
|
73
|
-
return true;
|
|
23
|
+
console.info('[LOGIN]', 'ntqq配置加载失败~');
|
|
24
|
+
process.exit();
|
|
74
25
|
}
|
package/lib/ntqq/sdk/wss.js
CHANGED
|
@@ -11,7 +11,7 @@ import { MESSAGE_AUDIT } from './message/MESSAGE_AUDIT.js';
|
|
|
11
11
|
import { AUDIO_ACTION } from './message/AUDIO_ACTION.js';
|
|
12
12
|
import { FORUMS_EVENT } from './message/FORUMS_EVENT.js';
|
|
13
13
|
import { setBotMsgByQQ } from './bot.js';
|
|
14
|
-
import { getBotConfigByKey } from '../../
|
|
14
|
+
import { getBotConfigByKey } from '../../config/index.js';
|
|
15
15
|
/**
|
|
16
16
|
* 会话事件分类
|
|
17
17
|
* @param ws
|
|
@@ -3,7 +3,7 @@ import { ClientAPIByQQ as Client } from 'qq-channel';
|
|
|
3
3
|
import { Private } from '../privatechat.js';
|
|
4
4
|
import { segmentQQ } from '../segment.js';
|
|
5
5
|
import { setBotMsgByQQ } from '../bot.js';
|
|
6
|
-
import { getBotConfigByKey } from '../../../
|
|
6
|
+
import { getBotConfigByKey } from '../../../config/index.js';
|
|
7
7
|
/**
|
|
8
8
|
* 公私域合并
|
|
9
9
|
* @param e
|