@alemonjs/bubble 2.1.0-alpha.1 → 2.1.0-alpha.2
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 +8 -8
- package/lib/index.js +48 -62
- package/lib/sdk/types.d.ts +13 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,30 +18,30 @@ yarn add @alemonjs/bubble
|
|
|
18
18
|
bubble:
|
|
19
19
|
# Bot Token(必填)
|
|
20
20
|
token: 'YOUR_BOT_TOKEN'
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
# WebSocket Gateway URL(可选,默认: wss://bubble.alemonjs.com/api/bot/gateway)
|
|
23
23
|
GATEWAY_URL: 'wss://bubble.alemonjs.com/api/bot/gateway'
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
# API Base URL(可选,默认: https://bubble.alemonjs.com/api/bot/v1)
|
|
26
26
|
API_URL: 'https://bubble.alemonjs.com/api/bot/v1'
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
# CDN Base URL(可选,默认: https://bubble-oss-files.alemonjs.com)
|
|
29
29
|
CDN_URL: 'https://bubble-oss-files.alemonjs.com'
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
# 订阅的事件类型(可选,默认: 所有可用事件)
|
|
32
32
|
intent:
|
|
33
33
|
- MESSAGE_CREATE
|
|
34
34
|
- DM_MESSAGE_CREATE
|
|
35
35
|
- GUILD_MEMBER_ADD
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
# 主人配置(可选)
|
|
38
38
|
master_key: []
|
|
39
39
|
master_id: []
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
# 代理配置(可选)
|
|
42
42
|
websocket_proxy: ''
|
|
43
43
|
request_proxy: ''
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
# 客户端名称(可选,默认: alemonjs-bot)
|
|
46
46
|
clientName: 'alemonjs-bot'
|
|
47
47
|
```
|
|
@@ -75,4 +75,4 @@ bubble:
|
|
|
75
75
|
- `BOT_READY` - 机器人就绪
|
|
76
76
|
- `EVENTS_SUBSCRIBED` - 事件订阅成功
|
|
77
77
|
- `EVENTS_UNSUBSCRIBED` - 事件取消订阅成功
|
|
78
|
-
- `SUBSCRIBE_DENIED` - 订阅被拒绝
|
|
78
|
+
- `SUBSCRIBE_DENIED` - 订阅被拒绝
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const main = () => {
|
|
|
17
17
|
return `${CDN_URL}/${avatar}`;
|
|
18
18
|
};
|
|
19
19
|
client.on('MESSAGE_CREATE', event => {
|
|
20
|
-
if (event.author?.
|
|
20
|
+
if (event.author?.is_bot) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const atUsers = [];
|
|
@@ -30,51 +30,51 @@ const main = () => {
|
|
|
30
30
|
for (const item of atUsers) {
|
|
31
31
|
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
32
32
|
}
|
|
33
|
-
const UserId = String(event.
|
|
33
|
+
const UserId = String(event.authorId);
|
|
34
34
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
35
|
-
const UserAvatar = createUserAvatar(UserId, event
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
35
|
+
const UserAvatar = createUserAvatar(UserId, event?.author?.avatar);
|
|
36
|
+
const e = {
|
|
37
|
+
name: 'message.create',
|
|
38
|
+
Platform: platform,
|
|
39
|
+
GuildId: String(event.channelId || ''),
|
|
40
|
+
ChannelId: String(event.channelId || ''),
|
|
41
|
+
SpaceId: String(event.channelId || ''),
|
|
42
|
+
UserId: UserId,
|
|
43
|
+
UserKey,
|
|
44
|
+
UserName: event?.author?.username,
|
|
45
|
+
UserAvatar: UserAvatar,
|
|
46
|
+
IsMaster: isMaster,
|
|
47
|
+
IsBot: false,
|
|
48
|
+
OpenId: UserId,
|
|
49
|
+
MessageId: String(event.id),
|
|
50
|
+
MessageText: msg,
|
|
51
|
+
CreateAt: Date.now(),
|
|
52
|
+
tag: 'message.create',
|
|
53
|
+
value: event
|
|
54
|
+
};
|
|
55
|
+
cbp.send(e);
|
|
56
|
+
});
|
|
57
|
+
client.on('DM_MESSAGE_CREATE', event => {
|
|
58
|
+
const UserId = String(event.authorId);
|
|
59
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
60
|
+
const UserAvatar = createUserAvatar(UserId, event?.author?.avatar);
|
|
61
|
+
const e = {
|
|
62
|
+
name: 'private.message.create',
|
|
63
|
+
Platform: platform,
|
|
64
|
+
UserId: UserId,
|
|
65
|
+
UserKey,
|
|
66
|
+
UserName: event?.author?.username,
|
|
67
|
+
UserAvatar: UserAvatar,
|
|
68
|
+
IsMaster: isMaster,
|
|
69
|
+
IsBot: false,
|
|
70
|
+
OpenId: UserId,
|
|
71
|
+
MessageId: String(event.id),
|
|
72
|
+
MessageText: event.content,
|
|
73
|
+
CreateAt: Date.now(),
|
|
74
|
+
tag: 'private.message.create',
|
|
75
|
+
value: event
|
|
76
|
+
};
|
|
77
|
+
cbp.send(e);
|
|
78
78
|
});
|
|
79
79
|
const api = {
|
|
80
80
|
active: {
|
|
@@ -96,27 +96,13 @@ const main = () => {
|
|
|
96
96
|
}
|
|
97
97
|
const tag = event.tag;
|
|
98
98
|
if (tag === 'message.create') {
|
|
99
|
-
const ChannelId = String(event.value.
|
|
99
|
+
const ChannelId = String(event.value.channelId || '');
|
|
100
100
|
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
101
101
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
102
102
|
}
|
|
103
103
|
else if (tag === 'private.message.create') {
|
|
104
|
-
const UserId = String(event.value.
|
|
105
|
-
const ChannelId = String(event.value.
|
|
106
|
-
const res = await senduser(client, {
|
|
107
|
-
channel_id: ChannelId,
|
|
108
|
-
author_id: UserId
|
|
109
|
-
}, val);
|
|
110
|
-
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
111
|
-
}
|
|
112
|
-
else if (tag === 'interaction.create') {
|
|
113
|
-
const ChannelId = String(event.value.channel_id || '');
|
|
114
|
-
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
115
|
-
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
116
|
-
}
|
|
117
|
-
else if (tag === 'private.interaction.create') {
|
|
118
|
-
const UserId = String(event.value.user.id || '');
|
|
119
|
-
const ChannelId = String(event.value.channel_id || '');
|
|
104
|
+
const UserId = String(event.value.authorId || '');
|
|
105
|
+
const ChannelId = String(event.value.channelId || '');
|
|
120
106
|
const res = await senduser(client, {
|
|
121
107
|
channel_id: ChannelId,
|
|
122
108
|
author_id: UserId
|
package/lib/sdk/types.d.ts
CHANGED
|
@@ -30,23 +30,23 @@ export interface BaseMessage {
|
|
|
30
30
|
id: string | number;
|
|
31
31
|
content: string;
|
|
32
32
|
type?: string | number;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
author
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
channelId?: string | number;
|
|
34
|
+
guildId?: string | number;
|
|
35
|
+
authorId?: string | number;
|
|
36
|
+
author: {
|
|
37
|
+
id: number;
|
|
38
|
+
is_bot?: boolean;
|
|
39
|
+
avatar?: string | null;
|
|
40
|
+
username: string;
|
|
41
|
+
};
|
|
42
|
+
attachment?: Attachment[];
|
|
43
|
+
createdAt?: string;
|
|
41
44
|
}
|
|
42
45
|
export interface MessageCreateEvent extends BaseMessage {
|
|
43
|
-
|
|
44
|
-
nickname?: string;
|
|
45
|
-
roles?: number[];
|
|
46
|
-
};
|
|
46
|
+
mentions?: any[];
|
|
47
47
|
}
|
|
48
48
|
export interface DmMessageCreateEvent extends BaseMessage {
|
|
49
|
-
|
|
49
|
+
threadId?: string | number;
|
|
50
50
|
}
|
|
51
51
|
export type MessageUpdateEvent = BaseMessage;
|
|
52
52
|
export interface MessageDeleteEvent {
|
|
@@ -110,18 +110,5 @@ export interface FileQuota {
|
|
|
110
110
|
}
|
|
111
111
|
export interface BubbleEventMap {
|
|
112
112
|
MESSAGE_CREATE: MessageCreateEvent;
|
|
113
|
-
MESSAGE_UPDATE: MessageUpdateEvent;
|
|
114
|
-
MESSAGE_DELETE: MessageDeleteEvent;
|
|
115
|
-
MESSAGE_UNPIN: MessageDeleteEvent;
|
|
116
113
|
DM_MESSAGE_CREATE: DmMessageCreateEvent;
|
|
117
|
-
DM_MESSAGE_UPDATE: DmMessageCreateEvent;
|
|
118
|
-
DM_MESSAGE_DELETE: MessageDeleteEvent;
|
|
119
|
-
DM_MESSAGE_UNPIN: MessageDeleteEvent;
|
|
120
|
-
GUILD_MEMBER_ADD: GuildMemberEvent;
|
|
121
|
-
GUILD_MEMBER_UPDATE: GuildMemberEvent;
|
|
122
|
-
GUILD_MEMBER_REMOVE: GuildMemberEvent;
|
|
123
|
-
BOT_READY: BotReadyEvent;
|
|
124
|
-
EVENTS_SUBSCRIBED: EventsSubscribedEvent;
|
|
125
|
-
EVENTS_UNSUBSCRIBED: EventsUnsubscribedEvent;
|
|
126
|
-
SUBSCRIBE_DENIED: SubscribeDeniedEvent;
|
|
127
114
|
}
|