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.
@@ -3,7 +3,45 @@ const MessageCollector = require('./MessageCollector');
3
3
  const Collection = require('@discordjs/collection').Collection;
4
4
 
5
5
  let client;
6
+
7
+ /**
8
+ * @internal
9
+ */
6
10
  class Channel {
11
+ /**
12
+ * Creates a new Channel instance.
13
+ * @param {Object} data - Raw channel data.
14
+ * @param {string|number} data.id - The unique ID of the channel.
15
+ * @param {string} data.name - The name of the channel.
16
+ * @param {string} [data.description] - The channel description.
17
+ * @param {string} [data.type="text"] - The type of the channel (text, voice, etc.).
18
+ * @param {string} [data.icon_url] - The URL of the channel icon.
19
+ * @param {string|number} data.created_by - ID of the channel owner.
20
+ * @param {boolean} [data.is_private=false] - Whether the channel is private.
21
+ * @param {boolean} [data.is_locked=false] - Whether the channel is locked.
22
+ * @param {number|string} [data.member_count=0] - Number of members in the channel.
23
+ * @param {string|Date} data.created_at - Creation timestamp.
24
+ * @param {string|Date} data.updated_at - Last update timestamp.
25
+ * @param {import('./Client')} clientInstance - The client instance.
26
+ * @returns {Channel} The created Channel instance.
27
+ * @example
28
+ * // msg.channel
29
+ * Channel {
30
+ * id: 2,
31
+ * name: 'Privado',
32
+ * description: 'DM Privada para conversar secretas!\n',
33
+ * type: 'text',
34
+ * iconUrl: 'https://api.beniocord.site/uploads/1762899895145-938680330.gif',
35
+ * ownerId: 1,
36
+ * isPrivate: true,
37
+ * isLocked: false,
38
+ * memberCount: 8,
39
+ * createdAt: '2025-09-21T15:28:43.610Z',
40
+ * updatedAt: '2025-11-11T23:49:54.906Z',
41
+ * members: Collection(0) [Map] { fetch: [AsyncFunction (anonymous)] },
42
+ * messages: Collection(0) [Map] { fetch: [AsyncFunction (anonymous)] }
43
+ * }
44
+ */
7
45
  constructor(data, clientInstance) {
8
46
  client = clientInstance;
9
47
 
@@ -19,6 +57,10 @@ class Channel {
19
57
  this.createdAt = data.created_at;
20
58
  this.updatedAt = data.updated_at;
21
59
 
60
+ /**
61
+ * Cached members of the channel.
62
+ * @type {Collection<string, import('./User')>}
63
+ */
22
64
  this.members = new Collection();
23
65
  this.members.fetch = async () => {
24
66
  const members = await client.fetchChannelMembers(this.id);
@@ -29,6 +71,10 @@ class Channel {
29
71
  return this.members;
30
72
  };
31
73
 
74
+ /**
75
+ * Cached messages of the channel.
76
+ * @type {Collection<string, import('./Message')>}
77
+ */
32
78
  this.messages = new Collection();
33
79
  this.messages.fetch = async (id) => {
34
80
  if (client.fetchMessage) {
@@ -46,22 +92,40 @@ class Channel {
46
92
  });
47
93
  }
48
94
 
95
+ /**
96
+ * Sends a message to the channel.
97
+ * @param {string|Object} content - The content of the message.
98
+ * @param {Object} [opts] - Optional message options.
99
+ * @returns {Promise<import('./Message')>} The sent message.
100
+ */
49
101
  async send(content, opts = {}) {
50
102
  return client.sendMessage(this.id, content, opts);
51
103
  }
52
104
 
105
+ /**
106
+ * Starts typing indicator in the channel.
107
+ * @returns {Promise<void>}
108
+ */
53
109
  startTyping() {
54
110
  return client.startTyping(this.id);
55
111
  }
56
112
 
113
+ /**
114
+ * Stops typing indicator in the channel.
115
+ * @returns {Promise<void>}
116
+ */
57
117
  stopTyping() {
58
118
  return client.stopTyping(this.id);
59
119
  }
60
120
 
121
+ /**
122
+ * Creates a new message collector in this channel.
123
+ * @param {Object} [options={}] - Collector options.
124
+ * @returns {MessageCollector} The created message collector.
125
+ */
61
126
  createMessageCollector(options = {}) {
62
127
  return new MessageCollector(this, options, client);
63
128
  }
64
-
65
129
  }
66
130
 
67
131
  module.exports = Channel;
@@ -1,14 +1,59 @@
1
1
  const { formatUrl } = require("../helpers");
2
2
 
3
+ /**
4
+ * @internal
5
+ */
3
6
  class Emoji {
7
+ /**
8
+ * Creates a new Emoji instance.
9
+ * @param {Object} data - Raw emoji data.
10
+ * @param {string|number} data.id - The unique ID of the emoji.
11
+ * @param {string|number} data.user_id - The ID of the user who uploaded the emoji.
12
+ * @param {string} data.name - The name of the emoji.
13
+ * @param {string} data.url - The URL of the emoji image.
14
+ * @param {string|number|Date} data.created_at - Timestamp when the emoji was created.
15
+ * @returns {Emoji} The created Emoji instance.
16
+ * @example
17
+ * Emoji {
18
+ * id: 1,
19
+ * userId: 1,
20
+ * name: 'shitcord',
21
+ * url: 'https://api.beniocord.site/uploads/emojis/1758982533925-364594757.png',
22
+ * createdAt: '2025-09-27T14:15:33.932Z'
23
+ * }
24
+ *
25
+ */
4
26
  constructor(data) {
27
+ /**
28
+ * The unique ID of the emoji.
29
+ * @type {string|number}
30
+ */
5
31
  this.id = data.id;
32
+
33
+ /**
34
+ * The ID of the user who uploaded the emoji.
35
+ * @type {string|number}
36
+ */
6
37
  this.userId = data.user_id;
38
+
39
+ /**
40
+ * The name of the emoji.
41
+ * @type {string}
42
+ */
7
43
  this.name = data.name;
44
+
45
+ /**
46
+ * The URL of the emoji image.
47
+ * @type {string}
48
+ */
8
49
  this.url = formatUrl(data.url);
50
+
51
+ /**
52
+ * Timestamp when the emoji was created.
53
+ * @type {string|number|Date}
54
+ */
9
55
  this.createdAt = data.created_at;
10
- this.updatedAt = data.updated_at;
11
56
  }
12
57
  }
13
58
 
14
- module.exports = Emoji;
59
+ module.exports = Emoji;
@@ -3,7 +3,69 @@ const Channel = require("./Channel");
3
3
  const { formatUrl } = require('../helpers/index');
4
4
 
5
5
  let client;
6
+
7
+ /**
8
+ * @internal
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.
27
+ * @returns {Message} The created Message instance.
28
+ * @example
29
+ * Message {
30
+ * id: 20711,
31
+ * content: 'Hello World!',
32
+ * messageType: 'text',
33
+ * fileUrl: null,
34
+ * fileName: null,
35
+ * fileSize: null,
36
+ * attachments: [],
37
+ * replyTo: 20709,
38
+ * stickerId: null,
39
+ * editedAt: null,
40
+ * createdAt: '2025-11-16T14:29:40.598Z',
41
+ * author: User {
42
+ * id: 1,
43
+ * username: 'junior9244',
44
+ * displayName: 'Junior',
45
+ * avatarUrl: 'https://api.beniocord.site/uploads/avatars/1760736025811-629632107.png',
46
+ * status: 'online',
47
+ * emblems: [],
48
+ * isBot: false,
49
+ * lastSeen: '2025-11-16T14:29:40.598Z',
50
+ * createdAt: '2025-11-16T14:29:40.598Z'
51
+ * },
52
+ * channel: Channel {
53
+ * id: 2,
54
+ * name: 'Privado',
55
+ * description: 'DM Privada para conversar secretas!\n',
56
+ * type: 'text',
57
+ * iconUrl: 'https://api.beniocord.site/uploads/1762899895145-938680330.gif',
58
+ * ownerId: 1,
59
+ * isPrivate: true,
60
+ * isLocked: false,
61
+ * memberCount: 8,
62
+ * createdAt: '2025-09-21T15:28:43.610Z',
63
+ * updatedAt: '2025-11-11T23:49:54.906Z',
64
+ * members: Collection(0) [Map] { fetch: [AsyncFunction (anonymous)] },
65
+ * messages: Collection(0) [Map] { fetch: [AsyncFunction (anonymous)] }
66
+ * }
67
+ * }
68
+ */
7
69
  constructor(data, clientInstance) {
8
70
  this.id = data.id;
9
71
  this.content = data.content;
@@ -25,13 +87,21 @@ class Message {
25
87
  });
26
88
  }
27
89
 
28
- // this.author = data.user ? new User(data.user, this) : null;
29
90
  this.author = data.user ? new User(data.user, clientInstance) : null;
30
91
  this.channel = data.channel ? new Channel(data.channel, clientInstance) : null;
31
- // this.member = { user: this.author }
32
92
  client = clientInstance;
33
93
  }
34
94
 
95
+ /**
96
+ * Replies to this message.
97
+ * @param {string} content - Content of the reply.
98
+ * @param {Object} [opts={}] - Additional options for the reply.
99
+ * @returns {Promise<Message>} The sent reply message.
100
+ *
101
+ * @example
102
+ * // Replying to a message
103
+ * await msg.reply("Thanks for your message!");
104
+ */
35
105
  async reply(content, opts = {}) {
36
106
  return client.sendMessage(this.channel.id, content, {
37
107
  replyTo: this.id,
@@ -39,10 +109,27 @@ class Message {
39
109
  });
40
110
  }
41
111
 
112
+ /**
113
+ * Edits this message.
114
+ * @param {string} content - New content for the message.
115
+ * @returns {Promise<Message>} The edited message.
116
+ *
117
+ * @example
118
+ * // Editing a message
119
+ * await msg.edit("Updated content!");
120
+ */
42
121
  async edit(content) {
43
122
  return client.editMessage(this.id, content);
44
123
  }
45
124
 
125
+ /**
126
+ * Deletes this message.
127
+ * @returns {Promise<void>}
128
+ *
129
+ * @example
130
+ * // Deleting a message
131
+ * await msg.delete();
132
+ */
46
133
  async delete() {
47
134
  return client.deleteMessage(this.id);
48
135
  }
@@ -1,45 +1,68 @@
1
1
  const EventEmitter = require('events');
2
2
 
3
3
  class MessageCollector extends EventEmitter {
4
+ /**
5
+ * Creates a new MessageCollector.
6
+ *
7
+ * @param {Channel} channel - The channel to listen for messages.
8
+ * @param {Object} [options={}] - Options for the collector.
9
+ * @param {function(Message): boolean|Promise<boolean>} [options.filter] - Filter function to determine which messages are collected.
10
+ * @param {number} [options.time=60000] - Time in milliseconds before the collector stops automatically.
11
+ * @param {number} [options.max=Infinity] - Maximum number of messages to collect before stopping.
12
+ * @param {Client} client - The client instance to listen for events.
13
+ *
14
+ * @example
15
+ * const collector = new MessageCollector(channel, { filter: msg => msg.content.includes('hello'), time: 30000 }, client);
16
+ * collector.on('collect', msg => console.log(`Collected message: ${msg.content}`));
17
+ * collector.on('end', (collected, reason) => console.log(`Collector ended: ${reason}, collected ${collected.length} messages`));
18
+ */
4
19
  constructor(channel, options = {}, client) {
5
20
  super();
6
-
21
+
7
22
  this.channel = channel;
8
23
  this.client = client;
9
- // this.client = channel.client;
10
24
  this.filter = options.filter || (() => true);
11
25
  this.time = options.time || 60000;
12
26
  this.max = options.max || Infinity;
13
27
  this.collected = [];
14
28
  this.ended = false;
15
-
29
+
16
30
  this._timeout = null;
17
31
  this._handleMessage = this._handleMessage.bind(this);
18
-
32
+
19
33
  this._setup();
20
34
  }
21
-
35
+
36
+ /**
37
+ * Initializes event listeners and timeout for automatic stop.
38
+ * @private
39
+ */
22
40
  _setup() {
23
41
  this.client.on('messageCreate', this._handleMessage);
24
-
42
+
25
43
  if (this.time) {
26
44
  this._timeout = setTimeout(() => {
27
45
  this.stop('time');
28
46
  }, this.time);
29
47
  }
30
48
  }
31
-
49
+
50
+ /**
51
+ * Internal handler for incoming messages.
52
+ * @param {Message} message - The message received.
53
+ * @private
54
+ */
32
55
  async _handleMessage(message) {
33
56
  if (this.ended) return;
34
57
  if (message.channel.id !== this.channel.id) return;
35
-
58
+
36
59
  try {
37
60
  const filterResult = await this.filter(message);
38
61
  if (!filterResult) return;
39
-
62
+
40
63
  this.collected.push(message);
41
64
  this.emit('collect', message);
42
-
65
+
43
66
  if (this.collected.length >= this.max) {
44
67
  this.stop('limit');
45
68
  }
@@ -47,28 +70,40 @@ class MessageCollector extends EventEmitter {
47
70
  this.emit('error', error);
48
71
  }
49
72
  }
50
-
51
- stop(reason = 'user', ) {
73
+
74
+ /**
75
+ * Stops the collector manually or automatically.
76
+ *
77
+ * @param {string} [reason='user'] - Reason for stopping ('user', 'time', 'limit', etc.).
78
+ * @fires MessageCollector#end
79
+ */
80
+ stop(reason = 'user') {
52
81
  if (this.ended) return;
53
-
82
+
54
83
  this.ended = true;
55
-
84
+
56
85
  if (this._timeout) {
57
86
  clearTimeout(this._timeout);
58
87
  this._timeout = null;
59
88
  }
60
-
89
+
61
90
  this.client.removeListener('messageCreate', this._handleMessage);
62
91
  this.emit('end', this.collected, reason);
63
92
  }
64
-
93
+
94
+ /**
95
+ * Resets the timer for the collector.
96
+ *
97
+ * @param {Object} [options={}] - Options to override current timer.
98
+ * @param {number} [options.time] - New time in milliseconds to set.
99
+ */
65
100
  resetTimer(options = {}) {
66
101
  if (this._timeout) {
67
102
  clearTimeout(this._timeout);
68
103
  }
69
-
104
+
70
105
  const time = options.time || this.time;
71
-
106
+
72
107
  if (time) {
73
108
  this._timeout = setTimeout(() => {
74
109
  this.stop('time');
@@ -77,4 +112,23 @@ class MessageCollector extends EventEmitter {
77
112
  }
78
113
  }
79
114
 
80
- module.exports = MessageCollector;
115
+ /**
116
+ * Emitted when a message is successfully collected.
117
+ * @event MessageCollector#collect
118
+ * @param {Message} message - The collected message.
119
+ */
120
+
121
+ /**
122
+ * Emitted when the collector ends.
123
+ * @event MessageCollector#end
124
+ * @param {Message[]} collected - Array of collected messages.
125
+ * @param {string} reason - Reason the collector ended.
126
+ */
127
+
128
+ /**
129
+ * Emitted when an error occurs inside the collector.
130
+ * @event MessageCollector#error
131
+ * @param {Error} error - The error encountered.
132
+ */
133
+
134
+ module.exports = MessageCollector;
@@ -1,7 +1,40 @@
1
1
  const { formatUrl } = require("../helpers");
2
+ let client;
2
3
 
4
+ /**
5
+ * @internal
6
+ */
3
7
  class User {
4
- constructor(data, client) {
8
+ /**
9
+ * Creates a new User instance.
10
+ * @param {Object} data - Raw user data.
11
+ * @param {string|number} data.id - The unique ID of the user.
12
+ * @param {string} data.username - The username of the user.
13
+ * @param {string} data.display_name - The display name of the user.
14
+ * @param {string} data.avatar_url - The URL of the user's avatar.
15
+ * @param {string} [data.status='offline'] - The user's status.
16
+ * @param {Array<Object>} [data.emblems=[]] - Array of user emblems.
17
+ * @param {boolean} data.is_bot - Whether the user is a bot.
18
+ * @param {string|number|Date} data.last_seen - Last seen timestamp.
19
+ * @param {string|number|Date} data.created_at - Account creation timestamp.
20
+ * @param {import('./Client')} clientInstance - The client instance.
21
+ * @returns {User} The created User instance.
22
+ * @example
23
+ * User {
24
+ * id: 1,
25
+ * username: 'junior9244',
26
+ * displayName: 'Junior',
27
+ * avatarUrl: 'https://api.beniocord.site/uploads/avatars/1760736025811-629632107.png',
28
+ * status: 'online',
29
+ * emblems: [ [Object], [Object] ],
30
+ * isBot: false,
31
+ * lastSeen: '2025-11-16T14:44:19.394Z',
32
+ * createdAt: '2025-09-21T15:00:07.753Z'
33
+ * }
34
+ */
35
+ constructor(data, clientInstance) {
36
+ client = clientInstance;
37
+
5
38
  this.id = data.id;
6
39
  this.username = data.username;
7
40
  this.displayName = data.display_name;
@@ -11,17 +44,31 @@ class User {
11
44
  this.isBot = data.is_bot;
12
45
  this.lastSeen = data.last_seen;
13
46
  this.createdAt = data.created_at;
14
- // this.email = data.email;
15
- // this.updatedAt = data.updated_at;
16
47
  }
17
48
 
18
- // displayAvatarURL() {
19
- // return this.avatarUrl;
20
- // }
21
-
49
+ /**
50
+ * Returns the avatar URL of the user.
51
+ * @returns {string} The avatar URL.
52
+ * @example
53
+ * https://api.beniocord.site/uploads/avatars/1760736025811-629632107.png
54
+ */
22
55
  avatarURL() {
23
56
  return this.avatarUrl;
24
57
  }
58
+
59
+ /**
60
+ * Fetches or refreshes this user from the API.
61
+ * @param {boolean} [force=false] - Whether to force fetch even if cached.
62
+ * @returns {Promise<User>} The updated User instance.
63
+ * @example
64
+ * const freshUser = await user.fetch();
65
+ */
66
+ async fetch(force = false) {
67
+ if (!client) throw new Error("Client instance not available.");
68
+ const updatedUser = await client.fetchUser(this.id, force);
69
+ Object.assign(this, updatedUser);
70
+ return this;
71
+ }
25
72
  }
26
73
 
27
- module.exports = User;
74
+ module.exports = User;