discord-self-lite 0.1.11 → 0.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discord-self-lite",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Lightweight Discord selfbot library",
5
5
  "keywords": [
6
6
  "discord",
@@ -135,7 +135,7 @@ class Channel {
135
135
  * @returns {Guild|null} The guild instance or null if not a guild channel
136
136
  */
137
137
  getGuild() {
138
- const guildId = this.data.guild_id;
138
+ const guildId = this.guildId;
139
139
  if (!guildId) return null;
140
140
  return this.client.getGuild(guildId);
141
141
  }
@@ -145,7 +145,7 @@ class Channel {
145
145
  * @returns {Promise<Guild|null>} The guild instance or null if not a guild channel
146
146
  */
147
147
  async fetchGuild() {
148
- const guildId = this.data.guild_id;
148
+ const guildId = this.guildId;
149
149
  if (!guildId) return null;
150
150
  return await this.client.fetchGuild(guildId);
151
151
  }
@@ -214,7 +214,7 @@ class Channel {
214
214
  if (this.isDM() || this.isGroupDM()) {
215
215
  return `https://discord.com/channels/@me/${this.id}`;
216
216
  }
217
- const guildId = this.data.guild_id;
217
+ const guildId = this.guildId;
218
218
  return `https://discord.com/channels/${guildId}/${this.id}`;
219
219
  }
220
220
 
@@ -235,8 +235,8 @@ class Channel {
235
235
  }
236
236
 
237
237
  // Apply channel permission overwrites
238
- if (this.data.permission_overwrites) {
239
- const overwrites = this.data.permission_overwrites;
238
+ if (this.permissionOverwrites) {
239
+ const overwrites = this.permissionOverwrites;
240
240
 
241
241
  // Role overwrites (deny takes precedence over allow)
242
242
  const memberRoles = member.roles || [];
@@ -245,7 +245,7 @@ class Channel {
245
245
  // Role overwrite
246
246
  if (
247
247
  memberRoles.includes(overwrite.id) ||
248
- overwrite.id === this.data.guild_id
248
+ overwrite.id === this.guildId
249
249
  ) {
250
250
  permissions &= ~toBigInt(overwrite.deny || 0);
251
251
  permissions |= toBigInt(overwrite.allow || 0);
@@ -105,10 +105,10 @@ class Guild {
105
105
  * @returns {string|null} The icon URL or null if no icon
106
106
  */
107
107
  getIconURL(options = {}) {
108
- if (!this.data.icon) return null;
108
+ if (!this.icon) return null;
109
109
  const size = options.size || 512;
110
110
  const format = options.format || "png";
111
- return `https://cdn.discordapp.com/icons/${this.id}/${this.data.icon}.${format}?size=${size}`;
111
+ return `https://cdn.discordapp.com/icons/${this.id}/${this.icon}.${format}?size=${size}`;
112
112
  }
113
113
 
114
114
  /**
@@ -119,10 +119,10 @@ class Guild {
119
119
  * @returns {string|null} The banner URL or null if no banner
120
120
  */
121
121
  getBannerURL(options = {}) {
122
- if (!this.data.banner) return null;
122
+ if (!this.banner) return null;
123
123
  const size = options.size || 512;
124
124
  const format = options.format || "png";
125
- return `https://cdn.discordapp.com/banners/${this.id}/${this.data.banner}.${format}?size=${size}`;
125
+ return `https://cdn.discordapp.com/banners/${this.id}/${this.banner}.${format}?size=${size}`;
126
126
  }
127
127
 
128
128
  /**
@@ -1,5 +1,21 @@
1
1
  const User = require("./User");
2
2
 
3
+ function camelCaseKeys(obj) {
4
+ if (Array.isArray(obj)) {
5
+ return obj.map((item) => camelCaseKeys(item));
6
+ } else if (obj !== null && typeof obj === "object") {
7
+ const newObj = {};
8
+ for (const [key, value] of Object.entries(obj)) {
9
+ const camelKey = key.replace(/_([a-z])/g, (_, letter) =>
10
+ letter.toUpperCase(),
11
+ );
12
+ newObj[camelKey] = camelCaseKeys(value);
13
+ }
14
+ return newObj;
15
+ }
16
+ return obj;
17
+ }
18
+
3
19
  /**
4
20
  * Represents a Discord message
5
21
  */
@@ -31,9 +47,9 @@ class Message {
31
47
  }
32
48
  }
33
49
 
34
- this.components = this.components || [];
50
+ this.components = camelCaseKeys(this.components || []);
35
51
  this.attachments = this.attachments || [];
36
- this.embeds = this.embeds || [];
52
+ this.embeds = camelCaseKeys(this.embeds || []);
37
53
  this.mentions = this.mentions || [];
38
54
  this.mentionRoles = this.mentionRoles || [];
39
55
  this.reactions = this.reactions || [];
@@ -65,9 +81,9 @@ class Message {
65
81
  this[camelKey] = value;
66
82
  }
67
83
 
68
- this.components = this.components || [];
84
+ this.components = camelCaseKeys(this.components || []);
69
85
  this.attachments = this.attachments || [];
70
- this.embeds = this.embeds || [];
86
+ this.embeds = camelCaseKeys(this.embeds || []);
71
87
  this.mentions = this.mentions || [];
72
88
  this.mentionRoles = this.mentionRoles || [];
73
89
  this.reactions = this.reactions || [];
@@ -117,11 +133,11 @@ class Message {
117
133
 
118
134
  // Get all buttons from components
119
135
  const buttons = [];
120
- if (this.data.components && Array.isArray(this.data.components)) {
121
- for (const row of this.data.components) {
136
+ if (this.components && Array.isArray(this.components)) {
137
+ for (const row of this.components) {
122
138
  if (row.components && Array.isArray(row.components)) {
123
139
  for (const component of row.components) {
124
- if (component.type === 2 && component.custom_id) {
140
+ if (component.type === 2 && component.customId) {
125
141
  // Type 2 is button
126
142
  buttons.push(component);
127
143
  }
@@ -137,7 +153,7 @@ class Message {
137
153
  // Handle different input types
138
154
  if (input === null) {
139
155
  // No input: click first button
140
- customId = buttons[0].custom_id;
156
+ customId = buttons[0].customId;
141
157
  } else if (typeof input === "number") {
142
158
  // Integer input: click button at that index
143
159
  if (input < 0 || input >= buttons.length) {
@@ -147,17 +163,17 @@ class Message {
147
163
  } button(s) (0-${buttons.length - 1})`,
148
164
  );
149
165
  }
150
- customId = buttons[input].custom_id;
166
+ customId = buttons[input].customId;
151
167
  } else if (typeof input === "string") {
152
- // String input: use as custom_id directly (preserving original behavior)
168
+ // String input: use as customId directly
153
169
  customId = input;
154
170
  } else {
155
171
  throw new Error("Invalid input type. Expected null, number, or string.");
156
172
  }
157
173
 
158
174
  // Get required data for button interaction
159
- const applicationId = this.data.application_id || this.author.id;
160
- const messageFlags = this.data.flags || 0;
175
+ const applicationId = this.applicationId || this.author.id;
176
+ const messageFlags = this.flags || 0;
161
177
 
162
178
  if (!this.client.sessionId) {
163
179
  throw new Error(
@@ -207,13 +223,15 @@ class Message {
207
223
  let channel;
208
224
  try {
209
225
  channel = await this.client.resolveChannel(channelId);
210
- } catch {
226
+ } catch (error) {
227
+ console.error(error);
211
228
  return null;
212
229
  }
213
230
 
214
231
  try {
215
232
  return await channel.fetchMessage(messageId);
216
- } catch {
233
+ } catch (error) {
234
+ console.error(error);
217
235
  return null;
218
236
  }
219
237
  }
@@ -680,7 +680,19 @@ class RestManager {
680
680
  * @returns {Promise<object>} Message data
681
681
  */
682
682
  async fetchMessage(channelId, messageId) {
683
- return await this.request(`/channels/${channelId}/messages/${messageId}`);
683
+ const messages = await this.request(
684
+ `/channels/${channelId}/messages?limit=1&around=${messageId}`,
685
+ );
686
+ if (Array.isArray(messages)) {
687
+ const message = messages.find((m) => m.id === messageId);
688
+ if (message) return message;
689
+ }
690
+ throw new DiscordAPIError(
691
+ "Unknown Message",
692
+ 404,
693
+ `/channels/${channelId}/messages/${messageId}`,
694
+ { message: "Unknown Message", code: 10008 },
695
+ );
684
696
  }
685
697
 
686
698
  /**