beniocord.js 2.1.1 → 2.1.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/Client.js CHANGED
@@ -9,6 +9,8 @@ const Message = require("./structures/Message");
9
9
  const User = require("./structures/User");
10
10
  const Channel = require("./structures/Channel");
11
11
  const Emoji = require("./structures/Emoji");
12
+ const Sticker = require("./structures/Sticker");
13
+
12
14
  const { MessageEmbed, MessageAttachment } = require("./structures/Util");
13
15
  const { formatUrl } = require("./helpers");
14
16
 
@@ -57,8 +59,8 @@ class Client extends EventEmitter {
57
59
  * @fires Client#typingStop
58
60
  * @class Client
59
61
  * @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
+ * @param {Object} options - Client configuration options
63
+ * @param {string} options.token - Bot token used for authentication
62
64
  * @example
63
65
  * const Beniocord = require('beniocord.js');
64
66
  * const client = new Beniocord({ token: 'YOUR_BOT_TOKEN' });
@@ -616,31 +618,27 @@ class Client extends EventEmitter {
616
618
  * Edits a message
617
619
  * @param {string} messageId - Message ID
618
620
  * @param {string} newContent - New message content
619
- * @returns {Promise<Object>} Response data
621
+ * @returns {Promise<Message>} Response data
620
622
  */
621
623
  async editMessage(messageId, newContent) {
622
624
  return new Promise((resolve, reject) => {
623
- try {
624
- this._ensureConnected();
625
- } catch (error) {
626
- return reject(error);
627
- }
628
-
629
625
  this.socket.emit(
630
626
  'message:edit',
631
627
  { messageId, content: newContent },
632
- (response) => {
628
+ async (response) => {
633
629
  if (response && response.error) {
634
630
  reject(new ClientError(response.error, "EDIT_ERROR"));
635
631
  } else {
636
632
  this._updateMessageContent(messageId, newContent, new Date().toISOString());
637
- resolve(response);
633
+ const msg = await this._processSocketMessage(response); // transforma response em Message
634
+ resolve(msg);
638
635
  }
639
636
  }
640
637
  );
641
638
  });
642
639
  }
643
640
 
641
+
644
642
  /**
645
643
  * Deletes a message
646
644
  * @param {string} messageId - Message ID
@@ -727,11 +725,7 @@ class Client extends EventEmitter {
727
725
  created_at: raw.created_at,
728
726
  };
729
727
  const messageData = { ...raw, user: userData };
730
-
731
- // Cria a mensagem
732
728
  const message = new Message(messageData, this);
733
-
734
- // Cache do author
735
729
  if (message.author) this.cache.users.set(message.author.id, message.author);
736
730
 
737
731
  // --- CHANNEL ---
@@ -744,6 +738,21 @@ class Client extends EventEmitter {
744
738
  message.channel = channel;
745
739
  }
746
740
 
741
+ // --- STICKER ---
742
+ if (!message.sticker && raw.sticker_id) {
743
+ let sticker = this.cache.stickers.get(raw.sticker_id);
744
+
745
+ if (!sticker) {
746
+ try {
747
+ sticker = await this.fetchSticker(raw.sticker_id);
748
+ } catch (_) {
749
+ sticker = null;
750
+ }
751
+ }
752
+
753
+ message.sticker = sticker;
754
+ }
755
+
747
756
  return message;
748
757
  } catch (error) {
749
758
  throw error instanceof ClientError
@@ -856,8 +865,9 @@ class Client extends EventEmitter {
856
865
 
857
866
  try {
858
867
  const res = await this._axios.get(`/api/stickers/${id}`);
859
- this.cache.stickers.set(res.data.id, res.data);
860
- return res.data;
868
+ const sticker = new Sticker(res.data);
869
+ this.cache.stickers.set(sticker.id, sticker);
870
+ return sticker;
861
871
  } catch (error) {
862
872
  throw error instanceof ClientError
863
873
  ? error
@@ -1085,10 +1095,27 @@ class Client extends EventEmitter {
1085
1095
  /**
1086
1096
  * @event Client#messageEdit
1087
1097
  */
1088
- this.socket.on('message:edited', (data) => {
1089
- const { messageId, content, editedAt } = data;
1090
- this._updateMessageContent(messageId, content, editedAt);
1091
- this.emit('messageEdit', data);
1098
+ this.socket.on('message:edited', async (data) => {
1099
+ const { messageId: id, content, editedAt } = data;
1100
+
1101
+ let msg;
1102
+ for (const [channelId, messages] of this.cache.channels) {
1103
+ const channel = messages;
1104
+ if (channel.messages.has(id)) {
1105
+ msg = channel.messages.get(id);
1106
+ msg.content = content;
1107
+ msg.editedAt = editedAt;
1108
+ msg.edited = true;
1109
+ break;
1110
+ }
1111
+ }
1112
+
1113
+ if (!msg) {
1114
+ msg = await this._processSocketMessage(data);
1115
+ this._cacheMessage(msg);
1116
+ }
1117
+
1118
+ this.emit('messageEdit', msg);
1092
1119
  });
1093
1120
 
1094
1121
  /**
@@ -1328,6 +1355,15 @@ class Client extends EventEmitter {
1328
1355
  await msg.channel.members.fetch();
1329
1356
  }
1330
1357
 
1358
+ if (!msg.sticker && data.sticker_id) {
1359
+ let sticker = this.cache.stickers.get(data.sticker_id);
1360
+
1361
+ if (!sticker) {
1362
+ sticker = await this.fetchSticker(data.sticker_id).catch(() => null);
1363
+ }
1364
+
1365
+ msg.sticker = sticker;
1366
+ }
1331
1367
  return msg;
1332
1368
  }
1333
1369
 
@@ -1344,10 +1380,8 @@ class Client extends EventEmitter {
1344
1380
  const channel = msg.channel;
1345
1381
  this._ensureCached(this.cache.channels, channel.id, channel);
1346
1382
 
1347
- // guarda a mensagem no canal
1348
1383
  channel.messages.set(msg.id, msg);
1349
1384
 
1350
- // limita a 50 mensagens
1351
1385
  if (channel.messages.size > 50) {
1352
1386
  const firstKey = channel.messages.firstKey(); // método do Collection
1353
1387
  channel.messages.delete(firstKey);
package/README.md CHANGED
@@ -11,6 +11,7 @@ A powerful JavaScript library for building Beniocord bots with ease.
11
11
  [![GitHub stars](https://img.shields.io/github/stars/Junior37534/beniocord.js?color=yellow&logo=github&style=flat-square)](https://github.com/Junior37534/beniocord.js)
12
12
  [![GitHub issues](https://img.shields.io/github/issues/Junior37534/beniocord.js?color=green&logo=github&style=flat-square)](https://github.com/Junior37534/beniocord.js/issues)
13
13
  [![Join Beniocord](https://img.shields.io/badge/Join-Beniocord-5865F2?style=flat-square&logoColor=white)](https://beniocord.site/register)
14
+ [![Better Stack Badge](https://uptime.betterstack.com/status-badges/v2/monitor/284m0.svg)](https://uptime.betterstack.com/?utm_source=status_badge)
14
15
 
15
16
  ---
16
17
 
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.1.1",
8
+ "version": "2.1.2",
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": {
@@ -20,7 +20,7 @@ class Message {
20
20
  * @param {Object} [data.user] - Author user data.
21
21
  * @param {Object} [data.channel] - Channel data where the message was sent.
22
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.
23
+ * @param {Object} [data.sticker] - Sticker object attached to the message.
24
24
  * @param {string|number|Date} [data.edited_at] - Timestamp when the message was edited.
25
25
  * @param {string|number|Date} [data.created_at] - Timestamp when the message was created.
26
26
  * @param {Object} clientInstance - The client instance.
@@ -35,9 +35,16 @@ class Message {
35
35
  * fileSize: null,
36
36
  * attachments: [],
37
37
  * replyTo: 20709,
38
- * stickerId: null,
39
38
  * editedAt: null,
40
39
  * createdAt: '2025-11-16T14:29:40.598Z',
40
+ * sticker: {
41
+ * id: 1,
42
+ * name: 'carrin',
43
+ * url: '/uploads/stickers/1758986081574-510376341.gif',
44
+ * tags: [],
45
+ * user_id: 2,
46
+ * owner: 'kkauabr'
47
+ * },
41
48
  * author: User {
42
49
  * id: 1,
43
50
  * username: 'junior9244',
@@ -75,10 +82,11 @@ class Message {
75
82
  this.fileSize = data.file_size;
76
83
  this.attachments = [];
77
84
  this.replyTo = data.reply_to;
78
- this.stickerId = data.sticker_id;
79
85
  this.editedAt = data.edited_at;
80
86
  this.createdAt = data.created_at;
81
87
 
88
+ this.sticker = null;
89
+
82
90
  if (data.file_url) {
83
91
  this.attachments.push({
84
92
  url: this.fileUrl,
@@ -0,0 +1,75 @@
1
+ const { formatUrl } = require("../helpers");
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ class Sticker {
7
+ /**
8
+ * Creates a new Sticker instance.
9
+ * @param {Object} data - Raw sticker data.
10
+ * @param {string|number} data.id - The unique ID of the sticker.
11
+ * @param {string|number} data.user_id - The ID of the user who uploaded the sticker.
12
+ * @param {string} data.name - The name of the sticker.
13
+ * @param {string} data.url - The URL of the sticker image.
14
+ * @param {string[]|null} data.tags - Array of tags associated with the sticker.
15
+ * @param {string|number|Date} data.created_at - Timestamp when the sticker was created.
16
+ * @param {string|number|Date} data.updated_at - Timestamp when the sticker was last updated.
17
+ * @returns {Sticker} The created Sticker instance.
18
+ *
19
+ * @example
20
+ * Sticker {
21
+ * id: 2,
22
+ * userId: 1,
23
+ * name: 'saboroso',
24
+ * url: 'https://api.beniocord.site/uploads/stickers/1758986145335-603013635.png',
25
+ * tags: [ 'sabor', 'delicia', 'gostoso' ],
26
+ * createdAt: '2025-09-27T15:15:45.555Z',
27
+ * updatedAt: '2025-09-27T15:15:45.555Z'
28
+ * }
29
+ */
30
+ constructor(data) {
31
+ /**
32
+ * The unique ID of the sticker.
33
+ * @type {string|number}
34
+ */
35
+ this.id = data.id;
36
+
37
+ /**
38
+ * The ID of the user who uploaded the sticker.
39
+ * @type {string|number}
40
+ */
41
+ this.userId = data.user_id;
42
+
43
+ /**
44
+ * The name of the sticker.
45
+ * @type {string}
46
+ */
47
+ this.name = data.name;
48
+
49
+ /**
50
+ * Array of tags for the sticker.
51
+ * @type {string[]}
52
+ */
53
+ this.tags = Array.isArray(data.tags) ? data.tags : [];
54
+
55
+ /**
56
+ * The formatted URL of the sticker image.
57
+ * @type {string}
58
+ */
59
+ this.url = formatUrl(data.url);
60
+
61
+ /**
62
+ * Timestamp when the sticker was created.
63
+ * @type {string|number|Date}
64
+ */
65
+ this.createdAt = data.created_at;
66
+
67
+ /**
68
+ * Timestamp when the sticker was last updated.
69
+ * @type {string|number|Date}
70
+ */
71
+ this.updatedAt = data.updated_at;
72
+ }
73
+ }
74
+
75
+ module.exports = Sticker;