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
package/src/classes/Channel.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
239
|
-
const overwrites = this.
|
|
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.
|
|
248
|
+
overwrite.id === this.guildId
|
|
249
249
|
) {
|
|
250
250
|
permissions &= ~toBigInt(overwrite.deny || 0);
|
|
251
251
|
permissions |= toBigInt(overwrite.allow || 0);
|
package/src/classes/Guild.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
125
|
+
return `https://cdn.discordapp.com/banners/${this.id}/${this.banner}.${format}?size=${size}`;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
package/src/classes/Message.js
CHANGED
|
@@ -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.
|
|
121
|
-
for (const row of this.
|
|
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.
|
|
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].
|
|
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].
|
|
166
|
+
customId = buttons[input].customId;
|
|
151
167
|
} else if (typeof input === "string") {
|
|
152
|
-
// String input: use as
|
|
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.
|
|
160
|
-
const messageFlags = this.
|
|
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
|
-
|
|
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
|
/**
|