alemonjs 1.0.0
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/LICENSE +340 -0
- package/README.md +54 -0
- package/lib/alemon/app.js +38 -0
- package/lib/alemon/apps.js +121 -0
- package/lib/alemon/buffer.js +38 -0
- package/lib/alemon/dealmsg.js +423 -0
- package/lib/alemon/dialogue.js +61 -0
- package/lib/alemon/index.js +40 -0
- package/lib/alemon/message.js +27 -0
- package/lib/alemon/plugin.js +44 -0
- package/lib/alemon/puppeteer.js +226 -0
- package/lib/alemon/qrcode.js +66 -0
- package/lib/alemon/screenshot.js +126 -0
- package/lib/alemon/typings.js +96 -0
- package/lib/config.js +25 -0
- package/lib/discord/alemon/api.js +44 -0
- package/lib/discord/alemon/bot.js +11 -0
- package/lib/discord/alemon/conversation.js +7 -0
- package/lib/discord/alemon/message/PUBLIC_GUILD_MESSAGES.js +185 -0
- package/lib/discord/alemon/segment.js +62 -0
- package/lib/discord/index.js +50 -0
- package/lib/discord/login.js +99 -0
- package/lib/index.js +12 -0
- package/lib/kook/alemon/bot.js +11 -0
- package/lib/kook/alemon/conversation.js +56 -0
- package/lib/kook/alemon/message/PUBLIC_GUILD_MESSAGES.js +195 -0
- package/lib/kook/alemon/segment.js +90 -0
- package/lib/kook/index.js +39 -0
- package/lib/kook/login.js +53 -0
- package/lib/login.js +112 -0
- package/lib/main.js +106 -0
- package/lib/ntqq/alemon/bot.js +11 -0
- package/lib/ntqq/alemon/conversation.js +18 -0
- package/lib/ntqq/alemon/message/C2C_MESSAGE_CREATE.js +142 -0
- package/lib/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.js +218 -0
- package/lib/ntqq/alemon/segment.js +29 -0
- package/lib/ntqq/alemon/types.js +1 -0
- package/lib/ntqq/index.js +77 -0
- package/lib/ntqq/login.js +74 -0
- package/lib/ntqq/sdk/api.js +158 -0
- package/lib/ntqq/sdk/config.js +46 -0
- package/lib/ntqq/sdk/index.js +5 -0
- package/lib/ntqq/sdk/intents.js +69 -0
- package/lib/ntqq/sdk/types.js +1 -0
- package/lib/ntqq/sdk/typings.js +9 -0
- package/lib/ntqq/sdk/web/client.js +89 -0
- package/lib/ntqq/sdk/web/img.js +76 -0
- package/lib/ntqq/sdk/web/index.js +4 -0
- package/lib/ntqq/sdk/web/ip.js +24 -0
- package/lib/ntqq/sdk/wss.js +178 -0
- package/lib/qq/alemon/apidoc.js +216 -0
- package/lib/qq/alemon/bot.js +11 -0
- package/lib/qq/alemon/console.js +13 -0
- package/lib/qq/alemon/conversation.js +139 -0
- package/lib/qq/alemon/doc.js +93 -0
- package/lib/qq/alemon/e.js +41 -0
- package/lib/qq/alemon/message/AUDIO_ACTION.js +57 -0
- package/lib/qq/alemon/message/DIRECT_MESSAGE.js +202 -0
- package/lib/qq/alemon/message/FORUMS_EVENT.js +66 -0
- package/lib/qq/alemon/message/GUILDS.js +65 -0
- package/lib/qq/alemon/message/GUILD_MEMBERS.js +153 -0
- package/lib/qq/alemon/message/GUILD_MESSAGES.js +50 -0
- package/lib/qq/alemon/message/GUILD_MESSAGE_REACTIONS.js +37 -0
- package/lib/qq/alemon/message/INTERACTION.js +36 -0
- package/lib/qq/alemon/message/MESSAGE.js +303 -0
- package/lib/qq/alemon/message/MESSAGE_AUDIT.js +41 -0
- package/lib/qq/alemon/message/OPEN_FORUMS_EVENT.js +74 -0
- package/lib/qq/alemon/message/PUBLIC_GUILD_MESSAGES.js +52 -0
- package/lib/qq/alemon/permissions.js +43 -0
- package/lib/qq/alemon/privatechat.js +78 -0
- package/lib/qq/alemon/segment.js +25 -0
- package/lib/qq/alemon/types.js +25 -0
- package/lib/qq/index.js +44 -0
- package/lib/qq/login.js +151 -0
- package/lib/types.js +5 -0
- package/lib/villa/alemon/conversation.js +48 -0
- package/lib/villa/alemon/message/GUILDS.js +124 -0
- package/lib/villa/alemon/message/GUILD_MEMBERS.js +128 -0
- package/lib/villa/alemon/message/GUILD_MESSAGE_REACTIONS.js +127 -0
- package/lib/villa/alemon/message/MESSAGES.js +334 -0
- package/lib/villa/alemon/message/MESSAGE_AUDIT.js +128 -0
- package/lib/villa/alemon/message/e.js +41 -0
- package/lib/villa/alemon/segment.js +34 -0
- package/lib/villa/index.js +46 -0
- package/lib/villa/login.js +62 -0
- package/package.json +63 -0
- package/types/alemon/app.d.ts +22 -0
- package/types/alemon/apps.d.ts +41 -0
- package/types/alemon/buffer.d.ts +13 -0
- package/types/alemon/dealmsg.d.ts +41 -0
- package/types/alemon/dialogue.d.ts +55 -0
- package/types/alemon/index.d.ts +40 -0
- package/types/alemon/message.d.ts +17 -0
- package/types/alemon/plugin.d.ts +69 -0
- package/types/alemon/puppeteer.d.ts +53 -0
- package/types/alemon/qrcode.d.ts +20 -0
- package/types/alemon/screenshot.d.ts +23 -0
- package/types/alemon/typings.d.ts +525 -0
- package/types/config.d.ts +12 -0
- package/types/discord/alemon/api.d.ts +11 -0
- package/types/discord/alemon/bot.d.ts +6 -0
- package/types/discord/alemon/conversation.d.ts +6 -0
- package/types/discord/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +7 -0
- package/types/discord/alemon/segment.d.ts +46 -0
- package/types/discord/index.d.ts +1 -0
- package/types/discord/login.d.ts +7 -0
- package/types/index.d.ts +6 -0
- package/types/kook/alemon/bot.d.ts +8 -0
- package/types/kook/alemon/conversation.d.ts +7 -0
- package/types/kook/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +6 -0
- package/types/kook/alemon/segment.d.ts +66 -0
- package/types/kook/index.d.ts +5 -0
- package/types/kook/login.d.ts +7 -0
- package/types/login.d.ts +18 -0
- package/types/main.d.ts +15 -0
- package/types/ntqq/alemon/bot.d.ts +8 -0
- package/types/ntqq/alemon/conversation.d.ts +8 -0
- package/types/ntqq/alemon/message/C2C_MESSAGE_CREATE.d.ts +2 -0
- package/types/ntqq/alemon/message/GROUP_AT_MESSAGE_CREATE.d.ts +8 -0
- package/types/ntqq/alemon/segment.d.ts +20 -0
- package/types/ntqq/alemon/types.d.ts +11 -0
- package/types/ntqq/index.d.ts +1 -0
- package/types/ntqq/login.d.ts +6 -0
- package/types/ntqq/sdk/api.d.ts +44 -0
- package/types/ntqq/sdk/config.d.ts +23 -0
- package/types/ntqq/sdk/index.d.ts +5 -0
- package/types/ntqq/sdk/intents.d.ts +2 -0
- package/types/ntqq/sdk/types.d.ts +11 -0
- package/types/ntqq/sdk/typings.d.ts +17 -0
- package/types/ntqq/sdk/web/client.d.ts +8 -0
- package/types/ntqq/sdk/web/img.d.ts +20 -0
- package/types/ntqq/sdk/web/index.d.ts +4 -0
- package/types/ntqq/sdk/web/ip.d.ts +5 -0
- package/types/ntqq/sdk/wss.d.ts +35 -0
- package/types/qq/alemon/apidoc.d.ts +154 -0
- package/types/qq/alemon/bot.d.ts +8 -0
- package/types/qq/alemon/console.d.ts +1 -0
- package/types/qq/alemon/conversation.d.ts +5 -0
- package/types/qq/alemon/doc.d.ts +93 -0
- package/types/qq/alemon/e.d.ts +38 -0
- package/types/qq/alemon/message/AUDIO_ACTION.d.ts +15 -0
- package/types/qq/alemon/message/DIRECT_MESSAGE.d.ts +16 -0
- package/types/qq/alemon/message/FORUMS_EVENT.d.ts +25 -0
- package/types/qq/alemon/message/GUILDS.d.ts +19 -0
- package/types/qq/alemon/message/GUILD_MEMBERS.d.ts +11 -0
- package/types/qq/alemon/message/GUILD_MESSAGES.d.ts +12 -0
- package/types/qq/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +9 -0
- package/types/qq/alemon/message/INTERACTION.d.ts +8 -0
- package/types/qq/alemon/message/MESSAGE.d.ts +16 -0
- package/types/qq/alemon/message/MESSAGE_AUDIT.d.ts +9 -0
- package/types/qq/alemon/message/OPEN_FORUMS_EVENT.d.ts +28 -0
- package/types/qq/alemon/message/PUBLIC_GUILD_MESSAGES.d.ts +12 -0
- package/types/qq/alemon/permissions.d.ts +29 -0
- package/types/qq/alemon/privatechat.d.ts +14 -0
- package/types/qq/alemon/segment.d.ts +19 -0
- package/types/qq/alemon/types.d.ts +82 -0
- package/types/qq/index.d.ts +6 -0
- package/types/qq/login.d.ts +6 -0
- package/types/types.d.ts +85 -0
- package/types/villa/alemon/conversation.d.ts +7 -0
- package/types/villa/alemon/message/GUILDS.d.ts +10 -0
- package/types/villa/alemon/message/GUILD_MEMBERS.d.ts +14 -0
- package/types/villa/alemon/message/GUILD_MESSAGE_REACTIONS.d.ts +7 -0
- package/types/villa/alemon/message/MESSAGES.d.ts +7 -0
- package/types/villa/alemon/message/MESSAGE_AUDIT.d.ts +10 -0
- package/types/villa/alemon/message/e.d.ts +37 -0
- package/types/villa/alemon/segment.d.ts +26 -0
- package/types/villa/index.d.ts +1 -0
- package/types/villa/login.d.ts +7 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { typeMessage } from '../../../alemon/index.js';
|
|
2
|
+
import { mergeMessages } from './MESSAGE.js';
|
|
3
|
+
import { getBotMsgByQQ } from '../bot.js';
|
|
4
|
+
/**
|
|
5
|
+
* *
|
|
6
|
+
* 公域
|
|
7
|
+
* *
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
PUBLIC_GUILD_MESSAGES (1 << 30) // 消息事件,此为公域的消息事件
|
|
11
|
+
AT_MESSAGE_CREATE // 当收到@机器人的消息时
|
|
12
|
+
PUBLIC_MESSAGE_DELETE // 当频道的消息被删除时
|
|
13
|
+
*/
|
|
14
|
+
export const PUBLIC_GUILD_MESSAGES = async (event) => {
|
|
15
|
+
const e = {
|
|
16
|
+
platform: 'qq',
|
|
17
|
+
bot: getBotMsgByQQ(),
|
|
18
|
+
event: 'MESSAGES',
|
|
19
|
+
eventType: 'CREATE',
|
|
20
|
+
isPrivate: false,
|
|
21
|
+
isRecall: false,
|
|
22
|
+
isGroup: true // 群聊
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* 消息撤回
|
|
26
|
+
*/
|
|
27
|
+
if (new RegExp(/DELETE$/).test(event.eventType)) {
|
|
28
|
+
e.eventType = 'DELETE';
|
|
29
|
+
e.isRecall = true;
|
|
30
|
+
await typeMessage(e)
|
|
31
|
+
.then(() => {
|
|
32
|
+
console.info(`\n[${e.event}] [${e.eventType}] [${true}]`);
|
|
33
|
+
return true;
|
|
34
|
+
})
|
|
35
|
+
.catch(err => {
|
|
36
|
+
console.error(err);
|
|
37
|
+
console.error(`\n[${e.event}] [${e.eventType}] [${false}]`);
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 消息创建
|
|
44
|
+
*/
|
|
45
|
+
if (new RegExp(/CREATE$/).test(event.eventType)) {
|
|
46
|
+
mergeMessages(e, event).catch((err) => {
|
|
47
|
+
console.error(err);
|
|
48
|
+
return false;
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { not_permissions, permissions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 得到权限对象
|
|
4
|
+
* @param value 权值
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export function getPermissionsFromValue(value) {
|
|
8
|
+
const look = Boolean(value & permissions.look);
|
|
9
|
+
const manage = Boolean(value & permissions.manage);
|
|
10
|
+
const speak = Boolean(value & permissions.speak);
|
|
11
|
+
const broadcast = Boolean(value & permissions.broadcast);
|
|
12
|
+
return { look, manage, speak, broadcast };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 得到权限对象
|
|
16
|
+
* @param channel_id 频道id
|
|
17
|
+
* @param id 用户id
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export async function channewlPermissions(channel_id, id) {
|
|
21
|
+
/* 自身机器人权限检测 */
|
|
22
|
+
const authority = await clientApiByQQ.channelPermissionsApi
|
|
23
|
+
.channelPermissions(channel_id, id)
|
|
24
|
+
.catch(err => {
|
|
25
|
+
console.error(err);
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
/* 机器人没有权限 */
|
|
29
|
+
if (!authority) {
|
|
30
|
+
return not_permissions;
|
|
31
|
+
}
|
|
32
|
+
const { data: { permissions: botmiss } } = authority;
|
|
33
|
+
/** 错误的解构对象 */
|
|
34
|
+
if (!botmiss) {
|
|
35
|
+
return not_permissions;
|
|
36
|
+
}
|
|
37
|
+
const power = getPermissionsFromValue(botmiss);
|
|
38
|
+
return {
|
|
39
|
+
state: true,
|
|
40
|
+
...power,
|
|
41
|
+
botmiss
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ClientAPIByQQ as Client } from 'qq-channel';
|
|
2
|
+
/**
|
|
3
|
+
* 公信转私信
|
|
4
|
+
* @param EMessage
|
|
5
|
+
* @param msg
|
|
6
|
+
* @param img
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export const Private = async (EMessage, msg, img, name) => {
|
|
10
|
+
const postSessionRes = await clientApiByQQ.directMessageApi
|
|
11
|
+
.createDirectMessage({
|
|
12
|
+
source_guild_id: EMessage.guild_id,
|
|
13
|
+
recipient_id: EMessage.author.id
|
|
14
|
+
})
|
|
15
|
+
.catch((err) => {
|
|
16
|
+
console.error(err);
|
|
17
|
+
return false;
|
|
18
|
+
});
|
|
19
|
+
if (!postSessionRes)
|
|
20
|
+
return false;
|
|
21
|
+
const { data: { guild_id } } = postSessionRes;
|
|
22
|
+
if (!guild_id)
|
|
23
|
+
return false;
|
|
24
|
+
if (Buffer.isBuffer(msg)) {
|
|
25
|
+
try {
|
|
26
|
+
return await Client.postDirectImage({
|
|
27
|
+
id: EMessage.guild_id,
|
|
28
|
+
msg_id: EMessage.id,
|
|
29
|
+
image: msg,
|
|
30
|
+
name: typeof img == 'string' ? img : undefined
|
|
31
|
+
})
|
|
32
|
+
.then(() => true)
|
|
33
|
+
.catch((err) => {
|
|
34
|
+
console.error(err);
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
console.error(err);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const content = Array.isArray(msg)
|
|
44
|
+
? msg.join('')
|
|
45
|
+
: typeof msg === 'string'
|
|
46
|
+
? msg
|
|
47
|
+
: undefined;
|
|
48
|
+
if (Buffer.isBuffer(img)) {
|
|
49
|
+
try {
|
|
50
|
+
return await Client.postDirectImage({
|
|
51
|
+
id: EMessage.guild_id,
|
|
52
|
+
msg_id: EMessage.id,
|
|
53
|
+
image: img,
|
|
54
|
+
content: content,
|
|
55
|
+
name: name
|
|
56
|
+
})
|
|
57
|
+
.then(() => true)
|
|
58
|
+
.catch((err) => {
|
|
59
|
+
console.error(err);
|
|
60
|
+
return false;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
console.error(err);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return await clientApiByQQ.directMessageApi
|
|
69
|
+
.postDirectMessage(guild_id, {
|
|
70
|
+
msg_id: EMessage.id,
|
|
71
|
+
content
|
|
72
|
+
})
|
|
73
|
+
.then(() => true)
|
|
74
|
+
.catch(err => {
|
|
75
|
+
console.error(err);
|
|
76
|
+
return false;
|
|
77
|
+
});
|
|
78
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const segmentQQ = {
|
|
2
|
+
/**
|
|
3
|
+
* 艾特某人
|
|
4
|
+
* @param uid
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
at: function (uid) {
|
|
8
|
+
return `<@!${uid}>`;
|
|
9
|
+
},
|
|
10
|
+
/**
|
|
11
|
+
* 艾特全体
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
atAll: function atAll() {
|
|
15
|
+
return `@everyone`;
|
|
16
|
+
},
|
|
17
|
+
/**
|
|
18
|
+
* 子频道引用
|
|
19
|
+
* @param channel_id
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
atChannel: function (channel_id) {
|
|
23
|
+
return `<#${channel_id}>`;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export var EventTypeDataEnum;
|
|
2
|
+
(function (EventTypeDataEnum) {
|
|
3
|
+
EventTypeDataEnum["AT_MESSAGE_CREATE"] = "AT_MESSAGE_CREATE";
|
|
4
|
+
})(EventTypeDataEnum = EventTypeDataEnum || (EventTypeDataEnum = {}));
|
|
5
|
+
/**
|
|
6
|
+
* 可查看子频道 0x0000000001(1 << 0) 支持指定成员可见类型,支持身份组可见类型
|
|
7
|
+
* 可管理子频道 0x0000000002(1 << 1) 创建者、管理员、子频道管理员都具有此权限
|
|
8
|
+
* 可发言子频道 0x0000000004(1 << 2) 支持指定成员发言类型,支持身份组发言类型
|
|
9
|
+
* 可直播子频道 0x0000000008 (1 << 3) 支持指定成员发起直播,支持身份组发起直播;仅可在直播子频道中设置
|
|
10
|
+
*/
|
|
11
|
+
export const permissions = {
|
|
12
|
+
look: 1,
|
|
13
|
+
manage: 2,
|
|
14
|
+
speak: 4,
|
|
15
|
+
broadcast: 8
|
|
16
|
+
};
|
|
17
|
+
// 权限模板
|
|
18
|
+
export const not_permissions = {
|
|
19
|
+
state: false,
|
|
20
|
+
look: false,
|
|
21
|
+
manage: false,
|
|
22
|
+
speak: false,
|
|
23
|
+
broadcast: false,
|
|
24
|
+
botmiss: 0
|
|
25
|
+
};
|
package/lib/qq/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import './alemon/console.js';
|
|
2
|
+
import { createOpenAPI, createWebsocket } from 'qq-guild-bot';
|
|
3
|
+
import { setBotConfig } from 'qq-channel';
|
|
4
|
+
import { checkRobotByQQ } from './login.js';
|
|
5
|
+
import { createConversationByQQ } from './alemon/conversation.js';
|
|
6
|
+
import { getBotConfigByKey } from '../login.js';
|
|
7
|
+
export async function createAlemonByQQ() {
|
|
8
|
+
/**
|
|
9
|
+
* 登录
|
|
10
|
+
*/
|
|
11
|
+
if (await checkRobotByQQ().catch(err => {
|
|
12
|
+
console.error(err);
|
|
13
|
+
process.exit();
|
|
14
|
+
})) {
|
|
15
|
+
/**
|
|
16
|
+
* 读取配置
|
|
17
|
+
*/
|
|
18
|
+
const cfg = getBotConfigByKey('qq');
|
|
19
|
+
/**
|
|
20
|
+
* 创建 clientApiByQQ
|
|
21
|
+
*/
|
|
22
|
+
global.clientApiByQQ = createOpenAPI(cfg);
|
|
23
|
+
/**
|
|
24
|
+
* 设置 qq-channal 配置
|
|
25
|
+
*/
|
|
26
|
+
setBotConfig({
|
|
27
|
+
token: cfg.token,
|
|
28
|
+
appID: cfg.appID,
|
|
29
|
+
intents: cfg.intents,
|
|
30
|
+
secret: '',
|
|
31
|
+
sandbox: cfg.sandbox
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* 创建 websocket
|
|
35
|
+
*/
|
|
36
|
+
const WebsocketClient = createWebsocket(cfg);
|
|
37
|
+
/**
|
|
38
|
+
* 创建 conversation
|
|
39
|
+
*/
|
|
40
|
+
createConversationByQQ(WebsocketClient);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
package/lib/qq/login.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import prompts from 'prompts';
|
|
2
|
+
import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
|
|
3
|
+
import { setBotConfigByKey, getBotConfigByKey } from '../login.js';
|
|
4
|
+
import { getToml, writeToml } from '../config.js';
|
|
5
|
+
/**
|
|
6
|
+
* 登录配置
|
|
7
|
+
* @param Bcf
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export async function checkRobotByQQ() {
|
|
11
|
+
if (process.argv.indexOf('login') == -1) {
|
|
12
|
+
const config = getBotConfigByKey('qq');
|
|
13
|
+
if ((config ?? '') !== '' &&
|
|
14
|
+
(config.appID ?? '') !== '' &&
|
|
15
|
+
(config.token ?? '') !== '') {
|
|
16
|
+
if (!config.intents) {
|
|
17
|
+
config.intents = [
|
|
18
|
+
AvailableIntentsEventsEnum.GUILDS,
|
|
19
|
+
AvailableIntentsEventsEnum.PUBLIC_GUILD_MESSAGES,
|
|
20
|
+
AvailableIntentsEventsEnum.DIRECT_MESSAGE,
|
|
21
|
+
AvailableIntentsEventsEnum.GUILD_MEMBERS
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
setBotConfigByKey('qq', config);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
console.info('[LOGIN]', '-----------------------');
|
|
29
|
+
console.info('[LOGIN]', '推荐将机器人设置', '订阅推送', '打开');
|
|
30
|
+
console.info('[LOGIN]', '推荐将机器人设置', '私聊权限', '打开');
|
|
31
|
+
console.info('[LOGIN]', '非管理类机器推荐', '普通成员', '身份');
|
|
32
|
+
console.info('[LOGIN]', '-----------------------');
|
|
33
|
+
console.info('[LOGIN]', '退出重来?可按', '[CTRL+C]');
|
|
34
|
+
console.info('[LOGIN]', '更改登录?执行', 'npm run login');
|
|
35
|
+
console.info('[LOGIN]', '-----------------------');
|
|
36
|
+
const timeoutId = setTimeout(() => {
|
|
37
|
+
throw '超过1分钟未完成登录';
|
|
38
|
+
}, 60000);
|
|
39
|
+
const { appID, token, inputBot, imputDev } = await prompts([
|
|
40
|
+
{
|
|
41
|
+
type: 'password',
|
|
42
|
+
name: 'appID',
|
|
43
|
+
message: 'BotAppID: ',
|
|
44
|
+
validate: value => value !== '' && typeof value === 'string' ? true : '机器人 appID: '
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'password',
|
|
48
|
+
name: 'token',
|
|
49
|
+
message: 'BotToken: ',
|
|
50
|
+
validate: value => value !== '' && typeof value === 'string' ? true : '机器人 token: '
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'select',
|
|
54
|
+
name: 'inputBot',
|
|
55
|
+
message: '请选择机器人类型 :',
|
|
56
|
+
choices: [
|
|
57
|
+
{ title: '公域', value: '0' },
|
|
58
|
+
{ title: '私域', value: '1' }
|
|
59
|
+
],
|
|
60
|
+
/**
|
|
61
|
+
* 默认公域
|
|
62
|
+
*/
|
|
63
|
+
initial: 0
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'select',
|
|
67
|
+
name: 'imputDev',
|
|
68
|
+
message: '请选择机器人环境 :',
|
|
69
|
+
choices: [
|
|
70
|
+
{ title: '部署环境', value: '0' },
|
|
71
|
+
{ title: '开发环境', value: '1' }
|
|
72
|
+
],
|
|
73
|
+
/**
|
|
74
|
+
* 默认部署
|
|
75
|
+
*/
|
|
76
|
+
initial: 0
|
|
77
|
+
}
|
|
78
|
+
]).catch((err) => {
|
|
79
|
+
console.error(err);
|
|
80
|
+
process.exit();
|
|
81
|
+
});
|
|
82
|
+
if (!appID || !token || !inputBot || !imputDev) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
clearTimeout(timeoutId);
|
|
86
|
+
/**
|
|
87
|
+
* 默认公域机器人
|
|
88
|
+
*/
|
|
89
|
+
let intents = [
|
|
90
|
+
AvailableIntentsEventsEnum.GUILDS,
|
|
91
|
+
AvailableIntentsEventsEnum.GUILD_MEMBERS,
|
|
92
|
+
AvailableIntentsEventsEnum.DIRECT_MESSAGE,
|
|
93
|
+
/**
|
|
94
|
+
* 公域特有
|
|
95
|
+
*/
|
|
96
|
+
AvailableIntentsEventsEnum.PUBLIC_GUILD_MESSAGES //公域事件
|
|
97
|
+
];
|
|
98
|
+
/**
|
|
99
|
+
* 默认公域机器人
|
|
100
|
+
*/
|
|
101
|
+
let isPrivate = false;
|
|
102
|
+
if (inputBot == '1') {
|
|
103
|
+
/**
|
|
104
|
+
* 私域机器人
|
|
105
|
+
*/
|
|
106
|
+
intents = [
|
|
107
|
+
AvailableIntentsEventsEnum.GUILDS,
|
|
108
|
+
AvailableIntentsEventsEnum.GUILD_MEMBERS,
|
|
109
|
+
AvailableIntentsEventsEnum.DIRECT_MESSAGE,
|
|
110
|
+
/**
|
|
111
|
+
* 需申请的
|
|
112
|
+
*/
|
|
113
|
+
AvailableIntentsEventsEnum.AUDIO_ACTION,
|
|
114
|
+
AvailableIntentsEventsEnum.MESSAGE_AUDIT,
|
|
115
|
+
AvailableIntentsEventsEnum.INTERACTION,
|
|
116
|
+
AvailableIntentsEventsEnum.GUILD_MESSAGE_REACTIONS,
|
|
117
|
+
/**
|
|
118
|
+
* 私域特有
|
|
119
|
+
*/
|
|
120
|
+
AvailableIntentsEventsEnum.GUILD_MESSAGES,
|
|
121
|
+
AvailableIntentsEventsEnum.FORUMS_EVENT //私域论坛
|
|
122
|
+
];
|
|
123
|
+
/**
|
|
124
|
+
* 私域机器人
|
|
125
|
+
*/
|
|
126
|
+
isPrivate = true;
|
|
127
|
+
}
|
|
128
|
+
// 默认部署
|
|
129
|
+
let sandbox = false;
|
|
130
|
+
// 开发环境
|
|
131
|
+
if (imputDev == '1')
|
|
132
|
+
sandbox = true;
|
|
133
|
+
// 得到已变更的配置
|
|
134
|
+
const db = getBotConfigByKey('qq');
|
|
135
|
+
// 得到配置
|
|
136
|
+
const data = getToml();
|
|
137
|
+
data.qq = {
|
|
138
|
+
...db,
|
|
139
|
+
// 覆盖新配置
|
|
140
|
+
appID,
|
|
141
|
+
token,
|
|
142
|
+
intents,
|
|
143
|
+
isPrivate,
|
|
144
|
+
sandbox
|
|
145
|
+
};
|
|
146
|
+
// 写入配置
|
|
147
|
+
writeToml(data);
|
|
148
|
+
// 设置配置
|
|
149
|
+
setBotConfigByKey('qq', data.qq);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MESSAGES_VILLA } from './message/MESSAGES.js';
|
|
2
|
+
import { GUILD_MEMBERS_VILLA } from './message/GUILD_MEMBERS.js';
|
|
3
|
+
import { GUILD_MESSAGE_REACTIONS_VILLA } from './message/GUILD_MESSAGE_REACTIONS.js';
|
|
4
|
+
import { MESSAGE_AUDIT_VILLA } from './message/MESSAGE_AUDIT.js';
|
|
5
|
+
import { GUILDS_VILLA } from './message/GUILDS.js';
|
|
6
|
+
/**
|
|
7
|
+
* 事件处理集
|
|
8
|
+
*/
|
|
9
|
+
const ConversationMap = {
|
|
10
|
+
/**
|
|
11
|
+
* 房间消息--成员进出
|
|
12
|
+
*/
|
|
13
|
+
[1]: GUILD_MEMBERS_VILLA,
|
|
14
|
+
/**
|
|
15
|
+
* 会话消息
|
|
16
|
+
*/
|
|
17
|
+
[2]: MESSAGES_VILLA,
|
|
18
|
+
/**
|
|
19
|
+
* 别野消息--机器人进入
|
|
20
|
+
*/
|
|
21
|
+
[3]: GUILDS_VILLA,
|
|
22
|
+
/**
|
|
23
|
+
* 别野消息--机器人退出
|
|
24
|
+
*/
|
|
25
|
+
[4]: GUILDS_VILLA,
|
|
26
|
+
/**
|
|
27
|
+
* 表情表态
|
|
28
|
+
*/
|
|
29
|
+
[5]: GUILD_MESSAGE_REACTIONS_VILLA,
|
|
30
|
+
/**
|
|
31
|
+
* 审核事件
|
|
32
|
+
*/
|
|
33
|
+
[6]: MESSAGE_AUDIT_VILLA
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* 消息接收入口
|
|
37
|
+
* @param req
|
|
38
|
+
* @param res
|
|
39
|
+
*/
|
|
40
|
+
export async function callBackByVilla(event) {
|
|
41
|
+
if (Object.prototype.hasOwnProperty.call(ConversationMap, event.type)) {
|
|
42
|
+
return await ConversationMap[event.type](event);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// console.info('[新事件触发]', event.type)
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { typeMessage } from '../../../alemon/index.js';
|
|
2
|
+
import { segmentVilla } from '../segment.js';
|
|
3
|
+
import { now_e } from './e.js';
|
|
4
|
+
/**
|
|
5
|
+
* 涉及房间的接口不可用
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 机器人进出
|
|
9
|
+
* @param event 回调数据
|
|
10
|
+
* @param val 类型控制
|
|
11
|
+
*/
|
|
12
|
+
export async function GUILDS_VILLA(event) {
|
|
13
|
+
/**
|
|
14
|
+
* 别野编号
|
|
15
|
+
*/
|
|
16
|
+
const villa_id = event.robot.villa_id ?? '';
|
|
17
|
+
/**
|
|
18
|
+
* 制作e消息对象
|
|
19
|
+
*/
|
|
20
|
+
const e = {
|
|
21
|
+
platform: 'villa',
|
|
22
|
+
/**
|
|
23
|
+
* 机器人信息
|
|
24
|
+
*/
|
|
25
|
+
bot: {
|
|
26
|
+
id: event.robot.template.id,
|
|
27
|
+
name: event.robot.template.name,
|
|
28
|
+
avatar: event.robot.template.icon
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* 事件类型
|
|
32
|
+
*/
|
|
33
|
+
event: 'GUILD',
|
|
34
|
+
/**
|
|
35
|
+
* 消息类型
|
|
36
|
+
*/
|
|
37
|
+
eventType: event.type == 3 ? 'CREATE' : 'DELETE',
|
|
38
|
+
/**
|
|
39
|
+
* 是否是私域
|
|
40
|
+
*/
|
|
41
|
+
isPrivate: false,
|
|
42
|
+
/**
|
|
43
|
+
* 是否是群聊
|
|
44
|
+
*/
|
|
45
|
+
isGroup: true,
|
|
46
|
+
/**
|
|
47
|
+
* 是否是撤回
|
|
48
|
+
*/
|
|
49
|
+
isRecall: false,
|
|
50
|
+
/**
|
|
51
|
+
* 艾特得到的qq
|
|
52
|
+
*/
|
|
53
|
+
at_users: [],
|
|
54
|
+
/**
|
|
55
|
+
* 是否是艾特
|
|
56
|
+
*/
|
|
57
|
+
at: false,
|
|
58
|
+
/**
|
|
59
|
+
* 是否是机器人主人
|
|
60
|
+
*/
|
|
61
|
+
isMaster: false,
|
|
62
|
+
/**
|
|
63
|
+
* 去除了艾特后的消息
|
|
64
|
+
*/
|
|
65
|
+
msg: '',
|
|
66
|
+
/**
|
|
67
|
+
* 别野编号
|
|
68
|
+
*/
|
|
69
|
+
msg_id: event.id,
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
at_user: undefined,
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
guild_id: String(villa_id),
|
|
78
|
+
/**
|
|
79
|
+
* 房间编号
|
|
80
|
+
*/
|
|
81
|
+
channel_id: '',
|
|
82
|
+
/**
|
|
83
|
+
* 消息原文
|
|
84
|
+
*/
|
|
85
|
+
msg_txt: '',
|
|
86
|
+
/**
|
|
87
|
+
* 用户编号
|
|
88
|
+
*/
|
|
89
|
+
user_id: '',
|
|
90
|
+
/**
|
|
91
|
+
* 用户名
|
|
92
|
+
*/
|
|
93
|
+
user_name: '',
|
|
94
|
+
/**
|
|
95
|
+
* 消息触发时间
|
|
96
|
+
*/
|
|
97
|
+
msg_create_time: new Date().getTime(),
|
|
98
|
+
/**
|
|
99
|
+
* 模板函数
|
|
100
|
+
*/
|
|
101
|
+
segment: segmentVilla,
|
|
102
|
+
/**
|
|
103
|
+
* 用户头像
|
|
104
|
+
*/
|
|
105
|
+
user_avatar: '',
|
|
106
|
+
...now_e,
|
|
107
|
+
reply: async (msg, img, name) => {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* 只匹配类型
|
|
113
|
+
*/
|
|
114
|
+
await typeMessage(e)
|
|
115
|
+
.then(() => {
|
|
116
|
+
console.info(`\n[${e.event}] [${e.eventType}] [${true}] `);
|
|
117
|
+
return true;
|
|
118
|
+
})
|
|
119
|
+
.catch(err => {
|
|
120
|
+
console.error(`\n[${e.event}] [${e.eventType}] [${false}] `);
|
|
121
|
+
console.error(err);
|
|
122
|
+
return false;
|
|
123
|
+
});
|
|
124
|
+
}
|