beniocord.js 2.0.9 → 2.1.1
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/Client.js +211 -39
- package/README.md +55 -45
- package/package.json +1 -1
- package/structures/Channel.js +65 -1
- package/structures/Emoji.js +47 -2
- package/structures/Message.js +89 -2
- package/structures/MessageCollector.js +73 -19
- package/structures/User.js +55 -8
- package/structures/Util.js +115 -55
package/Client.js
CHANGED
|
@@ -10,30 +10,60 @@ const User = require("./structures/User");
|
|
|
10
10
|
const Channel = require("./structures/Channel");
|
|
11
11
|
const Emoji = require("./structures/Emoji");
|
|
12
12
|
const { MessageEmbed, MessageAttachment } = require("./structures/Util");
|
|
13
|
-
|
|
14
|
-
class ClientError extends Error {
|
|
15
|
-
constructor(message, code) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.name = 'ClientError';
|
|
18
|
-
this.code = code;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
13
|
+
const { formatUrl } = require("./helpers");
|
|
21
14
|
|
|
22
15
|
let global = {
|
|
23
16
|
token: "",
|
|
24
17
|
apiUrl: "https://api-bots.beniocord.site"
|
|
25
18
|
};
|
|
26
19
|
|
|
27
|
-
/**
|
|
28
|
-
* @fires Client#ready
|
|
29
|
-
* @fires Client#messageCreate
|
|
30
|
-
* @fires Client#messageDelete
|
|
31
|
-
* @fires Client#messageEdit
|
|
32
|
-
* @fires Client#error
|
|
33
|
-
* @fires Client#disconnect
|
|
34
|
-
* @fires Client#reconnect
|
|
35
|
-
*/
|
|
36
20
|
class Client extends EventEmitter {
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {Object} ClientEvents
|
|
23
|
+
* @property {User} ready - Fired when the client finishes connecting
|
|
24
|
+
* @property {Message} messageCreate - Fired when a new message is created
|
|
25
|
+
* @property {Message} messageUpdate - Fired when a message is updated
|
|
26
|
+
* @property {Message} messageDelete - Fired when a message is deleted
|
|
27
|
+
* @property {Channel} channelCreate - Fired when a new channel is created
|
|
28
|
+
* @property {Channel} channelDelete - Fired when a channel is deleted
|
|
29
|
+
* @property {Channel} channelUpdate - Fired when a channel is updated
|
|
30
|
+
* @property {{channel: Channel, member: User}} channelMemberAdd - Fired when a member joins a channel
|
|
31
|
+
* @property {{channel: Channel, member: User}} channelMemberRemove - Fired when a member leaves a channel
|
|
32
|
+
* @property {User} channelMemberUpdate - Fired when a member updates their info in a channel
|
|
33
|
+
* @property {Emoji} emojiCreate - Fired when a new emoji is created
|
|
34
|
+
* @property {Emoji} emojiDelete - Fired when an emoji is deleted
|
|
35
|
+
* @property {Error} error - Fired when an error occurs
|
|
36
|
+
* @property {void} disconnect - Fired when disconnected from the gateway
|
|
37
|
+
* @property {void} reconnect - Fired when reconnecting to the gateway
|
|
38
|
+
*
|
|
39
|
+
* @fires Client#ready
|
|
40
|
+
* @fires Client#messageCreate
|
|
41
|
+
* @fires Client#messageDelete
|
|
42
|
+
* @fires Client#messageEdit
|
|
43
|
+
* @fires Client#error
|
|
44
|
+
* @fires Client#disconnect
|
|
45
|
+
* @fires Client#reconnect
|
|
46
|
+
* @fires Client#emojiCreate
|
|
47
|
+
* @fires Client#emojiDelete
|
|
48
|
+
* @fires Client#stickerCreate
|
|
49
|
+
* @fires Client#stickerDelete
|
|
50
|
+
* @fires Client#channelCreate
|
|
51
|
+
* @fires Client#channelDelete
|
|
52
|
+
* @fires Client#channelUpdate
|
|
53
|
+
* @fires Client#channelMemberAdd
|
|
54
|
+
* @fires Client#channelMemberRemove
|
|
55
|
+
* @fires Client#channelMemberUpdate
|
|
56
|
+
* @fires Client#typingStart
|
|
57
|
+
* @fires Client#typingStop
|
|
58
|
+
* @class Client
|
|
59
|
+
* @description The main class of BenioCord.js, responsible for managing API communication and bot events.
|
|
60
|
+
* @param {Object} options - Opções de configuração do cliente
|
|
61
|
+
* @param {string} options.token - Token do bot para autenticação
|
|
62
|
+
* @example
|
|
63
|
+
* const Beniocord = require('beniocord.js');
|
|
64
|
+
* const client = new Beniocord({ token: 'YOUR_BOT_TOKEN' });
|
|
65
|
+
* client.login();
|
|
66
|
+
*/
|
|
37
67
|
constructor({ token }) {
|
|
38
68
|
super();
|
|
39
69
|
|
|
@@ -50,6 +80,7 @@ class Client extends EventEmitter {
|
|
|
50
80
|
this.isConnected = false;
|
|
51
81
|
this.isReady = false;
|
|
52
82
|
this.status = 'online';
|
|
83
|
+
this.version = require('./package.json').version;
|
|
53
84
|
|
|
54
85
|
// Configuration options
|
|
55
86
|
this.config = {
|
|
@@ -141,6 +172,10 @@ class Client extends EventEmitter {
|
|
|
141
172
|
await this._joinAllChannelRooms();
|
|
142
173
|
|
|
143
174
|
this.isReady = true;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @event Client#ready
|
|
178
|
+
*/
|
|
144
179
|
this.emit("ready", this.user);
|
|
145
180
|
|
|
146
181
|
return this.user;
|
|
@@ -159,7 +194,8 @@ class Client extends EventEmitter {
|
|
|
159
194
|
}
|
|
160
195
|
|
|
161
196
|
/**
|
|
162
|
-
*
|
|
197
|
+
* Kills the connection to the server
|
|
198
|
+
* @returns {void}
|
|
163
199
|
*/
|
|
164
200
|
disconnect() {
|
|
165
201
|
this._stopHeartbeat();
|
|
@@ -198,10 +234,14 @@ class Client extends EventEmitter {
|
|
|
198
234
|
/**
|
|
199
235
|
* Sets the bot's status
|
|
200
236
|
* @param {string} status - Status: "online", "away", "dnd", "offline"
|
|
237
|
+
* @returns {Promise<Object>}
|
|
238
|
+
* @example
|
|
239
|
+
* client.setStatus("dnd").then((data) => {
|
|
240
|
+
* console.log("Status updated:", data);
|
|
241
|
+
* });
|
|
201
242
|
*/
|
|
202
243
|
async setStatus(status) {
|
|
203
244
|
const validStatuses = ["online", "offline", "away", "dnd"];
|
|
204
|
-
|
|
205
245
|
if (!validStatuses.includes(status)) {
|
|
206
246
|
throw new ClientError(
|
|
207
247
|
`Invalid status. Valid statuses are: ${validStatuses.join(", ")}`,
|
|
@@ -211,12 +251,19 @@ class Client extends EventEmitter {
|
|
|
211
251
|
|
|
212
252
|
this._ensureConnected();
|
|
213
253
|
this.status = status;
|
|
214
|
-
|
|
254
|
+
|
|
255
|
+
return new Promise((resolve) => {
|
|
256
|
+
this.socket.once('user:status-update', (data) => {
|
|
257
|
+
resolve(data);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
this.socket.emit('status:update', { status });
|
|
261
|
+
});
|
|
215
262
|
}
|
|
216
263
|
|
|
217
264
|
/**
|
|
218
265
|
* Fetches information about the bot user
|
|
219
|
-
* @param {boolean} force - Force fetch from API instead of cache
|
|
266
|
+
* @param {boolean} [force=false] - Force fetch from API instead of cache
|
|
220
267
|
* @returns {Promise<User>} Bot user object
|
|
221
268
|
*/
|
|
222
269
|
async fetchMe(force = false) {
|
|
@@ -240,7 +287,7 @@ class Client extends EventEmitter {
|
|
|
240
287
|
/**
|
|
241
288
|
* Fetches a user by ID
|
|
242
289
|
* @param {string} id - User ID
|
|
243
|
-
* @param {boolean} force - Force fetch from API instead of cache
|
|
290
|
+
* @param {boolean} [force=false] - Force fetch from API instead of cache
|
|
244
291
|
* @returns {Promise<User>} User object
|
|
245
292
|
*/
|
|
246
293
|
async fetchUser(id, force = false) {
|
|
@@ -286,7 +333,7 @@ class Client extends EventEmitter {
|
|
|
286
333
|
/**
|
|
287
334
|
* Fetches a specific channel by ID
|
|
288
335
|
* @param {string} id - Channel ID
|
|
289
|
-
* @param {boolean} force - Force fetch from API instead of cache
|
|
336
|
+
* @param {boolean} [force=false] - Force fetch from API instead of cache
|
|
290
337
|
* @returns {Promise<Channel>} Channel object
|
|
291
338
|
*/
|
|
292
339
|
async fetchChannel(id, force = false) {
|
|
@@ -409,7 +456,7 @@ class Client extends EventEmitter {
|
|
|
409
456
|
* Adds a member to a channel
|
|
410
457
|
* @param {string} channelId - Channel ID
|
|
411
458
|
* @param {string} userId - User ID to add
|
|
412
|
-
* @param {string} role - Member role (default: 'member')
|
|
459
|
+
* @param {string} [role] - Member role (default: 'member')
|
|
413
460
|
* @returns {Promise<Object>} Response data
|
|
414
461
|
*/
|
|
415
462
|
async addChannelMember(channelId, userId, role = 'member') {
|
|
@@ -665,9 +712,43 @@ class Client extends EventEmitter {
|
|
|
665
712
|
async fetchMessage(channelId, messageId) {
|
|
666
713
|
try {
|
|
667
714
|
const res = await this._axios.get(`/api/channels/${channelId}/messages/${messageId}`);
|
|
668
|
-
|
|
715
|
+
const raw = res.data;
|
|
716
|
+
|
|
717
|
+
// --- USER ---
|
|
718
|
+
const userData = {
|
|
719
|
+
id: raw.user_id,
|
|
720
|
+
username: raw.username,
|
|
721
|
+
display_name: raw.display_name,
|
|
722
|
+
avatar_url: raw.avatar_url,
|
|
723
|
+
status: raw.status || 'online',
|
|
724
|
+
emblems: raw.emblems || [],
|
|
725
|
+
is_bot: raw.is_bot ?? false,
|
|
726
|
+
last_seen: raw.last_seen ?? raw.created_at,
|
|
727
|
+
created_at: raw.created_at,
|
|
728
|
+
};
|
|
729
|
+
const messageData = { ...raw, user: userData };
|
|
730
|
+
|
|
731
|
+
// Cria a mensagem
|
|
732
|
+
const message = new Message(messageData, this);
|
|
733
|
+
|
|
734
|
+
// Cache do author
|
|
735
|
+
if (message.author) this.cache.users.set(message.author.id, message.author);
|
|
736
|
+
|
|
737
|
+
// --- CHANNEL ---
|
|
738
|
+
if (!message.channel && raw.channel_id) {
|
|
739
|
+
// Tenta pegar da cache
|
|
740
|
+
let channel = this.cache.channels.get(raw.channel_id);
|
|
741
|
+
if (!channel) {
|
|
742
|
+
channel = await this.fetchChannel(raw.channel_id);
|
|
743
|
+
}
|
|
744
|
+
message.channel = channel;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
return message;
|
|
669
748
|
} catch (error) {
|
|
670
|
-
throw error instanceof ClientError
|
|
749
|
+
throw error instanceof ClientError
|
|
750
|
+
? error
|
|
751
|
+
: new ClientError(error.message, "FETCH_MESSAGE_ERROR");
|
|
671
752
|
}
|
|
672
753
|
}
|
|
673
754
|
|
|
@@ -678,6 +759,7 @@ class Client extends EventEmitter {
|
|
|
678
759
|
/**
|
|
679
760
|
* Starts typing indicator in a channel
|
|
680
761
|
* @param {string} channelId - Channel ID
|
|
762
|
+
* @returns {void}
|
|
681
763
|
*/
|
|
682
764
|
startTyping(channelId) {
|
|
683
765
|
try {
|
|
@@ -691,6 +773,7 @@ class Client extends EventEmitter {
|
|
|
691
773
|
/**
|
|
692
774
|
* Stops typing indicator in a channel
|
|
693
775
|
* @param {string} channelId - Channel ID
|
|
776
|
+
* @returns {void}
|
|
694
777
|
*/
|
|
695
778
|
stopTyping(channelId) {
|
|
696
779
|
try {
|
|
@@ -708,7 +791,7 @@ class Client extends EventEmitter {
|
|
|
708
791
|
/**
|
|
709
792
|
* Fetches an emoji by ID
|
|
710
793
|
* @param {string} id - Emoji ID
|
|
711
|
-
* @param {boolean} force - Force fetch from API instead of cache
|
|
794
|
+
* @param {boolean} [force=false] - Force fetch from API instead of cache
|
|
712
795
|
* @returns {Promise<Emoji>} Emoji object
|
|
713
796
|
*/
|
|
714
797
|
async fetchEmoji(id, force = false) {
|
|
@@ -731,13 +814,12 @@ class Client extends EventEmitter {
|
|
|
731
814
|
/**
|
|
732
815
|
* Fetches all available emojis
|
|
733
816
|
* @param {Object} options - Fetch options
|
|
734
|
-
* @param {boolean} options.includeOthers - Include emojis from other users
|
|
735
817
|
* @param {string} options.search - Search query
|
|
736
818
|
* @returns {Promise<Emoji[]>} Array of emoji objects
|
|
737
819
|
*/
|
|
738
820
|
async fetchAllEmojis(options = {}) {
|
|
739
821
|
try {
|
|
740
|
-
const endpoint =
|
|
822
|
+
const endpoint = '/api/emojis/all';
|
|
741
823
|
const params = {};
|
|
742
824
|
|
|
743
825
|
if (options.search) {
|
|
@@ -745,7 +827,9 @@ class Client extends EventEmitter {
|
|
|
745
827
|
}
|
|
746
828
|
|
|
747
829
|
const res = await this._axios.get(endpoint, { params });
|
|
830
|
+
|
|
748
831
|
const emojis = res.data.map(e => {
|
|
832
|
+
if (!e.user_id) e.user_id = this.user.id;
|
|
749
833
|
const emoji = new Emoji(e);
|
|
750
834
|
this.cache.emojis.set(emoji.id, emoji);
|
|
751
835
|
return emoji;
|
|
@@ -753,14 +837,16 @@ class Client extends EventEmitter {
|
|
|
753
837
|
|
|
754
838
|
return emojis;
|
|
755
839
|
} catch (error) {
|
|
756
|
-
throw error instanceof ClientError
|
|
840
|
+
throw error instanceof ClientError
|
|
841
|
+
? error
|
|
842
|
+
: new ClientError(error.message, "FETCH_EMOJIS_ERROR");
|
|
757
843
|
}
|
|
758
844
|
}
|
|
759
845
|
|
|
760
846
|
/**
|
|
761
847
|
* Fetches a sticker by ID
|
|
762
848
|
* @param {string} id - Sticker ID
|
|
763
|
-
* @param {boolean} force - Force fetch from API instead of cache
|
|
849
|
+
* @param {boolean} [force=false] - Force fetch from API instead of cache
|
|
764
850
|
* @returns {Promise<Object>} Sticker data
|
|
765
851
|
*/
|
|
766
852
|
async fetchSticker(id, force = false) {
|
|
@@ -834,6 +920,7 @@ class Client extends EventEmitter {
|
|
|
834
920
|
|
|
835
921
|
/**
|
|
836
922
|
* Clears all cached data
|
|
923
|
+
* @returns {void}
|
|
837
924
|
*/
|
|
838
925
|
clearCache() {
|
|
839
926
|
this.cache.users.clear();
|
|
@@ -930,7 +1017,7 @@ class Client extends EventEmitter {
|
|
|
930
1017
|
});
|
|
931
1018
|
|
|
932
1019
|
this.socket.on("reconnect_error", (error) => {
|
|
933
|
-
this.emit("
|
|
1020
|
+
this.emit("error", error);
|
|
934
1021
|
});
|
|
935
1022
|
|
|
936
1023
|
this.socket.on("reconnect_failed", () => {
|
|
@@ -968,6 +1055,9 @@ class Client extends EventEmitter {
|
|
|
968
1055
|
_setupSocketHandlers() {
|
|
969
1056
|
this._removeSocketHandlers();
|
|
970
1057
|
|
|
1058
|
+
/**
|
|
1059
|
+
* @event Client#messageCreate
|
|
1060
|
+
*/
|
|
971
1061
|
this.socket.on('message:new', async (data) => {
|
|
972
1062
|
try {
|
|
973
1063
|
if (this._sentMessages.has(data.id)) {
|
|
@@ -983,31 +1073,49 @@ class Client extends EventEmitter {
|
|
|
983
1073
|
}
|
|
984
1074
|
});
|
|
985
1075
|
|
|
1076
|
+
/**
|
|
1077
|
+
* @event Client#messageDelete
|
|
1078
|
+
*/
|
|
986
1079
|
this.socket.on('message:deleted', (data) => {
|
|
987
1080
|
const { messageId } = data;
|
|
988
1081
|
this._markMessageDeleted(messageId);
|
|
989
1082
|
this.emit('messageDelete', data);
|
|
990
1083
|
});
|
|
991
1084
|
|
|
1085
|
+
/**
|
|
1086
|
+
* @event Client#messageEdit
|
|
1087
|
+
*/
|
|
992
1088
|
this.socket.on('message:edited', (data) => {
|
|
993
1089
|
const { messageId, content, editedAt } = data;
|
|
994
1090
|
this._updateMessageContent(messageId, content, editedAt);
|
|
995
1091
|
this.emit('messageEdit', data);
|
|
996
1092
|
});
|
|
997
1093
|
|
|
1094
|
+
/**
|
|
1095
|
+
* @event Client#typingStart
|
|
1096
|
+
*/
|
|
998
1097
|
this.socket.on('typing:user-start', (data) => {
|
|
999
1098
|
this.emit('typingStart', data);
|
|
1000
1099
|
});
|
|
1001
1100
|
|
|
1101
|
+
/**
|
|
1102
|
+
* @event Client#typingStop
|
|
1103
|
+
*/
|
|
1002
1104
|
this.socket.on('typing:user-stop', (data) => {
|
|
1003
1105
|
this.emit('typingStop', data);
|
|
1004
1106
|
});
|
|
1005
1107
|
|
|
1108
|
+
/**
|
|
1109
|
+
* @event Client#userStatusUpdate
|
|
1110
|
+
*/
|
|
1006
1111
|
this.socket.on('user:status-update', (data) => {
|
|
1007
1112
|
this._updateUserStatus(data);
|
|
1008
1113
|
this.emit('userStatusUpdate', data);
|
|
1009
1114
|
});
|
|
1010
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* @event Client#memberJoin
|
|
1118
|
+
*/
|
|
1011
1119
|
this.socket.on('member:join', async (data) => {
|
|
1012
1120
|
const member = await this.fetchUser(data.memberId).catch(() => null);
|
|
1013
1121
|
const channel = this.cache.channels.get(data.channelId);
|
|
@@ -1017,6 +1125,9 @@ class Client extends EventEmitter {
|
|
|
1017
1125
|
this.emit('memberJoin', { channel, member });
|
|
1018
1126
|
});
|
|
1019
1127
|
|
|
1128
|
+
/**
|
|
1129
|
+
* @event Client#memberLeave
|
|
1130
|
+
*/
|
|
1020
1131
|
this.socket.on('member:leave', async (data) => {
|
|
1021
1132
|
const channel = this.cache.channels.get(data.channelId);
|
|
1022
1133
|
const member = this.cache.users.get(data.memberId);
|
|
@@ -1032,16 +1143,25 @@ class Client extends EventEmitter {
|
|
|
1032
1143
|
this.emit('memberLeave', { channel, member });
|
|
1033
1144
|
});
|
|
1034
1145
|
|
|
1146
|
+
/**
|
|
1147
|
+
* @event Client#channelUpdate
|
|
1148
|
+
*/
|
|
1035
1149
|
this.socket.on('channel:update', (data) => {
|
|
1036
1150
|
this._updateChannel(data);
|
|
1037
1151
|
this.emit('channelUpdate', data);
|
|
1038
1152
|
});
|
|
1039
1153
|
|
|
1154
|
+
/**
|
|
1155
|
+
* @event Client#channelDelete
|
|
1156
|
+
*/
|
|
1040
1157
|
this.socket.on('channel:delete', (data) => {
|
|
1041
1158
|
this.cache.channels.delete(data.channelId);
|
|
1042
1159
|
this.emit('channelDelete', data);
|
|
1043
1160
|
});
|
|
1044
1161
|
|
|
1162
|
+
/**
|
|
1163
|
+
* @event Client#rateLimited
|
|
1164
|
+
*/
|
|
1045
1165
|
this.socket.on('rate:limited', (data) => {
|
|
1046
1166
|
this.emit('rateLimited', data);
|
|
1047
1167
|
});
|
|
@@ -1183,12 +1303,21 @@ class Client extends EventEmitter {
|
|
|
1183
1303
|
const msg = new Message(data, this);
|
|
1184
1304
|
|
|
1185
1305
|
if (!msg.author && data.user_id) {
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
username
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1306
|
+
const cachedUser = this.cache.users.get(data.user_id);
|
|
1307
|
+
if (cachedUser) {
|
|
1308
|
+
cachedUser.username = data.username || cachedUser.username;
|
|
1309
|
+
cachedUser.displayName = data.display_name || cachedUser.displayName;
|
|
1310
|
+
cachedUser.avatarUrl = formatUrl(data.avatar_url) || cachedUser.avatarUrl;
|
|
1311
|
+
msg.author = cachedUser;
|
|
1312
|
+
} else {
|
|
1313
|
+
msg.author = new User({
|
|
1314
|
+
id: data.user_id,
|
|
1315
|
+
username: data.username,
|
|
1316
|
+
display_name: data.display_name,
|
|
1317
|
+
avatar_url: data.avatar_url,
|
|
1318
|
+
}, this);
|
|
1319
|
+
this.cache.users.set(msg.author.id, msg.author);
|
|
1320
|
+
}
|
|
1192
1321
|
}
|
|
1193
1322
|
|
|
1194
1323
|
if (!msg.channel && data.channel_id) {
|
|
@@ -1387,8 +1516,51 @@ class Client extends EventEmitter {
|
|
|
1387
1516
|
throw new ClientError(`File upload error: ${error.message}`, 'UPLOAD_FAILED');
|
|
1388
1517
|
}
|
|
1389
1518
|
}
|
|
1519
|
+
|
|
1520
|
+
// ============================================================================
|
|
1521
|
+
// EVENT EMITTER OVERRIDES
|
|
1522
|
+
// ============================================================================
|
|
1523
|
+
|
|
1524
|
+
/**
|
|
1525
|
+
* Attaches an event listener.
|
|
1526
|
+
* @superInternal
|
|
1527
|
+
* @template {keyof ClientEvents} K
|
|
1528
|
+
* @param {K} event The event name.
|
|
1529
|
+
* @param {(arg: ClientEvents[K]) => void} listener
|
|
1530
|
+
* @returns {this}
|
|
1531
|
+
*/
|
|
1532
|
+
on(event, listener) {
|
|
1533
|
+
return super.on(event, listener);
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
/**
|
|
1537
|
+
* Emits an event with typed arguments.
|
|
1538
|
+
* @internal
|
|
1539
|
+
* @template {keyof ClientEvents} K
|
|
1540
|
+
* @param {K} event
|
|
1541
|
+
* @param {ClientEvents[K]} payload
|
|
1542
|
+
* @returns {this}
|
|
1543
|
+
*/
|
|
1544
|
+
emit(event, payload) {
|
|
1545
|
+
return super.emit(event, payload);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
/**
|
|
1550
|
+
* @internal
|
|
1551
|
+
*/
|
|
1552
|
+
class ClientError extends Error {
|
|
1553
|
+
/**
|
|
1554
|
+
* @param {string} message - Error message
|
|
1555
|
+
* @param {string} code - Error code
|
|
1556
|
+
*/
|
|
1557
|
+
constructor(message, code) {
|
|
1558
|
+
super(message);
|
|
1559
|
+
this.name = 'ClientError';
|
|
1560
|
+
this.code = code;
|
|
1561
|
+
}
|
|
1390
1562
|
}
|
|
1391
1563
|
|
|
1392
1564
|
Client.MessageEmbed = MessageEmbed;
|
|
1393
|
-
Client.ClientError = ClientError;
|
|
1565
|
+
// Client.ClientError = ClientError;
|
|
1394
1566
|
module.exports = Client;
|
package/README.md
CHANGED
|
@@ -1,29 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Getting Started
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Introduction <span style="font-size:0.8em;">Intro</span>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### Beniocord.js
|
|
6
|
+
|
|
7
|
+
A powerful JavaScript library for building Beniocord bots with ease.
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/beniocord.js)
|
|
10
|
+
[](https://www.npmjs.com/package/beniocord.js)
|
|
11
|
+
[](https://github.com/Junior37534/beniocord.js)
|
|
12
|
+
[](https://github.com/Junior37534/beniocord.js/issues)
|
|
13
|
+
[](https://beniocord.site/register)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
### About
|
|
18
|
+
|
|
19
|
+
Beniocord.js is a powerful Node.js module that allows you to easily interact with the Beniocord API. It provides an intuitive and modern approach to bot development.
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
- 🚀 Easy to use and beginner-friendly
|
|
24
|
+
- ⚡ Fast and efficient
|
|
25
|
+
- 📦 Object-oriented design
|
|
26
|
+
- 🔄 Promise-based architecture
|
|
27
|
+
- 🎯 Full Beniocord API coverage
|
|
28
|
+
- 💪 TypeScript support
|
|
29
|
+
|
|
30
|
+
### Requirements
|
|
31
|
+
|
|
32
|
+
- Node.js >= 18
|
|
33
|
+
- NPM >= 9
|
|
6
34
|
|
|
7
35
|
---
|
|
8
36
|
|
|
9
37
|
## Installation
|
|
10
38
|
|
|
39
|
+
Install via NPM:
|
|
40
|
+
|
|
11
41
|
```bash
|
|
12
42
|
npm install beniocord.js
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
> Make sure you have Node.js >= 18 installed.
|
|
43
|
+
````
|
|
16
44
|
|
|
17
45
|
---
|
|
18
46
|
|
|
19
|
-
##
|
|
47
|
+
## Quick Example
|
|
20
48
|
|
|
21
49
|
```js
|
|
22
|
-
const
|
|
23
|
-
const {
|
|
24
|
-
require('dotenv').config();
|
|
25
|
-
|
|
26
|
-
const client = new Client({ token: process.env.BOT_TOKEN });
|
|
50
|
+
const Beniocord = require("beniocord.js");
|
|
51
|
+
const client = new Beniocord({ token: 'YOUR_BOT_TOKEN' });
|
|
27
52
|
|
|
28
53
|
client.on("ready", () => {
|
|
29
54
|
console.log("🤖 Bot connected!");
|
|
@@ -31,20 +56,21 @@ client.on("ready", () => {
|
|
|
31
56
|
|
|
32
57
|
client.on("messageCreate", async (msg) => {
|
|
33
58
|
if (msg.author?.id === client.user?.id) return;
|
|
34
|
-
if (!msg.content) return;
|
|
59
|
+
if (!msg.content.startsWith('!')) return;
|
|
35
60
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
const comando = msg.content.slice('!'.length).split(' ')[0];
|
|
62
|
+
const args = msg.content.slice(comando.length + '!'.length + 1).trim().split(' ');
|
|
63
|
+
|
|
64
|
+
if (comando === "ping") {
|
|
65
|
+
const msgTimestamp = Date.now() - Date.parse(msg.createdAt);
|
|
66
|
+
const sent = await msg.channel.send("🏓 Pinging...");
|
|
67
|
+
const editTimestamp = Date.now() - Date.parse(sent.createdAt);
|
|
68
|
+
|
|
69
|
+
await sent.edit(
|
|
70
|
+
`🏓 **Pong!**\n` +
|
|
71
|
+
`📨 **Message → Bot:** ${msgTimestamp}ms\n` +
|
|
72
|
+
`✏️ **Send → Edit:** ${editTimestamp}ms`
|
|
73
|
+
);
|
|
48
74
|
}
|
|
49
75
|
});
|
|
50
76
|
|
|
@@ -53,24 +79,8 @@ client.login();
|
|
|
53
79
|
|
|
54
80
|
---
|
|
55
81
|
|
|
56
|
-
##
|
|
57
|
-
|
|
58
|
-
* **Basic events**: `messageCreate`, `messageEdit`, `messageDelete`, `memberJoin`, `memberLeave`, `presenceUpdate`, `channelUpdate`, and more.
|
|
59
|
-
* **Basic moderation**: delete messages, edit messages, etc.
|
|
60
|
-
* **Embeds support**: create rich messages with `MessageEmbed`.
|
|
61
|
-
* **Event-driven**: easy to handle events in real-time.
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
|
|
65
|
-
## Events
|
|
66
|
-
|
|
67
|
-
```js
|
|
68
|
-
client.on("messageCreate", msg => {...});
|
|
69
|
-
client.on("memberJoin", data => {...});
|
|
70
|
-
client.on("channelUpdate", data => {...});
|
|
71
|
-
// and many more...
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
You can add custom events and interact with your bot in real-time.
|
|
82
|
+
## Useful Links
|
|
75
83
|
|
|
76
|
-
|
|
84
|
+
* [Official Website](https://beniocord.site)
|
|
85
|
+
* [Documentation](https://docs.beniocord.site)
|
|
86
|
+
* [Join Beniocord](https://beniocord.site/register)
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"socket.io-client": "^4.8.1"
|
|
6
6
|
},
|
|
7
7
|
"name": "beniocord.js",
|
|
8
|
-
"version": "2.
|
|
8
|
+
"version": "2.1.1",
|
|
9
9
|
"description": "Uma biblioteca leve e intuitiva para integração com APIs de bots em plataformas de mensagens, como Discord. Facilita o envio de mensagens, gerenciamento de canais e interação com usuários, proporcionando uma experiência de desenvolvimento ágil e eficiente.",
|
|
10
10
|
"main": "Client.js",
|
|
11
11
|
"scripts": {
|