discord-self-lite 0.1.12 → 0.1.13

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.12",
3
+ "version": "0.1.13",
4
4
  "description": "Lightweight Discord selfbot library",
5
5
  "keywords": [
6
6
  "discord",
@@ -53,6 +53,8 @@ class Message {
53
53
  this.mentions = this.mentions || [];
54
54
  this.mentionRoles = this.mentionRoles || [];
55
55
  this.reactions = this.reactions || [];
56
+ this.guildId =
57
+ this.guildId || this.client.getChannel(this.channelId)?.guildId || null;
56
58
  this.url = `https://discord.com/channels/${this.guildId ? this.guildId : "@me"}/${this.channelId}/${this.id}`;
57
59
  }
58
60
 
@@ -22,18 +22,79 @@ function resolveColor(color) {
22
22
  class WebhookClient {
23
23
  /**
24
24
  * Create a new WebhookClient
25
- * @param {string} url - The webhook URL
26
- * @param {object} [options={}] - Default options for the webhook
27
- * @param {string} [options.username] - Default username for the webhook
28
- * @param {string} [options.avatarURL] - Default avatar URL for the webhook
25
+ * @param {string|object} urlOrId - The webhook URL, an object containing `id` and `token` (or `url`), or just the webhook ID
26
+ * @param {string|object} [tokenOrOptions={}] - The webhook token (if first arg is ID) or default options
27
+ * @param {object} [options={}] - Default options for the webhook (if first two args are ID and token)
29
28
  */
30
- constructor(url, options = {}) {
31
- this.url = url;
32
- this.options = {
33
- username: options.username || null,
34
- avatarURL: options.avatarURL || null,
35
- ...options,
36
- };
29
+ constructor(urlOrId, tokenOrOptions = {}, options = {}) {
30
+ if (typeof urlOrId === "object" && urlOrId !== null) {
31
+ // constructor({ id, token, url, ...options }, options)
32
+ const data = urlOrId;
33
+ const opts = tokenOrOptions || {};
34
+
35
+ if (data.url) {
36
+ this.url = data.url;
37
+ try {
38
+ const parsed = WebhookClient.parseURL(data.url);
39
+ this.id = parsed.id;
40
+ this.token = parsed.token;
41
+ } catch {
42
+ // Ignore parse errors for custom/mock URLs
43
+ }
44
+ } else if (data.id && data.token) {
45
+ this.id = data.id.toString();
46
+ this.token = data.token;
47
+ this.url = `https://discord.com/api/webhooks/${this.id}/${this.token}`;
48
+ } else {
49
+ throw new Error(
50
+ "WebhookClient requires either a URL or an ID and Token",
51
+ );
52
+ }
53
+
54
+ this.options = {
55
+ username: data.username || opts.username || null,
56
+ avatarURL: data.avatarURL || opts.avatarURL || null,
57
+ ...data,
58
+ ...opts,
59
+ };
60
+
61
+ // Clean up internal keys from options
62
+ delete this.options.id;
63
+ delete this.options.token;
64
+ delete this.options.url;
65
+ } else if (
66
+ typeof urlOrId === "string" &&
67
+ typeof tokenOrOptions === "string"
68
+ ) {
69
+ // constructor(id, token, options)
70
+ this.id = urlOrId;
71
+ this.token = tokenOrOptions;
72
+ this.url = `https://discord.com/api/webhooks/${this.id}/${this.token}`;
73
+ this.options = {
74
+ username: options.username || null,
75
+ avatarURL: options.avatarURL || null,
76
+ ...options,
77
+ };
78
+ } else if (typeof urlOrId === "string") {
79
+ // constructor(url, options)
80
+ this.url = urlOrId;
81
+ try {
82
+ const parsed = WebhookClient.parseURL(urlOrId);
83
+ this.id = parsed.id;
84
+ this.token = parsed.token;
85
+ } catch {
86
+ // Ignore parse errors for custom/mock URLs
87
+ }
88
+ this.options = {
89
+ username: tokenOrOptions.username || null,
90
+ avatarURL: tokenOrOptions.avatarURL || null,
91
+ ...tokenOrOptions,
92
+ };
93
+ } else {
94
+ throw new Error(
95
+ "Invalid parameters provided to WebhookClient constructor",
96
+ );
97
+ }
37
98
  }
38
99
 
39
100
  /**