beniocord.js 2.0.8 → 2.1.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/Client.js CHANGED
@@ -11,29 +11,40 @@ const Channel = require("./structures/Channel");
11
11
  const Emoji = require("./structures/Emoji");
12
12
  const { MessageEmbed, MessageAttachment } = require("./structures/Util");
13
13
 
14
- class ClientError extends Error {
15
- constructor(message, code) {
16
- super(message);
17
- this.name = 'ClientError';
18
- this.code = code;
19
- }
20
- }
21
-
22
14
  let global = {
23
15
  token: "",
24
16
  apiUrl: "https://api-bots.beniocord.site"
25
17
  };
26
18
 
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
19
  class Client extends EventEmitter {
20
+ /**
21
+ * @fires Client#ready
22
+ * @fires Client#messageCreate
23
+ * @fires Client#messageDelete
24
+ * @fires Client#messageEdit
25
+ * @fires Client#error
26
+ * @fires Client#disconnect
27
+ * @fires Client#reconnect
28
+ * @fires Client#emojiCreate
29
+ * @fires Client#emojiDelete
30
+ * @fires Client#stickerCreate
31
+ * @fires Client#stickerDelete
32
+ * @fires Client#channelCreate
33
+ * @fires Client#channelDelete
34
+ * @fires Client#channelUpdate
35
+ * @fires Client#channelMemberAdd
36
+ * @fires Client#channelMemberRemove
37
+ * @fires Client#channelMemberUpdate
38
+ * @fires Client#typingStart
39
+ * @fires Client#typingStop
40
+ * @class Client
41
+ * @description Classe principal do BenioCord.js - Gerencia a comunicação com a API e eventos do bot
42
+ * @param {Object} options - Opções de configuração do cliente
43
+ * @param {string} options.token - Token do bot para autenticação
44
+ * @example
45
+ * const { Client } = require('beniocord.js');
46
+ * const client = new Client({ token: 'YOUR_BOT_TOKEN' });
47
+ */
37
48
  constructor({ token }) {
38
49
  super();
39
50
 
@@ -141,6 +152,10 @@ class Client extends EventEmitter {
141
152
  await this._joinAllChannelRooms();
142
153
 
143
154
  this.isReady = true;
155
+
156
+ /**
157
+ * @event Client#ready
158
+ */
144
159
  this.emit("ready", this.user);
145
160
 
146
161
  return this.user;
@@ -216,7 +231,7 @@ class Client extends EventEmitter {
216
231
 
217
232
  /**
218
233
  * Fetches information about the bot user
219
- * @param {boolean} force - Force fetch from API instead of cache
234
+ * @param {boolean} [force=false] - Force fetch from API instead of cache
220
235
  * @returns {Promise<User>} Bot user object
221
236
  */
222
237
  async fetchMe(force = false) {
@@ -240,7 +255,7 @@ class Client extends EventEmitter {
240
255
  /**
241
256
  * Fetches a user by ID
242
257
  * @param {string} id - User ID
243
- * @param {boolean} force - Force fetch from API instead of cache
258
+ * @param {boolean} [force=false] - Force fetch from API instead of cache
244
259
  * @returns {Promise<User>} User object
245
260
  */
246
261
  async fetchUser(id, force = false) {
@@ -286,7 +301,7 @@ class Client extends EventEmitter {
286
301
  /**
287
302
  * Fetches a specific channel by ID
288
303
  * @param {string} id - Channel ID
289
- * @param {boolean} force - Force fetch from API instead of cache
304
+ * @param {boolean} [force=false] - Force fetch from API instead of cache
290
305
  * @returns {Promise<Channel>} Channel object
291
306
  */
292
307
  async fetchChannel(id, force = false) {
@@ -708,7 +723,7 @@ class Client extends EventEmitter {
708
723
  /**
709
724
  * Fetches an emoji by ID
710
725
  * @param {string} id - Emoji ID
711
- * @param {boolean} force - Force fetch from API instead of cache
726
+ * @param {boolean} [force=false] - Force fetch from API instead of cache
712
727
  * @returns {Promise<Emoji>} Emoji object
713
728
  */
714
729
  async fetchEmoji(id, force = false) {
@@ -760,7 +775,7 @@ class Client extends EventEmitter {
760
775
  /**
761
776
  * Fetches a sticker by ID
762
777
  * @param {string} id - Sticker ID
763
- * @param {boolean} force - Force fetch from API instead of cache
778
+ * @param {boolean} [force=false] - Force fetch from API instead of cache
764
779
  * @returns {Promise<Object>} Sticker data
765
780
  */
766
781
  async fetchSticker(id, force = false) {
@@ -968,6 +983,9 @@ class Client extends EventEmitter {
968
983
  _setupSocketHandlers() {
969
984
  this._removeSocketHandlers();
970
985
 
986
+ /**
987
+ * @event Client#messageCreate
988
+ */
971
989
  this.socket.on('message:new', async (data) => {
972
990
  try {
973
991
  if (this._sentMessages.has(data.id)) {
@@ -983,31 +1001,49 @@ class Client extends EventEmitter {
983
1001
  }
984
1002
  });
985
1003
 
1004
+ /**
1005
+ * @event Client#messageDelete
1006
+ */
986
1007
  this.socket.on('message:deleted', (data) => {
987
1008
  const { messageId } = data;
988
1009
  this._markMessageDeleted(messageId);
989
1010
  this.emit('messageDelete', data);
990
1011
  });
991
1012
 
1013
+ /**
1014
+ * @event Client#messageEdit
1015
+ */
992
1016
  this.socket.on('message:edited', (data) => {
993
1017
  const { messageId, content, editedAt } = data;
994
1018
  this._updateMessageContent(messageId, content, editedAt);
995
1019
  this.emit('messageEdit', data);
996
1020
  });
997
1021
 
1022
+ /**
1023
+ * @event Client#typingStart
1024
+ */
998
1025
  this.socket.on('typing:user-start', (data) => {
999
1026
  this.emit('typingStart', data);
1000
1027
  });
1001
1028
 
1029
+ /**
1030
+ * @event Client#typingStop
1031
+ */
1002
1032
  this.socket.on('typing:user-stop', (data) => {
1003
1033
  this.emit('typingStop', data);
1004
1034
  });
1005
1035
 
1036
+ /**
1037
+ * @event Client#userStatusUpdate
1038
+ */
1006
1039
  this.socket.on('user:status-update', (data) => {
1007
1040
  this._updateUserStatus(data);
1008
1041
  this.emit('userStatusUpdate', data);
1009
1042
  });
1010
1043
 
1044
+ /**
1045
+ * @event Client#memberJoin
1046
+ */
1011
1047
  this.socket.on('member:join', async (data) => {
1012
1048
  const member = await this.fetchUser(data.memberId).catch(() => null);
1013
1049
  const channel = this.cache.channels.get(data.channelId);
@@ -1017,6 +1053,9 @@ class Client extends EventEmitter {
1017
1053
  this.emit('memberJoin', { channel, member });
1018
1054
  });
1019
1055
 
1056
+ /**
1057
+ * @event Client#memberLeave
1058
+ */
1020
1059
  this.socket.on('member:leave', async (data) => {
1021
1060
  const channel = this.cache.channels.get(data.channelId);
1022
1061
  const member = this.cache.users.get(data.memberId);
@@ -1032,16 +1071,25 @@ class Client extends EventEmitter {
1032
1071
  this.emit('memberLeave', { channel, member });
1033
1072
  });
1034
1073
 
1074
+ /**
1075
+ * @event Client#channelUpdate
1076
+ */
1035
1077
  this.socket.on('channel:update', (data) => {
1036
1078
  this._updateChannel(data);
1037
1079
  this.emit('channelUpdate', data);
1038
1080
  });
1039
1081
 
1082
+ /**
1083
+ * @event Client#channelDelete
1084
+ */
1040
1085
  this.socket.on('channel:delete', (data) => {
1041
1086
  this.cache.channels.delete(data.channelId);
1042
1087
  this.emit('channelDelete', data);
1043
1088
  });
1044
1089
 
1090
+ /**
1091
+ * @event Client#rateLimited
1092
+ */
1045
1093
  this.socket.on('rate:limited', (data) => {
1046
1094
  this.emit('rateLimited', data);
1047
1095
  });
@@ -1389,6 +1437,19 @@ class Client extends EventEmitter {
1389
1437
  }
1390
1438
  }
1391
1439
 
1440
+ class ClientError extends Error {
1441
+ /**
1442
+ * @private
1443
+ * @param {string} message - Error message
1444
+ * @param {string} code - Error code
1445
+ */
1446
+ constructor(message, code) {
1447
+ super(message);
1448
+ this.name = 'ClientError';
1449
+ this.code = code;
1450
+ }
1451
+ }
1452
+
1392
1453
  Client.MessageEmbed = MessageEmbed;
1393
- Client.ClientError = ClientError;
1454
+ // Client.ClientError = ClientError;
1394
1455
  module.exports = Client;
package/helpers/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  function formatUrl(url) {
2
2
  const base = 'https://api.beniocord.site';
3
- if (!url) return undefined;
3
+ if (!url) return null;
4
4
  if (url.startsWith(base) || url.startsWith('http')) return url;
5
5
  return base + (url.startsWith('/') ? url : '/' + url);
6
6
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "dependencies": {
3
+ "@discordjs/collection": "^2.1.1",
3
4
  "axios": "^1.12.2",
4
5
  "socket.io-client": "^4.8.1"
5
6
  },
6
7
  "name": "beniocord.js",
7
- "version": "2.0.8",
8
+ "version": "2.1.0",
8
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.",
9
10
  "main": "Client.js",
10
- "devDependencies": {},
11
11
  "scripts": {
12
12
  "test": "node bot.js"
13
13
  },
@@ -1,6 +1,6 @@
1
1
  const { formatUrl } = require('../helpers');
2
2
  const MessageCollector = require('./MessageCollector');
3
- const Collection = require('../collection').Collection;
3
+ const Collection = require('@discordjs/collection').Collection;
4
4
 
5
5
  let client;
6
6
  class Channel {
@@ -8,16 +8,16 @@ class Channel {
8
8
  client = clientInstance;
9
9
 
10
10
  this.id = data.id;
11
- this.ownerId = data.created_by;
12
11
  this.name = data.name;
13
12
  this.description = data.description;
14
13
  this.type = data.type || "text";
14
+ this.iconUrl = formatUrl(data.icon_url) || null;
15
+ this.ownerId = data.created_by;
15
16
  this.isPrivate = data.is_private;
16
17
  this.isLocked = data.is_locked;
17
- this.iconUrl = formatUrl(data.icon_url) || null;
18
+ this.memberCount = Number(data.member_count);
18
19
  this.createdAt = data.created_at;
19
20
  this.updatedAt = data.updated_at;
20
- this.memberCount = data.member_count;
21
21
 
22
22
  this.members = new Collection();
23
23
  this.members.fetch = async () => {
@@ -3,7 +3,32 @@ const Channel = require("./Channel");
3
3
  const { formatUrl } = require('../helpers/index');
4
4
 
5
5
  let client;
6
+
7
+ /**
8
+ * Represents a message in a channel.
9
+ */
6
10
  class Message {
11
+ /**
12
+ * Creates a new Message instance.
13
+ * @param {Object} data - Raw message data.
14
+ * @param {string|number} data.id - The unique ID of the message.
15
+ * @param {string} data.content - The content of the message.
16
+ * @param {string} [data.message_type="text"] - The type of the message (text, file, etc.).
17
+ * @param {string} [data.file_url] - URL of the attached file.
18
+ * @param {string} [data.file_name] - Name of the attached file.
19
+ * @param {number} [data.file_size] - Size of the attached file in bytes.
20
+ * @param {Object} [data.user] - Author user data.
21
+ * @param {Object} [data.channel] - Channel data where the message was sent.
22
+ * @param {string|number} [data.reply_to] - ID of the message this is replying to.
23
+ * @param {string|number} [data.sticker_id] - ID of a sticker attached to the message.
24
+ * @param {string|number|Date} [data.edited_at] - Timestamp when the message was edited.
25
+ * @param {string|number|Date} [data.created_at] - Timestamp when the message was created.
26
+ * @param {Object} clientInstance - The client instance to send/edit/delete messages.
27
+ * @example
28
+ * // Creating a message instance
29
+ * const msg = new Message({ id: 1, content: "Hello!" }, client);
30
+ *
31
+ */
7
32
  constructor(data, clientInstance) {
8
33
  this.id = data.id;
9
34
  this.content = data.content;
@@ -11,12 +36,11 @@ class Message {
11
36
  this.fileUrl = formatUrl(data.file_url);
12
37
  this.fileName = data.file_name;
13
38
  this.fileSize = data.file_size;
39
+ this.attachments = [];
14
40
  this.replyTo = data.reply_to;
41
+ this.stickerId = data.sticker_id;
15
42
  this.editedAt = data.edited_at;
16
43
  this.createdAt = data.created_at;
17
- this.stickerId = data.sticker_id;
18
-
19
- this.attachments = [];
20
44
 
21
45
  if (data.file_url) {
22
46
  this.attachments.push({
@@ -26,13 +50,21 @@ class Message {
26
50
  });
27
51
  }
28
52
 
29
- // this.author = data.user ? new User(data.user, this) : null;
30
53
  this.author = data.user ? new User(data.user, clientInstance) : null;
31
54
  this.channel = data.channel ? new Channel(data.channel, clientInstance) : null;
32
- // this.member = { user: this.author }
33
55
  client = clientInstance;
34
56
  }
35
57
 
58
+ /**
59
+ * Replies to this message.
60
+ * @param {string} content - Content of the reply.
61
+ * @param {Object} [opts={}] - Additional options for the reply.
62
+ * @returns {Promise<Message>} The sent reply message.
63
+ *
64
+ * @example
65
+ * // Replying to a message
66
+ * await msg.reply("Thanks for your message!");
67
+ */
36
68
  async reply(content, opts = {}) {
37
69
  return client.sendMessage(this.channel.id, content, {
38
70
  replyTo: this.id,
@@ -40,10 +72,27 @@ class Message {
40
72
  });
41
73
  }
42
74
 
75
+ /**
76
+ * Edits this message.
77
+ * @param {string} content - New content for the message.
78
+ * @returns {Promise<Message>} The edited message.
79
+ *
80
+ * @example
81
+ * // Editing a message
82
+ * await msg.edit("Updated content!");
83
+ */
43
84
  async edit(content) {
44
85
  return client.editMessage(this.id, content);
45
86
  }
46
87
 
88
+ /**
89
+ * Deletes this message.
90
+ * @returns {Promise<void>}
91
+ *
92
+ * @example
93
+ * // Deleting a message
94
+ * await msg.delete();
95
+ */
47
96
  async delete() {
48
97
  return client.deleteMessage(this.id);
49
98
  }
@@ -1,6 +1,21 @@
1
- const { formatUrl } = require("../helpers");
2
-
1
+ /**
2
+ * Represents a user.
3
+ */
3
4
  class User {
5
+ /**
6
+ * Creates a new User instance.
7
+ * @param {Object} data - Raw user data.
8
+ * @param {string|number} data.id - The unique ID of the user.
9
+ * @param {string} data.username - The username of the user.
10
+ * @param {string} data.display_name - The display name of the user.
11
+ * @param {string} data.avatar_url - The URL of the user's avatar.
12
+ * @param {string} [data.status='offline'] - The user's status.
13
+ * @param {Array<string>} [data.emblems=[]] - Array of user emblems.
14
+ * @param {boolean} data.is_bot - Whether the user is a bot.
15
+ * @param {string|number|Date} data.last_seen - Last seen timestamp.
16
+ * @param {string|number|Date} data.created_at - Account creation timestamp.
17
+ * @param {Object} client - The client instance (optional, internal use).
18
+ */
4
19
  constructor(data, client) {
5
20
  this.id = data.id;
6
21
  this.username = data.username;
@@ -8,17 +23,15 @@ class User {
8
23
  this.avatarUrl = formatUrl(data.avatar_url);
9
24
  this.status = data.status || "offline";
10
25
  this.emblems = data.emblems || [];
26
+ this.isBot = data.is_bot;
11
27
  this.lastSeen = data.last_seen;
12
28
  this.createdAt = data.created_at;
13
- this.isBot = data.is_bot;
14
- // this.email = data.email;
15
- // this.updatedAt = data.updated_at;
16
29
  }
17
30
 
18
- // displayAvatarURL() {
19
- // return this.avatarUrl;
20
- // }
21
-
31
+ /**
32
+ * Returns the avatar URL of the user.
33
+ * @returns {string} The avatar URL.
34
+ */
22
35
  avatarURL() {
23
36
  return this.avatarUrl;
24
37
  }