@nerimity/nerimity.js 1.8.0 → 1.8.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/.vscode/settings.json +4 -1
- package/build/Client.d.ts +9 -7
- package/build/Client.d.ts.map +1 -1
- package/build/Client.js +32 -13
- package/build/Client.js.map +1 -1
- package/build/RPCClient.d.ts +24 -0
- package/build/RPCClient.d.ts.map +1 -0
- package/build/RPCClient.js +72 -0
- package/build/RPCClient.js.map +1 -0
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/examples/rpc.js +19 -0
- package/package.json +4 -2
- package/src/Client.ts +500 -440
- package/src/RPCClient.ts +85 -0
- package/src/index.ts +2 -1
package/src/Client.ts
CHANGED
|
@@ -1,498 +1,558 @@
|
|
|
1
|
-
import EventEmitter from
|
|
2
|
-
import {Socket, io} from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import EventEmitter from "eventemitter3";
|
|
2
|
+
import { Socket, io } from "socket.io-client";
|
|
3
|
+
import {
|
|
4
|
+
ClientEventMap,
|
|
5
|
+
ClientEvents,
|
|
6
|
+
SocketClientEvents,
|
|
7
|
+
SocketServerEvents,
|
|
8
|
+
} from "./EventNames";
|
|
9
|
+
import {
|
|
10
|
+
AuthenticatedPayload,
|
|
11
|
+
ChannelType,
|
|
12
|
+
MessageButtonClickPayload,
|
|
13
|
+
MessageType,
|
|
14
|
+
RawChannel,
|
|
15
|
+
RawMessage,
|
|
16
|
+
RawMessageButton,
|
|
17
|
+
RawServer,
|
|
18
|
+
RawServerMember,
|
|
19
|
+
RawUser,
|
|
20
|
+
} from "./RawData";
|
|
21
|
+
import {
|
|
22
|
+
buttonClickCallback,
|
|
23
|
+
deleteMessage,
|
|
24
|
+
editMessage,
|
|
25
|
+
postMessage,
|
|
26
|
+
} from "./services/MessageService";
|
|
27
|
+
import { path, updatePath } from "./services/serviceEndpoints";
|
|
8
28
|
|
|
9
29
|
export const Events = ClientEvents;
|
|
10
30
|
|
|
11
31
|
export class Client extends EventEmitter<ClientEventMap> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
socket: Socket;
|
|
33
|
+
token: string | undefined;
|
|
34
|
+
user: ClientUser | undefined;
|
|
35
|
+
users: Users;
|
|
36
|
+
channels: Channels;
|
|
37
|
+
servers: Servers;
|
|
38
|
+
|
|
39
|
+
constructor(opts?: { urlOverride?: string }) {
|
|
40
|
+
super();
|
|
41
|
+
if (opts?.urlOverride) {
|
|
42
|
+
updatePath(opts.urlOverride);
|
|
43
|
+
}
|
|
44
|
+
this.socket = io(path, {
|
|
45
|
+
transports: ["websocket"],
|
|
46
|
+
autoConnect: false,
|
|
47
|
+
});
|
|
48
|
+
this.channels = new Channels(this);
|
|
49
|
+
this.users = new Users(this);
|
|
50
|
+
this.servers = new Servers(this);
|
|
51
|
+
new EventHandlers(this);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public login(token: string) {
|
|
55
|
+
this.token = token;
|
|
56
|
+
this.socket.connect();
|
|
57
|
+
}
|
|
38
58
|
}
|
|
39
59
|
|
|
40
|
-
|
|
41
60
|
class EventHandlers {
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
61
|
+
client: Client;
|
|
62
|
+
socket: Socket;
|
|
63
|
+
constructor(client: Client) {
|
|
64
|
+
this.client = client;
|
|
65
|
+
this.socket = client.socket;
|
|
66
|
+
|
|
67
|
+
client.socket.on(SocketServerEvents.CONNECT, this.onConnect.bind(this));
|
|
68
|
+
client.socket.on(
|
|
69
|
+
SocketServerEvents.USER_AUTHENTICATED,
|
|
70
|
+
this.onAuthenticated.bind(this)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
client.socket.on(
|
|
74
|
+
SocketServerEvents.SERVER_MEMBER_JOINED,
|
|
75
|
+
this.onServerMemberJoined.bind(this)
|
|
76
|
+
);
|
|
77
|
+
client.socket.on(
|
|
78
|
+
SocketServerEvents.SERVER_MEMBER_LEFT,
|
|
79
|
+
this.onServerMemberLeft.bind(this)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
client.socket.on(
|
|
83
|
+
SocketServerEvents.SERVER_JOINED,
|
|
84
|
+
this.onServerJoined.bind(this)
|
|
85
|
+
);
|
|
86
|
+
client.socket.on(
|
|
87
|
+
SocketServerEvents.SERVER_CHANNEL_CREATED,
|
|
88
|
+
this.onServerChannelCreated.bind(this)
|
|
89
|
+
);
|
|
90
|
+
client.socket.on(
|
|
91
|
+
SocketServerEvents.SERVER_CHANNEL_UPDATED,
|
|
92
|
+
this.onServerChannelUpdated.bind(this)
|
|
93
|
+
);
|
|
94
|
+
client.socket.on(
|
|
95
|
+
SocketServerEvents.SERVER_CHANNEL_DELETED,
|
|
96
|
+
this.onServerChannelDeleted.bind(this)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
client.socket.on(
|
|
100
|
+
SocketServerEvents.SERVER_LEFT,
|
|
101
|
+
this.onServerLeft.bind(this)
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
client.socket.on(
|
|
105
|
+
SocketServerEvents.MESSAGE_CREATED,
|
|
106
|
+
this.onMessageCreated.bind(this)
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
client.socket.on(
|
|
110
|
+
SocketServerEvents.MESSAGE_BUTTON_CLICKED,
|
|
111
|
+
this.onMessageButtonClicked.bind(this)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
onConnect() {
|
|
115
|
+
this.socket.emit(SocketClientEvents.AUTHENTICATE, {
|
|
116
|
+
token: this.client.token,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
onAuthenticated(payload: AuthenticatedPayload) {
|
|
120
|
+
this.client.user = new ClientUser(this.client, payload.user);
|
|
121
|
+
|
|
122
|
+
for (let i = 0; i < payload.servers.length; i++) {
|
|
123
|
+
const server = payload.servers[i];
|
|
124
|
+
this.client.servers.setCache(server);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (let i = 0; i < payload.channels.length; i++) {
|
|
128
|
+
const rawChannel = payload.channels[i];
|
|
129
|
+
this.client.channels.setCache(rawChannel);
|
|
130
|
+
}
|
|
131
|
+
for (let i = 0; i < payload.serverMembers.length; i++) {
|
|
132
|
+
const member = payload.serverMembers[i];
|
|
133
|
+
this.client.users.setCache(member.user);
|
|
134
|
+
const server = this.client.servers.cache.get(member.serverId);
|
|
135
|
+
server?.members.setCache(member);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.client.emit(ClientEvents.Ready);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
onServerMemberJoined(payload: { serverId: string; member: RawServerMember }) {
|
|
142
|
+
const server = this.client.servers.cache.get(payload.serverId);
|
|
143
|
+
this.client.users.setCache(payload.member.user);
|
|
144
|
+
const member = server?.members.setCache(payload.member);
|
|
145
|
+
if (!member) return;
|
|
146
|
+
this.client.emit("serverMemberJoined", member);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
onServerJoined(payload: {
|
|
150
|
+
server: RawServer;
|
|
151
|
+
members: RawServerMember[];
|
|
152
|
+
channels: RawChannel[];
|
|
153
|
+
// roles: any[];
|
|
154
|
+
// memberPresences: any[]
|
|
155
|
+
// voiceChannelUsers: any[];
|
|
156
|
+
}) {
|
|
157
|
+
const server = this.client.servers.setCache(payload.server);
|
|
158
|
+
|
|
159
|
+
for (let i = 0; i < payload.members.length; i++) {
|
|
160
|
+
const member = payload.members[i];
|
|
161
|
+
this.client.users.setCache(member.user);
|
|
162
|
+
server?.members.setCache(member);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (let i = 0; i < payload.channels.length; i++) {
|
|
166
|
+
const channel = payload.channels[i];
|
|
167
|
+
this.client.channels.setCache(channel);
|
|
168
|
+
}
|
|
169
|
+
this.client.emit(ClientEvents.ServerJoined, server);
|
|
170
|
+
}
|
|
171
|
+
onServerChannelCreated(payload: { serverId: string; channel: RawChannel }) {
|
|
172
|
+
const channel = this.client.channels.setCache(payload.channel);
|
|
173
|
+
this.client.emit(
|
|
174
|
+
ClientEvents.ServerChannelCreated,
|
|
175
|
+
channel as ServerChannel
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
onServerChannelUpdated(payload: {
|
|
179
|
+
serverId: string;
|
|
180
|
+
channelId: string;
|
|
181
|
+
updated: Partial<RawChannel>;
|
|
182
|
+
}) {
|
|
183
|
+
const channel = this.client.channels.cache.get(payload.channelId);
|
|
184
|
+
const updated = payload.updated;
|
|
185
|
+
if (channel) {
|
|
186
|
+
updateClass<ServerChannel>(channel as ServerChannel, updated);
|
|
187
|
+
this.client.emit(
|
|
188
|
+
ClientEvents.ServerChannelUpdated,
|
|
189
|
+
channel as ServerChannel
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
onServerChannelDeleted(payload: { serverId: string; channelId: string }) {
|
|
194
|
+
const channel = this.client.channels.cache.has(payload.channelId);
|
|
195
|
+
if (channel) {
|
|
196
|
+
this.client.channels.cache.delete(payload.channelId);
|
|
197
|
+
this.client.emit(ClientEvents.ServerChannelDeleted, {
|
|
198
|
+
channelId: payload.channelId,
|
|
199
|
+
serverId: payload.serverId,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
onServerLeft(payload: { serverId: string }) {
|
|
204
|
+
const server = this.client.servers.cache.get(payload.serverId);
|
|
205
|
+
if (!server) return;
|
|
206
|
+
this.client.emit(ClientEvents.ServerLeft, server);
|
|
207
|
+
this.client.servers.cache.delete(payload.serverId);
|
|
208
|
+
|
|
209
|
+
this.client.channels.cache.forEach((channel) => {
|
|
210
|
+
if (
|
|
211
|
+
channel instanceof ServerChannel &&
|
|
212
|
+
channel.serverId === payload.serverId
|
|
213
|
+
) {
|
|
214
|
+
this.client.channels.cache.delete(channel.id);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
server.members.cache.clear();
|
|
218
|
+
}
|
|
219
|
+
onServerMemberLeft(payload: { userId: string; serverId: string }) {
|
|
220
|
+
const server = this.client.servers.cache.get(payload.serverId);
|
|
221
|
+
const member = server?.members.cache.get(payload.userId);
|
|
222
|
+
if (!member) return;
|
|
223
|
+
this.client.emit("serverMemberLeft", member);
|
|
224
|
+
server?.members.cache.delete(payload.userId);
|
|
225
|
+
}
|
|
226
|
+
onMessageCreated(payload: { message: RawMessage }) {
|
|
227
|
+
const message = new Message(this.client, payload.message);
|
|
228
|
+
this.client.emit(ClientEvents.MessageCreate, message);
|
|
229
|
+
}
|
|
230
|
+
onMessageButtonClicked(payload: MessageButtonClickPayload) {
|
|
231
|
+
const button = new Button(this.client, payload);
|
|
232
|
+
this.client.emit("messageButtonClick", button);
|
|
233
|
+
}
|
|
171
234
|
}
|
|
172
235
|
|
|
173
|
-
|
|
174
|
-
|
|
175
236
|
export class Users {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
237
|
+
client: Client;
|
|
238
|
+
cache: Collection<string, User>;
|
|
239
|
+
constructor(client: Client) {
|
|
240
|
+
this.client = client;
|
|
241
|
+
this.cache = new Collection();
|
|
242
|
+
}
|
|
243
|
+
setCache(rawUser: RawUser) {
|
|
244
|
+
const user = new User(this.client, rawUser);
|
|
245
|
+
this.cache.set(rawUser.id, user);
|
|
246
|
+
return user;
|
|
247
|
+
}
|
|
186
248
|
}
|
|
187
249
|
|
|
188
|
-
|
|
189
250
|
export class Servers {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
251
|
+
client: Client;
|
|
252
|
+
cache: Collection<string, Server>;
|
|
253
|
+
constructor(client: Client) {
|
|
254
|
+
this.client = client;
|
|
255
|
+
this.cache = new Collection();
|
|
256
|
+
}
|
|
257
|
+
setCache(rawServer: RawServer) {
|
|
258
|
+
const server = new Server(this.client, rawServer);
|
|
259
|
+
this.cache.set(server.id, server);
|
|
260
|
+
return server;
|
|
261
|
+
}
|
|
201
262
|
}
|
|
202
263
|
|
|
203
|
-
|
|
204
|
-
|
|
205
264
|
export class Server {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
265
|
+
client: Client;
|
|
266
|
+
id: string;
|
|
267
|
+
name: string;
|
|
268
|
+
avatar?: string;
|
|
269
|
+
|
|
270
|
+
members: ServerMembers;
|
|
271
|
+
constructor(client: Client, server: RawServer) {
|
|
272
|
+
this.client = client;
|
|
273
|
+
|
|
274
|
+
this.id = server.id;
|
|
275
|
+
this.name = server.name;
|
|
276
|
+
this.avatar = server.avatar;
|
|
277
|
+
this.members = new ServerMembers(this.client);
|
|
278
|
+
}
|
|
220
279
|
}
|
|
221
280
|
|
|
222
281
|
export class ServerMembers {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
282
|
+
client: Client;
|
|
283
|
+
cache: Collection<string, ServerMember>;
|
|
284
|
+
constructor(client: Client) {
|
|
285
|
+
this.client = client;
|
|
286
|
+
this.cache = new Collection();
|
|
287
|
+
}
|
|
288
|
+
setCache(rawMember: RawServerMember) {
|
|
289
|
+
const member = new ServerMember(this.client, rawMember);
|
|
290
|
+
this.cache.set(member.user.id, member);
|
|
291
|
+
return member;
|
|
292
|
+
}
|
|
234
293
|
}
|
|
235
294
|
export class ServerMember {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
295
|
+
client: Client;
|
|
296
|
+
id: string;
|
|
297
|
+
user: User;
|
|
298
|
+
server: Server;
|
|
299
|
+
|
|
300
|
+
constructor(client: Client, member: RawServerMember) {
|
|
301
|
+
this.client = client;
|
|
302
|
+
this.id = member.user.id;
|
|
303
|
+
|
|
304
|
+
this.user = this.client.users.cache.get(member.user.id)!;
|
|
305
|
+
this.server = this.client.servers.cache.get(member.serverId)!;
|
|
306
|
+
}
|
|
307
|
+
toString() {
|
|
308
|
+
return `[@:${this.id}]`;
|
|
309
|
+
}
|
|
251
310
|
}
|
|
252
311
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
312
|
export class Channels {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
313
|
+
client: Client;
|
|
314
|
+
cache: Collection<string, AllChannel>;
|
|
315
|
+
constructor(client: Client) {
|
|
316
|
+
this.client = client;
|
|
317
|
+
this.cache = new Collection();
|
|
318
|
+
}
|
|
319
|
+
setCache(rawChannel: { id: string } & Omit<Partial<RawChannel>, "id">) {
|
|
320
|
+
let channel: AllChannel;
|
|
321
|
+
if (rawChannel.serverId)
|
|
322
|
+
channel = new ServerChannel(this.client, rawChannel as any);
|
|
323
|
+
else channel = new Channel(this.client, rawChannel as any);
|
|
324
|
+
this.cache.set(channel.id, channel);
|
|
325
|
+
return channel;
|
|
326
|
+
}
|
|
271
327
|
}
|
|
272
328
|
|
|
273
|
-
|
|
274
|
-
export type AllChannel = ServerChannel | Channel
|
|
329
|
+
export type AllChannel = ServerChannel | Channel;
|
|
275
330
|
|
|
276
331
|
export interface MessageOpts {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
332
|
+
htmlEmbed?: string;
|
|
333
|
+
buttons?: RawMessageButton[];
|
|
334
|
+
silent?: boolean;
|
|
280
335
|
}
|
|
281
336
|
|
|
282
337
|
export class Channel {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
338
|
+
client: Client;
|
|
339
|
+
id: string;
|
|
340
|
+
|
|
341
|
+
type: ChannelType;
|
|
342
|
+
createdAt?: number;
|
|
343
|
+
lastMessagedAt?: number;
|
|
344
|
+
constructor(client: Client, channel: RawChannel) {
|
|
345
|
+
this.client = client;
|
|
346
|
+
this.id = channel.id;
|
|
347
|
+
this.type = channel.type;
|
|
348
|
+
this.createdAt = channel.createdAt;
|
|
349
|
+
this.lastMessagedAt = channel.lastMessagedAt;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async send(content: string, opts?: MessageOpts) {
|
|
353
|
+
const RawMessage = await postMessage({
|
|
354
|
+
client: this.client,
|
|
355
|
+
channelId: this.id,
|
|
356
|
+
content: content,
|
|
357
|
+
silent: opts?.silent,
|
|
358
|
+
htmlEmbed: opts?.htmlEmbed,
|
|
359
|
+
buttons: opts?.buttons,
|
|
360
|
+
});
|
|
361
|
+
const message = new Message(this.client, RawMessage);
|
|
362
|
+
return message;
|
|
363
|
+
}
|
|
364
|
+
toString() {
|
|
365
|
+
return `[#:${this.id}]`;
|
|
366
|
+
}
|
|
312
367
|
}
|
|
313
368
|
|
|
314
369
|
function updateClass<T extends object>(classInstance: T, update: Partial<T>) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
370
|
+
for (const [key, value] of Object.entries(update) as [
|
|
371
|
+
keyof T,
|
|
372
|
+
T[keyof T]
|
|
373
|
+
][]) {
|
|
374
|
+
classInstance[key] = value;
|
|
375
|
+
}
|
|
318
376
|
}
|
|
319
377
|
|
|
320
378
|
export class ServerChannel extends Channel {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
379
|
+
createdById: string;
|
|
380
|
+
name: string;
|
|
381
|
+
serverId: string;
|
|
382
|
+
permissions: number;
|
|
383
|
+
categoryId?: string;
|
|
384
|
+
server: Server;
|
|
385
|
+
|
|
386
|
+
constructor(client: Client, channel: RawChannel) {
|
|
387
|
+
super(client, channel);
|
|
388
|
+
this.name = channel.name;
|
|
389
|
+
this.permissions = channel.permissions!;
|
|
390
|
+
this.createdById = channel.createdById!;
|
|
391
|
+
this.serverId = channel.serverId!;
|
|
392
|
+
this.categoryId = channel.categoryId!;
|
|
393
|
+
|
|
394
|
+
this.server = this.client.servers.cache.get(this.serverId)!;
|
|
395
|
+
}
|
|
338
396
|
}
|
|
339
397
|
|
|
340
398
|
const UserMentionRegex = /\[@:([0-9]+)\]/gm;
|
|
341
399
|
|
|
342
|
-
|
|
343
|
-
|
|
344
400
|
export class Message {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
401
|
+
client: Client;
|
|
402
|
+
id: string;
|
|
403
|
+
content?: string;
|
|
404
|
+
type: MessageType;
|
|
405
|
+
createdAt: number;
|
|
406
|
+
channelId: string;
|
|
407
|
+
channel: AllChannel;
|
|
408
|
+
user: User;
|
|
409
|
+
mentions: User[] = [];
|
|
410
|
+
constructor(client: Client, message: RawMessage) {
|
|
411
|
+
this.client = client;
|
|
412
|
+
|
|
413
|
+
this.id = message.id;
|
|
414
|
+
this.channelId = message.channelId;
|
|
415
|
+
this.channel = client.channels.cache.get(this.channelId)!;
|
|
416
|
+
this.content = message.content;
|
|
417
|
+
this.type = message.type;
|
|
418
|
+
this.createdAt = message.createdAt;
|
|
419
|
+
this.user = this.client.users.cache.get(message.createdBy.id)!;
|
|
420
|
+
|
|
421
|
+
if (!this.user) {
|
|
422
|
+
this.user = this.client.users.setCache(message.createdBy);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (!this.channel) {
|
|
426
|
+
this.channel = this.client.channels.setCache({
|
|
427
|
+
id: this.channelId,
|
|
428
|
+
type: ChannelType.DM_TEXT,
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (this.content) {
|
|
433
|
+
const mentionIds = [...this.content.matchAll(UserMentionRegex)].map(
|
|
434
|
+
(exp) => exp[1]
|
|
435
|
+
);
|
|
436
|
+
this.mentions = mentionIds
|
|
437
|
+
.map((id) => this.client.users.cache.get(id)!)
|
|
438
|
+
.filter((u) => u);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
reply(content: string, opts?: MessageOpts) {
|
|
442
|
+
return this.channel.send(`${this.user} ${content}`, opts);
|
|
443
|
+
}
|
|
444
|
+
async edit(content: string) {
|
|
445
|
+
const RawMessage = await editMessage({
|
|
446
|
+
client: this.client,
|
|
447
|
+
channelId: this.channel.id,
|
|
448
|
+
messageId: this.id,
|
|
449
|
+
content: content,
|
|
450
|
+
});
|
|
451
|
+
const message = new Message(this.client, RawMessage);
|
|
452
|
+
return message;
|
|
453
|
+
}
|
|
454
|
+
async delete() {
|
|
455
|
+
return deleteMessage({
|
|
456
|
+
channelId: this.channel.id,
|
|
457
|
+
client: this.client,
|
|
458
|
+
messageId: this.id,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
toString() {
|
|
462
|
+
return `[q:${this.id}]`;
|
|
463
|
+
}
|
|
395
464
|
}
|
|
396
465
|
|
|
397
|
-
|
|
398
466
|
class User {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
467
|
+
client: Client;
|
|
468
|
+
id: string;
|
|
469
|
+
avatar?: string;
|
|
470
|
+
banner?: string;
|
|
471
|
+
username: string;
|
|
472
|
+
hexColor: string;
|
|
473
|
+
tag: string;
|
|
474
|
+
badges: number;
|
|
475
|
+
joinedAt?: number;
|
|
476
|
+
bot?: boolean;
|
|
477
|
+
constructor(client: Client, user: RawUser) {
|
|
478
|
+
this.client = client;
|
|
479
|
+
|
|
480
|
+
this.id = user.id;
|
|
481
|
+
this.username = user.username;
|
|
482
|
+
this.tag = user.tag;
|
|
483
|
+
|
|
484
|
+
this.hexColor = user.hexColor;
|
|
485
|
+
this.badges = user.badges;
|
|
486
|
+
this.joinedAt = user.joinedAt;
|
|
487
|
+
this.avatar = user.avatar;
|
|
488
|
+
this.banner = user.banner;
|
|
489
|
+
this.bot = user.bot;
|
|
490
|
+
}
|
|
491
|
+
toString() {
|
|
492
|
+
return `[@:${this.id}]`;
|
|
493
|
+
}
|
|
426
494
|
}
|
|
427
495
|
|
|
428
496
|
export interface ActivityOpts {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
497
|
+
action: string;
|
|
498
|
+
name: string;
|
|
499
|
+
startedAt: number;
|
|
500
|
+
endsAt?: number;
|
|
501
|
+
|
|
502
|
+
imgSrc?: string;
|
|
503
|
+
title?: string;
|
|
504
|
+
subtitle?: string;
|
|
505
|
+
link?: string;
|
|
438
506
|
}
|
|
439
507
|
|
|
440
508
|
class ClientUser extends User {
|
|
509
|
+
setActivity(activity?: ActivityOpts | null) {
|
|
510
|
+
this.client.socket.emit(SocketClientEvents.UPDATE_ACTIVITY, activity);
|
|
511
|
+
}
|
|
441
512
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
constructor(client: Client, user: RawUser) {
|
|
447
|
-
super(client, user);
|
|
448
|
-
}
|
|
513
|
+
constructor(client: Client, user: RawUser) {
|
|
514
|
+
super(client, user);
|
|
515
|
+
}
|
|
449
516
|
}
|
|
450
517
|
|
|
451
|
-
|
|
452
518
|
class Collection<K, V> extends Map<K, V> {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
519
|
+
constructor() {
|
|
520
|
+
super();
|
|
521
|
+
}
|
|
456
522
|
}
|
|
457
523
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
524
|
export class Button {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
525
|
+
client: Client;
|
|
526
|
+
id: string;
|
|
527
|
+
|
|
528
|
+
userId: string;
|
|
529
|
+
messageId: string;
|
|
530
|
+
channelId: string;
|
|
531
|
+
|
|
532
|
+
user?: User;
|
|
533
|
+
channel: Channel;
|
|
534
|
+
|
|
535
|
+
constructor(client: Client, payload: MessageButtonClickPayload) {
|
|
536
|
+
this.client = client;
|
|
537
|
+
|
|
538
|
+
this.id = payload.buttonId;
|
|
539
|
+
this.userId = payload.userId;
|
|
540
|
+
this.channelId = payload.channelId;
|
|
541
|
+
this.messageId = payload.messageId;
|
|
542
|
+
this.user = this.client.users.cache.get(this.userId);
|
|
543
|
+
|
|
544
|
+
this.channel = client.channels.cache.get(this.channelId)!;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
async respond(opts?: { title?: string; content?: string }) {
|
|
548
|
+
await buttonClickCallback({
|
|
549
|
+
client: this.client,
|
|
550
|
+
buttonId: this.id,
|
|
551
|
+
channelId: this.channelId,
|
|
552
|
+
messageId: this.messageId,
|
|
553
|
+
userId: this.userId,
|
|
554
|
+
title: opts?.title,
|
|
555
|
+
content: opts?.content,
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
}
|