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,153 @@
|
|
|
1
|
+
import { typeMessage } from '../../../alemon/index.js';
|
|
2
|
+
import { getBotMsgByQQ } from '../bot.js';
|
|
3
|
+
// 非依赖引用
|
|
4
|
+
import { ClientAPIByQQ as Client } from 'qq-channel';
|
|
5
|
+
/**
|
|
6
|
+
GUILD_MEMBERS (1 << 1)
|
|
7
|
+
- GUILD_MEMBER_ADD // 当成员加入时
|
|
8
|
+
- GUILD_MEMBER_UPDATE // 当成员资料变更时
|
|
9
|
+
- GUILD_MEMBER_REMOVE // 当成员被移除时
|
|
10
|
+
*/
|
|
11
|
+
export const GUILD_MEMBERS = async (event) => {
|
|
12
|
+
const Eevent = 'GUILD_MEMBERS';
|
|
13
|
+
let eventType = 'CREATE';
|
|
14
|
+
if (new RegExp(/ADD$/).test(event.eventType)) {
|
|
15
|
+
eventType = 'CREATE';
|
|
16
|
+
}
|
|
17
|
+
else if (new RegExp(/UPDATE$/).test(event.eventType)) {
|
|
18
|
+
eventType = 'UPDATE';
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
eventType = 'DELETE';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 得到频道列表
|
|
25
|
+
*/
|
|
26
|
+
const ChannelsData = await clientApiByQQ.channelApi
|
|
27
|
+
.channels(event.msg.guild_id)
|
|
28
|
+
.then(res => {
|
|
29
|
+
const { data } = res;
|
|
30
|
+
return data;
|
|
31
|
+
})
|
|
32
|
+
.catch(err => {
|
|
33
|
+
console.error(err);
|
|
34
|
+
return false;
|
|
35
|
+
});
|
|
36
|
+
if (typeof ChannelsData == 'boolean') {
|
|
37
|
+
console.info(`\n[${Eevent}] [${eventType}]\n${false}`);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (ChannelsData.length == 0) {
|
|
41
|
+
console.info(`\n[${Eevent}] [${eventType}]\n${false}`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const ChannelData = ChannelsData.find(item => item.type === 0);
|
|
45
|
+
const e = {
|
|
46
|
+
platform: 'qq',
|
|
47
|
+
bot: getBotMsgByQQ(),
|
|
48
|
+
event: Eevent,
|
|
49
|
+
eventType: eventType,
|
|
50
|
+
isPrivate: false,
|
|
51
|
+
isRecall: false,
|
|
52
|
+
isGroup: true,
|
|
53
|
+
/**
|
|
54
|
+
* 发现消息
|
|
55
|
+
* @param msg
|
|
56
|
+
* @param img
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
reply: async (msg, img, name) => {
|
|
60
|
+
if (Buffer.isBuffer(msg)) {
|
|
61
|
+
try {
|
|
62
|
+
return await Client.postImage({
|
|
63
|
+
id: ChannelData.id,
|
|
64
|
+
msg_id: event.msg.id,
|
|
65
|
+
image: msg,
|
|
66
|
+
name: typeof img == 'string' ? img : undefined
|
|
67
|
+
})
|
|
68
|
+
.then(() => true)
|
|
69
|
+
.catch((err) => {
|
|
70
|
+
console.error(err);
|
|
71
|
+
return false;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
console.error(err);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const content = Array.isArray(msg)
|
|
80
|
+
? msg.join('')
|
|
81
|
+
: typeof msg === 'string'
|
|
82
|
+
? msg
|
|
83
|
+
: undefined;
|
|
84
|
+
if (Buffer.isBuffer(img)) {
|
|
85
|
+
try {
|
|
86
|
+
return await Client.postImage({
|
|
87
|
+
id: ChannelData.id,
|
|
88
|
+
msg_id: event.msg.id,
|
|
89
|
+
image: img,
|
|
90
|
+
content,
|
|
91
|
+
name: name
|
|
92
|
+
})
|
|
93
|
+
.then(() => true)
|
|
94
|
+
.catch((err) => {
|
|
95
|
+
console.error(err);
|
|
96
|
+
return false;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error(err);
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 发送文字
|
|
106
|
+
*/
|
|
107
|
+
return await clientApiByQQ.messageApi
|
|
108
|
+
.postMessage(ChannelData.id, {
|
|
109
|
+
content
|
|
110
|
+
})
|
|
111
|
+
.then(() => true)
|
|
112
|
+
.catch((err) => {
|
|
113
|
+
console.error(err);
|
|
114
|
+
return false;
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
replyCard: async (arr) => {
|
|
118
|
+
for (const item of arr) {
|
|
119
|
+
try {
|
|
120
|
+
if (item.type == 'qq_ark' || item.type == 'qq_embed') {
|
|
121
|
+
await clientApiByQQ.messageApi
|
|
122
|
+
.postMessage(event.msg.channel_id, {
|
|
123
|
+
msg_id: event.msg.id,
|
|
124
|
+
...item.card
|
|
125
|
+
})
|
|
126
|
+
.then(() => true)
|
|
127
|
+
.catch((err) => {
|
|
128
|
+
console.error(err);
|
|
129
|
+
return false;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
await typeMessage(e)
|
|
144
|
+
.then(() => {
|
|
145
|
+
console.info(`\n[${e.event}] [${e.eventType}] [${true}]`);
|
|
146
|
+
return true;
|
|
147
|
+
})
|
|
148
|
+
.catch(err => {
|
|
149
|
+
console.error(err);
|
|
150
|
+
console.error(`\n[${e.event}] [${e.eventType}] [${false}]`);
|
|
151
|
+
return false;
|
|
152
|
+
});
|
|
153
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { typeMessage } from '../../../alemon/index.js';
|
|
2
|
+
import { mergeMessages } from './MESSAGE.js';
|
|
3
|
+
import { getBotMsgByQQ } from '../bot.js';
|
|
4
|
+
/**
|
|
5
|
+
* *私域*
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
GUILD_MESSAGES (1 << 9) // 消息事件,仅 *私域* 机器人能够设置此 intents。
|
|
9
|
+
- MESSAGE_CREATE
|
|
10
|
+
// 频道内的全部消息,
|
|
11
|
+
而不只是 at 机器人的消息。
|
|
12
|
+
内容与 AT_MESSAGE_CREATE 相同
|
|
13
|
+
- MESSAGE_DELETE // 删除(撤回)消息事件
|
|
14
|
+
* */
|
|
15
|
+
export const GUILD_MESSAGES = async (event) => {
|
|
16
|
+
const e = {
|
|
17
|
+
platform: 'qq',
|
|
18
|
+
bot: getBotMsgByQQ(),
|
|
19
|
+
event: 'MESSAGES',
|
|
20
|
+
eventType: 'CREATE',
|
|
21
|
+
isPrivate: true,
|
|
22
|
+
isRecall: false,
|
|
23
|
+
isGroup: true
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 撤回消息
|
|
27
|
+
*/
|
|
28
|
+
if (new RegExp(/DELETE$/).test(event.eventType)) {
|
|
29
|
+
e.eventType = 'DELETE';
|
|
30
|
+
e.isRecall = true;
|
|
31
|
+
await typeMessage(e)
|
|
32
|
+
.then(() => {
|
|
33
|
+
console.info(`\n[${e.event}] [${e.eventType}] [${true}]`);
|
|
34
|
+
return true;
|
|
35
|
+
})
|
|
36
|
+
.catch(err => {
|
|
37
|
+
console.error(err);
|
|
38
|
+
console.error(`\n[${e.event}] [${e.eventType}] [${false}]`);
|
|
39
|
+
return false;
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 消息方法
|
|
45
|
+
*/
|
|
46
|
+
mergeMessages(e, event).catch((err) => {
|
|
47
|
+
console.error(err);
|
|
48
|
+
return false;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { typeMessage } from '../../../alemon/index.js';
|
|
2
|
+
import { getBotMsgByQQ } from '../bot.js';
|
|
3
|
+
/**
|
|
4
|
+
* DO
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
GUILD_MESSAGE_REACTIONS (1 << 10)
|
|
8
|
+
- MESSAGE_REACTION_ADD // 为消息添加表情表态
|
|
9
|
+
- MESSAGE_REACTION_REMOVE // 为消息删除表情表态
|
|
10
|
+
*/
|
|
11
|
+
export const GUILD_MESSAGE_REACTIONS = async (event) => {
|
|
12
|
+
const e = {
|
|
13
|
+
platform: 'qq',
|
|
14
|
+
bot: getBotMsgByQQ(),
|
|
15
|
+
event: 'GUILD_MESSAGE_REACTIONS',
|
|
16
|
+
eventType: 'CREATE',
|
|
17
|
+
isPrivate: true,
|
|
18
|
+
isRecall: false,
|
|
19
|
+
isGroup: false
|
|
20
|
+
};
|
|
21
|
+
if (new RegExp(/REMOVE$/).test(event.eventType)) {
|
|
22
|
+
e.eventType = 'DELETE';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 只匹配类型
|
|
26
|
+
*/
|
|
27
|
+
await typeMessage(e)
|
|
28
|
+
.then(() => {
|
|
29
|
+
console.info(`\n[${e.event}] [${e.eventType}] [${true}]`);
|
|
30
|
+
return true;
|
|
31
|
+
})
|
|
32
|
+
.catch(err => {
|
|
33
|
+
console.error(err);
|
|
34
|
+
console.error(`\n[${e.event}] [${e.eventType}] [${false}]`);
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { typeMessage } from '../../../alemon/index.js';
|
|
2
|
+
import { getBotMsgByQQ } from '../bot.js';
|
|
3
|
+
/**
|
|
4
|
+
* DO
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
INTERACTION (1 << 26)
|
|
8
|
+
- INTERACTION_CREATE // 互动事件创建时
|
|
9
|
+
*/
|
|
10
|
+
export const INTERACTION = async (event) => {
|
|
11
|
+
const e = {
|
|
12
|
+
platform: 'qq',
|
|
13
|
+
bot: getBotMsgByQQ(),
|
|
14
|
+
event: 'INTERACTION',
|
|
15
|
+
eventType: 'CREATE',
|
|
16
|
+
isPrivate: false,
|
|
17
|
+
isRecall: false,
|
|
18
|
+
isGroup: false
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 事件匹配
|
|
22
|
+
*/
|
|
23
|
+
if (!new RegExp(/CREATE$/).test(event.eventType)) {
|
|
24
|
+
e.eventType = 'DELETE';
|
|
25
|
+
}
|
|
26
|
+
await typeMessage(e)
|
|
27
|
+
.then(() => {
|
|
28
|
+
console.info(`\n[${e.event}] [${e.eventType}] [${true}]`);
|
|
29
|
+
return true;
|
|
30
|
+
})
|
|
31
|
+
.catch(err => {
|
|
32
|
+
console.error(err);
|
|
33
|
+
console.error(`\n[${e.event}] [${e.eventType}] [${false}]`);
|
|
34
|
+
return false;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { InstructionMatching } from '../../../alemon/index.js';
|
|
2
|
+
import { ClientAPIByQQ as Client } from 'qq-channel';
|
|
3
|
+
import { Private } from '../privatechat.js';
|
|
4
|
+
import { segmentQQ } from '../segment.js';
|
|
5
|
+
import { setBotMsgByQQ } from '../bot.js';
|
|
6
|
+
import { getBotConfigByKey } from '../../../login.js';
|
|
7
|
+
/**
|
|
8
|
+
* 公私域合并
|
|
9
|
+
* @param e
|
|
10
|
+
* @param data 原数据
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export const mergeMessages = async (e, event) => {
|
|
14
|
+
/**
|
|
15
|
+
* 屏蔽其他机器人的消息
|
|
16
|
+
*/
|
|
17
|
+
if (event.msg.author.bot)
|
|
18
|
+
return;
|
|
19
|
+
/**
|
|
20
|
+
* 得到登录配置
|
|
21
|
+
*/
|
|
22
|
+
const cfg = getBotConfigByKey('qq');
|
|
23
|
+
/**
|
|
24
|
+
* 得到主人id
|
|
25
|
+
*/
|
|
26
|
+
const masterID = cfg.masterID;
|
|
27
|
+
/**
|
|
28
|
+
* 默认不是主人
|
|
29
|
+
*/
|
|
30
|
+
e.isMaster = false;
|
|
31
|
+
/**
|
|
32
|
+
* 检查身份
|
|
33
|
+
*/
|
|
34
|
+
if (event.msg.author.id == masterID) {
|
|
35
|
+
/**
|
|
36
|
+
* 是主人
|
|
37
|
+
*/
|
|
38
|
+
e.isMaster = true;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 是群聊
|
|
42
|
+
*/
|
|
43
|
+
e.isGroup = true;
|
|
44
|
+
/**
|
|
45
|
+
* 消息发送机制
|
|
46
|
+
* @param msg 消息
|
|
47
|
+
* @param img
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
e.reply = async (msg, img, name) => {
|
|
51
|
+
if (Buffer.isBuffer(msg)) {
|
|
52
|
+
try {
|
|
53
|
+
return await Client.postImage({
|
|
54
|
+
id: event.msg.channel_id,
|
|
55
|
+
msg_id: event.msg.id,
|
|
56
|
+
image: msg,
|
|
57
|
+
name: typeof img == 'string' ? img : undefined
|
|
58
|
+
})
|
|
59
|
+
.then(() => true)
|
|
60
|
+
.catch((err) => {
|
|
61
|
+
console.error(err);
|
|
62
|
+
return false;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error(err);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const content = Array.isArray(msg)
|
|
71
|
+
? msg.join('')
|
|
72
|
+
: typeof msg === 'string'
|
|
73
|
+
? msg
|
|
74
|
+
: undefined;
|
|
75
|
+
if (Buffer.isBuffer(img)) {
|
|
76
|
+
try {
|
|
77
|
+
return await Client.postImage({
|
|
78
|
+
id: event.msg.channel_id,
|
|
79
|
+
msg_id: event.msg.id,
|
|
80
|
+
image: img,
|
|
81
|
+
content,
|
|
82
|
+
name: name
|
|
83
|
+
})
|
|
84
|
+
.then(() => true)
|
|
85
|
+
.catch((err) => {
|
|
86
|
+
console.error(err);
|
|
87
|
+
return false;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
console.error(err);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 发送接口
|
|
97
|
+
*/
|
|
98
|
+
return await clientApiByQQ.messageApi
|
|
99
|
+
.postMessage(event.msg.channel_id, {
|
|
100
|
+
msg_id: event.msg.id,
|
|
101
|
+
content
|
|
102
|
+
})
|
|
103
|
+
.then(() => true)
|
|
104
|
+
.catch((err) => {
|
|
105
|
+
console.error(err);
|
|
106
|
+
return false;
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
e.replyCard = async (arr) => {
|
|
110
|
+
for (const item of arr) {
|
|
111
|
+
try {
|
|
112
|
+
if (item.type == 'qq_ark' || item.type == 'qq_embed') {
|
|
113
|
+
await clientApiByQQ.messageApi
|
|
114
|
+
.postMessage(event.msg.channel_id, {
|
|
115
|
+
msg_id: event.msg.id,
|
|
116
|
+
...item.card
|
|
117
|
+
})
|
|
118
|
+
.then(() => true)
|
|
119
|
+
.catch((err) => {
|
|
120
|
+
console.error(err);
|
|
121
|
+
return false;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* 引用消息
|
|
136
|
+
* @param mid
|
|
137
|
+
* @param boj
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
e.replyByMid = async (mid, msg) => {
|
|
141
|
+
return await clientApiByQQ.messageApi
|
|
142
|
+
.postMessage(event.msg.channel_id, {
|
|
143
|
+
msg_id: mid,
|
|
144
|
+
content: msg,
|
|
145
|
+
message_reference: { message_id: mid }
|
|
146
|
+
})
|
|
147
|
+
.then(() => true)
|
|
148
|
+
.catch((err) => {
|
|
149
|
+
console.error(err);
|
|
150
|
+
return false;
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* 发送表情表态
|
|
155
|
+
* @param mid
|
|
156
|
+
* @param boj { emoji_type: number; emoji_id: string }
|
|
157
|
+
* @returns
|
|
158
|
+
*/
|
|
159
|
+
e.replyEmoji = async (mid, boj) => {
|
|
160
|
+
return await clientApiByQQ.reactionApi
|
|
161
|
+
.postReaction(event.msg.channel_id, {
|
|
162
|
+
message_id: mid,
|
|
163
|
+
...boj
|
|
164
|
+
})
|
|
165
|
+
.then(() => true)
|
|
166
|
+
.catch((err) => {
|
|
167
|
+
console.error(err);
|
|
168
|
+
return false;
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* 删除表情表态
|
|
173
|
+
* @param mid
|
|
174
|
+
* @param boj { emoji_type: number; emoji_id: string }
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
e.deleteEmoji = async (mid, boj) => {
|
|
178
|
+
return await clientApiByQQ.reactionApi
|
|
179
|
+
.deleteReaction(event.msg.channel_id, {
|
|
180
|
+
message_id: mid,
|
|
181
|
+
...boj
|
|
182
|
+
})
|
|
183
|
+
.then(() => true)
|
|
184
|
+
.catch((err) => {
|
|
185
|
+
console.error(err);
|
|
186
|
+
return false;
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* 消息原文
|
|
191
|
+
*/
|
|
192
|
+
e.msg_txt = event.msg.content;
|
|
193
|
+
/**
|
|
194
|
+
* 消息
|
|
195
|
+
*/
|
|
196
|
+
e.msg = event.msg.content;
|
|
197
|
+
/**
|
|
198
|
+
* 消息编号
|
|
199
|
+
*/
|
|
200
|
+
e.msg_id = event.msg.id;
|
|
201
|
+
/**
|
|
202
|
+
* 用户编号
|
|
203
|
+
*/
|
|
204
|
+
e.user_id = event.msg.author.id;
|
|
205
|
+
/**
|
|
206
|
+
* 用户头像
|
|
207
|
+
*/
|
|
208
|
+
e.user_avatar = event.msg.author.avatar;
|
|
209
|
+
/**
|
|
210
|
+
* 用户名
|
|
211
|
+
*/
|
|
212
|
+
e.user_name = event.msg.author.username;
|
|
213
|
+
/**
|
|
214
|
+
* 子频道编号
|
|
215
|
+
*/
|
|
216
|
+
e.channel_id = event.msg.channel_id;
|
|
217
|
+
/**
|
|
218
|
+
* 频道编号
|
|
219
|
+
*/
|
|
220
|
+
e.guild_id = event.msg.guild_id;
|
|
221
|
+
/**
|
|
222
|
+
* 模块
|
|
223
|
+
*/
|
|
224
|
+
e.segment = segmentQQ;
|
|
225
|
+
/**
|
|
226
|
+
* 被艾特的用户
|
|
227
|
+
*/
|
|
228
|
+
e.at_users = [];
|
|
229
|
+
/**
|
|
230
|
+
* 艾特消息处理
|
|
231
|
+
*/
|
|
232
|
+
e.at = false;
|
|
233
|
+
if (event.msg.mentions) {
|
|
234
|
+
/**
|
|
235
|
+
* 去掉@ 转为纯消息
|
|
236
|
+
*/
|
|
237
|
+
for await (const item of event.msg.mentions) {
|
|
238
|
+
if (item.bot != true) {
|
|
239
|
+
// 用户艾特才会为真
|
|
240
|
+
e.at = true;
|
|
241
|
+
}
|
|
242
|
+
e.at_users.push({
|
|
243
|
+
id: item.id,
|
|
244
|
+
name: item.username,
|
|
245
|
+
avatar: item.avatar,
|
|
246
|
+
bot: item.bot
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 循环删除文本中的at信息并去除前后空格
|
|
251
|
+
*/
|
|
252
|
+
e.at_users.forEach(item => {
|
|
253
|
+
e.msg = e.msg.replace(`<@!${item.id}>`, '').trim();
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 存在at
|
|
258
|
+
*/
|
|
259
|
+
if (e.at) {
|
|
260
|
+
/**
|
|
261
|
+
* 得到第一个艾特
|
|
262
|
+
*/
|
|
263
|
+
e.at_user = e.at_users.find(item => item.bot != true);
|
|
264
|
+
}
|
|
265
|
+
if (e.bot.avatar == 'string') {
|
|
266
|
+
/**
|
|
267
|
+
* 配置一下机器人头像
|
|
268
|
+
*/
|
|
269
|
+
const bot = e.at_users.find(item => item.bot == true && item.id == e.bot.id);
|
|
270
|
+
if (bot) {
|
|
271
|
+
e.bot.avatar = bot.avatar;
|
|
272
|
+
setBotMsgByQQ(bot);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* 公信专私信
|
|
277
|
+
* @param msg
|
|
278
|
+
* @param img
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
e.replyPrivate = async (msg, img, name) => {
|
|
282
|
+
return await Private(event.msg, msg, img)
|
|
283
|
+
.then(res => {
|
|
284
|
+
return res;
|
|
285
|
+
})
|
|
286
|
+
.catch(err => {
|
|
287
|
+
return err;
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* 消息处理
|
|
292
|
+
*/
|
|
293
|
+
await InstructionMatching(e)
|
|
294
|
+
.then(() => {
|
|
295
|
+
console.info(`\n[${e.channel_id}] [${e.user_name}] [${true}] \n ${e.msg_txt}`);
|
|
296
|
+
return;
|
|
297
|
+
})
|
|
298
|
+
.catch((err) => {
|
|
299
|
+
console.error(err);
|
|
300
|
+
console.info(`\n[${e.channel_id}] [${e.user_name}] [${false}] \n ${e.msg_txt}`);
|
|
301
|
+
return;
|
|
302
|
+
});
|
|
303
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { typeMessage } from '../../../alemon/index.js';
|
|
2
|
+
import { getBotMsgByQQ } from '../bot.js';
|
|
3
|
+
/**
|
|
4
|
+
* DO
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
MESSAGE_AUDIT (1 << 27)
|
|
8
|
+
- MESSAGE_AUDIT_PASS // 消息审核通过
|
|
9
|
+
- MESSAGE_AUDIT_REJECT // 消息审核不通过
|
|
10
|
+
*/
|
|
11
|
+
export const MESSAGE_AUDIT = async (event) => {
|
|
12
|
+
const e = {
|
|
13
|
+
platform: 'qq',
|
|
14
|
+
bot: getBotMsgByQQ(),
|
|
15
|
+
event: 'MESSAGE_AUDIT',
|
|
16
|
+
eventType: 'CREATE',
|
|
17
|
+
isPrivate: false,
|
|
18
|
+
isRecall: false,
|
|
19
|
+
isGroup: false
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 事件匹配
|
|
23
|
+
*/
|
|
24
|
+
e.event = 'MESSAGE_AUDIT';
|
|
25
|
+
if (new RegExp(/REJECT$/).test(event.eventType)) {
|
|
26
|
+
e.eventType = 'DELETE';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 只匹配类型
|
|
30
|
+
*/
|
|
31
|
+
await typeMessage(e)
|
|
32
|
+
.then(() => {
|
|
33
|
+
console.info(`\n[${e.event}] [${e.eventType}] [${true}]`);
|
|
34
|
+
return true;
|
|
35
|
+
})
|
|
36
|
+
.catch(err => {
|
|
37
|
+
console.error(err);
|
|
38
|
+
console.error(`\n[${e.event}] [${e.eventType}] [${false}]`);
|
|
39
|
+
return false;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { typeMessage } from '../../../alemon/index.js';
|
|
2
|
+
import { getBotMsgByQQ } from '../bot.js';
|
|
3
|
+
/**
|
|
4
|
+
* ***********
|
|
5
|
+
* 公域可能已删除公域论坛事件
|
|
6
|
+
* ***********
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* DO
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* ***********
|
|
13
|
+
* THREAD 主题 FORUMS_THREAD
|
|
14
|
+
* POST 帖子 FORUMS_POST
|
|
15
|
+
* REPLY 评论 FORUMS_REPLY
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
OPEN_FORUMS_EVENT (1 << 18) // 论坛事件, 此为公域的论坛事件
|
|
19
|
+
|
|
20
|
+
- OPEN_FORUM_THREAD_CREATE // 当用户创建主题时
|
|
21
|
+
- OPEN_FORUM_THREAD_UPDATE // 当用户更新主题时
|
|
22
|
+
- OPEN_FORUM_THREAD_DELETE // 当用户删除主题时
|
|
23
|
+
|
|
24
|
+
- OPEN_FORUM_POST_CREATE // 当用户创建帖子时
|
|
25
|
+
- OPEN_FORUM_POST_DELETE // 当用户删除帖子时
|
|
26
|
+
|
|
27
|
+
- OPEN_FORUM_REPLY_CREATE // 当用户回复评论时
|
|
28
|
+
- OPEN_FORUM_REPLY_DELETE // 当用户删除评论时
|
|
29
|
+
*/
|
|
30
|
+
export const OPEN_FORUMS_EVENT = async (event) => {
|
|
31
|
+
const e = {
|
|
32
|
+
platform: 'qq',
|
|
33
|
+
bot: getBotMsgByQQ(),
|
|
34
|
+
event: 'FORUMS_THREAD',
|
|
35
|
+
eventType: 'CREATE',
|
|
36
|
+
isPrivate: false,
|
|
37
|
+
isRecall: false,
|
|
38
|
+
isGroup: false
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* 事件匹配
|
|
42
|
+
*/
|
|
43
|
+
if (new RegExp(/^OPEN_FORUM_THREAD/).test(event.eventType)) {
|
|
44
|
+
e.event = 'FORUMS_THREAD';
|
|
45
|
+
}
|
|
46
|
+
else if (new RegExp(/^OPEN_FORUM_POST/).test(event.eventType)) {
|
|
47
|
+
e.event = 'FORUMS_POST';
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
e.event = 'FORUMS_REPLY';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 类型匹配
|
|
54
|
+
*/
|
|
55
|
+
if (new RegExp(/CREATE$/).test(event.eventType)) {
|
|
56
|
+
e.eventType = 'CREATE';
|
|
57
|
+
}
|
|
58
|
+
else if (new RegExp(/UPDATE$/).test(event.eventType)) {
|
|
59
|
+
e.eventType = 'UPDATE';
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
e.eventType = 'DELETE';
|
|
63
|
+
}
|
|
64
|
+
await typeMessage(e)
|
|
65
|
+
.then(() => {
|
|
66
|
+
console.info(`\n[${e.event}] [${e.eventType}] [${true}]`);
|
|
67
|
+
return true;
|
|
68
|
+
})
|
|
69
|
+
.catch(err => {
|
|
70
|
+
console.error(err);
|
|
71
|
+
console.error(`\n[${e.event}] [${e.eventType}] [${false}]`);
|
|
72
|
+
return false;
|
|
73
|
+
});
|
|
74
|
+
};
|