@impulsedev/chameleon 2.0.0 → 3.1.0
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/README.md +1 -0
- package/dist/{builders-CCZQJXF6.js → builders-WHD6LQWX.js} +5 -1
- package/dist/{chunk-F2RRJ7OJ.js → chunk-G4SUOXGV.js} +61 -0
- package/dist/index.d.ts +1019 -563
- package/dist/index.js +1586 -97
- package/package.json +1 -1
- package/diff.txt +0 -3086
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
buildGuild,
|
|
16
16
|
buildIntegration,
|
|
17
17
|
buildInteraction,
|
|
18
|
+
buildInvite,
|
|
18
19
|
buildMember,
|
|
19
20
|
buildMessage,
|
|
20
21
|
buildRole,
|
|
@@ -24,13 +25,15 @@ import {
|
|
|
24
25
|
buildStickerItem,
|
|
25
26
|
buildUser,
|
|
26
27
|
buildVoiceState,
|
|
28
|
+
buildWebhook,
|
|
27
29
|
resolveChannel,
|
|
28
30
|
resolveGuild,
|
|
29
31
|
resolveRole,
|
|
30
32
|
resolveUser,
|
|
31
33
|
serializeComponent,
|
|
34
|
+
toCamelCase,
|
|
32
35
|
toSnakeCase
|
|
33
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-G4SUOXGV.js";
|
|
34
37
|
|
|
35
38
|
// src/types/user/index.ts
|
|
36
39
|
var UserFlag = {
|
|
@@ -602,49 +605,97 @@ var WebhookType = {
|
|
|
602
605
|
APPLICATION: 3
|
|
603
606
|
};
|
|
604
607
|
|
|
608
|
+
// src/utils/collection.ts
|
|
609
|
+
var Collection = class _Collection extends Map {
|
|
610
|
+
first() {
|
|
611
|
+
return this.values().next().value;
|
|
612
|
+
}
|
|
613
|
+
last() {
|
|
614
|
+
const arr = Array.from(this.values());
|
|
615
|
+
return arr[arr.length - 1];
|
|
616
|
+
}
|
|
617
|
+
random() {
|
|
618
|
+
const arr = Array.from(this.values());
|
|
619
|
+
return arr[Math.floor(Math.random() * arr.length)];
|
|
620
|
+
}
|
|
621
|
+
find(fn) {
|
|
622
|
+
for (const [key, val] of this) {
|
|
623
|
+
if (fn(val, key, this)) return val;
|
|
624
|
+
}
|
|
625
|
+
return void 0;
|
|
626
|
+
}
|
|
627
|
+
filter(fn) {
|
|
628
|
+
const results = new _Collection();
|
|
629
|
+
for (const [key, val] of this) {
|
|
630
|
+
if (fn(val, key, this)) results.set(key, val);
|
|
631
|
+
}
|
|
632
|
+
return results;
|
|
633
|
+
}
|
|
634
|
+
map(fn) {
|
|
635
|
+
const results = [];
|
|
636
|
+
for (const [key, val] of this) {
|
|
637
|
+
results.push(fn(val, key, this));
|
|
638
|
+
}
|
|
639
|
+
return results;
|
|
640
|
+
}
|
|
641
|
+
some(fn) {
|
|
642
|
+
for (const [key, val] of this) {
|
|
643
|
+
if (fn(val, key, this)) return true;
|
|
644
|
+
}
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
every(fn) {
|
|
648
|
+
for (const [key, val] of this) {
|
|
649
|
+
if (!fn(val, key, this)) return false;
|
|
650
|
+
}
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
reduce(fn, initialValue) {
|
|
654
|
+
let accumulator;
|
|
655
|
+
let init = false;
|
|
656
|
+
if (initialValue !== void 0) {
|
|
657
|
+
accumulator = initialValue;
|
|
658
|
+
init = true;
|
|
659
|
+
}
|
|
660
|
+
for (const [key, val] of this) {
|
|
661
|
+
if (!init) {
|
|
662
|
+
accumulator = val;
|
|
663
|
+
init = true;
|
|
664
|
+
} else {
|
|
665
|
+
accumulator = fn(accumulator, val, key, this);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return accumulator;
|
|
669
|
+
}
|
|
670
|
+
toArray() {
|
|
671
|
+
return Array.from(this.values());
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
|
|
605
675
|
// src/utils/tongue.ts
|
|
606
|
-
var Tongue = class {
|
|
607
|
-
map;
|
|
676
|
+
var Tongue = class extends Collection {
|
|
608
677
|
max;
|
|
609
678
|
constructor(maxSize = Infinity) {
|
|
610
|
-
|
|
679
|
+
super();
|
|
611
680
|
this.max = maxSize;
|
|
612
681
|
}
|
|
613
682
|
get(key) {
|
|
614
|
-
if (!
|
|
615
|
-
const val =
|
|
616
|
-
|
|
617
|
-
|
|
683
|
+
if (!super.has(key)) return void 0;
|
|
684
|
+
const val = super.get(key);
|
|
685
|
+
super.delete(key);
|
|
686
|
+
super.set(key, val);
|
|
618
687
|
return val;
|
|
619
688
|
}
|
|
620
689
|
set(key, val) {
|
|
621
|
-
if (
|
|
622
|
-
|
|
623
|
-
} else if (this.
|
|
624
|
-
const firstKey = this.
|
|
625
|
-
if (firstKey !== void 0)
|
|
690
|
+
if (super.has(key)) {
|
|
691
|
+
super.delete(key);
|
|
692
|
+
} else if (this.size >= this.max) {
|
|
693
|
+
const firstKey = this.keys().next().value;
|
|
694
|
+
if (firstKey !== void 0) super.delete(firstKey);
|
|
626
695
|
}
|
|
627
|
-
|
|
696
|
+
super.set(key, val);
|
|
628
697
|
return this;
|
|
629
698
|
}
|
|
630
|
-
has(key) {
|
|
631
|
-
return this.map.has(key);
|
|
632
|
-
}
|
|
633
|
-
delete(key) {
|
|
634
|
-
return this.map.delete(key);
|
|
635
|
-
}
|
|
636
|
-
clear() {
|
|
637
|
-
this.map.clear();
|
|
638
|
-
}
|
|
639
|
-
get size() {
|
|
640
|
-
return this.map.size;
|
|
641
|
-
}
|
|
642
|
-
values() {
|
|
643
|
-
return this.map.values();
|
|
644
|
-
}
|
|
645
|
-
keys() {
|
|
646
|
-
return this.map.keys();
|
|
647
|
-
}
|
|
648
699
|
};
|
|
649
700
|
|
|
650
701
|
// src/client/store.ts
|
|
@@ -661,19 +712,21 @@ var TongueStore = class {
|
|
|
661
712
|
scheduledEvents;
|
|
662
713
|
autoModRules;
|
|
663
714
|
integrations;
|
|
715
|
+
voiceStates;
|
|
664
716
|
constructor(options) {
|
|
665
|
-
this.guilds = new Tongue(options?.guilds ??
|
|
666
|
-
this.roles = new Tongue(options?.roles ??
|
|
667
|
-
this.channels = new Tongue(options?.channels ??
|
|
717
|
+
this.guilds = new Tongue(options?.guilds ?? 100);
|
|
718
|
+
this.roles = new Tongue(options?.roles ?? 5e3);
|
|
719
|
+
this.channels = new Tongue(options?.channels ?? 5e3);
|
|
668
720
|
this.members = new Tongue(options?.members ?? 1e3);
|
|
669
721
|
this.messages = new Tongue(options?.messages ?? 100);
|
|
670
|
-
this.users = new Tongue(options?.users ??
|
|
671
|
-
this.emojis = new Tongue(options?.emojis ??
|
|
672
|
-
this.stickers = new Tongue(options?.stickers ??
|
|
673
|
-
this.stageInstances = new Tongue(options?.stageInstances ??
|
|
674
|
-
this.scheduledEvents = new Tongue(options?.scheduledEvents ??
|
|
675
|
-
this.autoModRules = new Tongue(options?.autoModRules ??
|
|
676
|
-
this.integrations = new Tongue(options?.integrations ??
|
|
722
|
+
this.users = new Tongue(options?.users ?? 1e4);
|
|
723
|
+
this.emojis = new Tongue(options?.emojis ?? 5e3);
|
|
724
|
+
this.stickers = new Tongue(options?.stickers ?? 5e3);
|
|
725
|
+
this.stageInstances = new Tongue(options?.stageInstances ?? 1e3);
|
|
726
|
+
this.scheduledEvents = new Tongue(options?.scheduledEvents ?? 1e3);
|
|
727
|
+
this.autoModRules = new Tongue(options?.autoModRules ?? 1e3);
|
|
728
|
+
this.integrations = new Tongue(options?.integrations ?? 1e3);
|
|
729
|
+
this.voiceStates = new Tongue(options?.voiceStates ?? 5e3);
|
|
677
730
|
}
|
|
678
731
|
static memberKey(guildId, userId) {
|
|
679
732
|
return `${guildId}_${userId}`;
|
|
@@ -695,7 +748,7 @@ var Bucket = class {
|
|
|
695
748
|
resetTimestamp = 0;
|
|
696
749
|
promiseQueue = Promise.resolve();
|
|
697
750
|
async queue(fn) {
|
|
698
|
-
return new Promise((
|
|
751
|
+
return new Promise((resolve4, reject) => {
|
|
699
752
|
this.promiseQueue = this.promiseQueue.then(async () => {
|
|
700
753
|
while (true) {
|
|
701
754
|
if (this.remaining <= 0 && Date.now() < this.resetTimestamp) {
|
|
@@ -704,7 +757,7 @@ var Bucket = class {
|
|
|
704
757
|
this.remaining--;
|
|
705
758
|
try {
|
|
706
759
|
const res = await fn();
|
|
707
|
-
|
|
760
|
+
resolve4(res);
|
|
708
761
|
break;
|
|
709
762
|
} catch (e) {
|
|
710
763
|
if (e instanceof RateLimitError) {
|
|
@@ -724,13 +777,13 @@ var RateLimiter = class {
|
|
|
724
777
|
routeToBucket = /* @__PURE__ */ new Map();
|
|
725
778
|
buckets = /* @__PURE__ */ new Map();
|
|
726
779
|
getRoute(method, endpoint) {
|
|
727
|
-
const
|
|
780
|
+
const path4 = endpoint.replace(/\/([a-z-]+)\/(?:[0-9]{17,19})/g, (match, p1) => {
|
|
728
781
|
if (["channels", "guilds", "webhooks"].includes(p1)) {
|
|
729
782
|
return match;
|
|
730
783
|
}
|
|
731
784
|
return `/${p1}/:id`;
|
|
732
785
|
});
|
|
733
|
-
const reactionRoute =
|
|
786
|
+
const reactionRoute = path4.replace(/\/reactions\/[^/]+\/?(@me|[0-9]{17,19})?/g, "/reactions/:emoji/:id");
|
|
734
787
|
return `${method} ${reactionRoute}`;
|
|
735
788
|
}
|
|
736
789
|
async execute(method, endpoint, requestFn) {
|
|
@@ -797,8 +850,8 @@ var ChameleonREST = class {
|
|
|
797
850
|
* Internal generic request handler that doesn't throw, returning `{ ok: boolean, ... }` shape
|
|
798
851
|
*/
|
|
799
852
|
async request(method, endpoint, body, headers) {
|
|
800
|
-
const
|
|
801
|
-
const url = `${this.baseUrl}${
|
|
853
|
+
const path4 = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
854
|
+
const url = `${this.baseUrl}${path4}`;
|
|
802
855
|
const reqHeaders = {
|
|
803
856
|
"Authorization": `Bot ${this.token}`,
|
|
804
857
|
"User-Agent": "Chameleon (https://github.com/impulsedoes/chameleon)",
|
|
@@ -810,7 +863,7 @@ var ChameleonREST = class {
|
|
|
810
863
|
reqBody = JSON.stringify(body);
|
|
811
864
|
}
|
|
812
865
|
try {
|
|
813
|
-
const response = await this.limiter.execute(method,
|
|
866
|
+
const response = await this.limiter.execute(method, path4, () => fetch(url, {
|
|
814
867
|
method,
|
|
815
868
|
headers: reqHeaders,
|
|
816
869
|
...reqBody !== void 0 ? { body: reqBody } : {}
|
|
@@ -860,6 +913,62 @@ var ChameleonREST = class {
|
|
|
860
913
|
delete(endpoint, headers) {
|
|
861
914
|
return this.request("DELETE", endpoint, void 0, headers);
|
|
862
915
|
}
|
|
916
|
+
async requestWithFiles(method, endpoint, body, files, headers) {
|
|
917
|
+
const routePath = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
918
|
+
const url = `${this.baseUrl}${routePath}`;
|
|
919
|
+
const reqHeaders = {
|
|
920
|
+
"Authorization": `Bot ${this.token}`,
|
|
921
|
+
"User-Agent": "Chameleon (https://github.com/impulsedoes/chameleon)",
|
|
922
|
+
...headers
|
|
923
|
+
};
|
|
924
|
+
const formData = new FormData();
|
|
925
|
+
const jsonPayload = {
|
|
926
|
+
...body ?? {},
|
|
927
|
+
attachments: files.map((f, i) => f.toAttachmentJSON(i))
|
|
928
|
+
};
|
|
929
|
+
formData.append("payload_json", JSON.stringify(jsonPayload));
|
|
930
|
+
for (let i = 0; i < files.length; i++) {
|
|
931
|
+
const file = files[i];
|
|
932
|
+
const uint8 = file.data instanceof Uint8Array ? file.data : new Uint8Array(file.data);
|
|
933
|
+
const blob = new Blob([uint8], { type: file.contentType ?? "application/octet-stream" });
|
|
934
|
+
formData.append(`files[${i}]`, blob, file.name);
|
|
935
|
+
}
|
|
936
|
+
try {
|
|
937
|
+
const response = await this.limiter.execute(method, routePath, () => fetch(url, {
|
|
938
|
+
method,
|
|
939
|
+
headers: reqHeaders,
|
|
940
|
+
body: formData
|
|
941
|
+
}));
|
|
942
|
+
let data = null;
|
|
943
|
+
if (response.status !== 204) {
|
|
944
|
+
const text = await response.text();
|
|
945
|
+
if (text) {
|
|
946
|
+
try {
|
|
947
|
+
data = JSON.parse(text);
|
|
948
|
+
} catch {
|
|
949
|
+
data = text;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if (response.ok) {
|
|
954
|
+
return { ok: true, data };
|
|
955
|
+
}
|
|
956
|
+
const errData = data;
|
|
957
|
+
return {
|
|
958
|
+
ok: false,
|
|
959
|
+
status: response.status,
|
|
960
|
+
...typeof errData?.code === "number" ? { code: errData.code } : {},
|
|
961
|
+
message: typeof errData?.message === "string" ? errData.message : response.statusText,
|
|
962
|
+
raw: data
|
|
963
|
+
};
|
|
964
|
+
} catch (error) {
|
|
965
|
+
return {
|
|
966
|
+
ok: false,
|
|
967
|
+
status: 0,
|
|
968
|
+
message: error instanceof Error ? error.message : "Unknown network error"
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
}
|
|
863
972
|
};
|
|
864
973
|
|
|
865
974
|
// src/gateway/index.ts
|
|
@@ -1229,7 +1338,7 @@ var ChameleonGateway = class {
|
|
|
1229
1338
|
// package.json
|
|
1230
1339
|
var package_default = {
|
|
1231
1340
|
name: "@impulsedev/chameleon",
|
|
1232
|
-
version: "
|
|
1341
|
+
version: "3.0.0",
|
|
1233
1342
|
description: "highly optimized, memory-efficient, and fully type-safe Discord API library",
|
|
1234
1343
|
main: "dist/index.js",
|
|
1235
1344
|
types: "dist/index.d.ts",
|
|
@@ -1542,6 +1651,12 @@ var CommandManager = class {
|
|
|
1542
1651
|
}
|
|
1543
1652
|
this._deployCommands(commands).catch(console.error);
|
|
1544
1653
|
}
|
|
1654
|
+
registerGuild(guildId, ...commands) {
|
|
1655
|
+
for (const cmd of commands) {
|
|
1656
|
+
this._commands.set(cmd.name, cmd);
|
|
1657
|
+
}
|
|
1658
|
+
this._deployCommands(commands, guildId).catch(console.error);
|
|
1659
|
+
}
|
|
1545
1660
|
registerComponent(handler) {
|
|
1546
1661
|
this._components.push(handler);
|
|
1547
1662
|
}
|
|
@@ -1572,13 +1687,15 @@ var CommandManager = class {
|
|
|
1572
1687
|
this.register(...commands);
|
|
1573
1688
|
}
|
|
1574
1689
|
}
|
|
1575
|
-
async _deployCommands(commands) {
|
|
1690
|
+
async _deployCommands(commands, guildId) {
|
|
1576
1691
|
const payload = commands.map((c) => this._transformCommand(c));
|
|
1577
1692
|
if (this._client.user?.id) {
|
|
1578
|
-
|
|
1693
|
+
const url = guildId ? `/applications/${this._client.user.id}/guilds/${guildId}/commands` : `/applications/${this._client.user.id}/commands`;
|
|
1694
|
+
await this._client.rest.put(url, payload);
|
|
1579
1695
|
} else {
|
|
1580
1696
|
this._client.on("READY", async () => {
|
|
1581
|
-
|
|
1697
|
+
const url = guildId ? `/applications/${this._client.user.id}/guilds/${guildId}/commands` : `/applications/${this._client.user.id}/commands`;
|
|
1698
|
+
await this._client.rest.put(url, payload);
|
|
1582
1699
|
});
|
|
1583
1700
|
}
|
|
1584
1701
|
}
|
|
@@ -1957,7 +2074,14 @@ var UserManager = class extends BaseManager {
|
|
|
1957
2074
|
async createDM(userId) {
|
|
1958
2075
|
const result = await this.rest.post("/users/@me/channels", { recipient_id: userId });
|
|
1959
2076
|
if (!result.ok) return result;
|
|
1960
|
-
return { ok: true, data: (await import("./builders-
|
|
2077
|
+
return { ok: true, data: (await import("./builders-WHD6LQWX.js")).buildChannel(result.data) };
|
|
2078
|
+
}
|
|
2079
|
+
async editCurrent(payload) {
|
|
2080
|
+
const result = await this.rest.patch("/users/@me", toSnakeCase(payload));
|
|
2081
|
+
if (!result.ok) return result;
|
|
2082
|
+
const user = this.build(result.data);
|
|
2083
|
+
this.store.users.set(user.id, user);
|
|
2084
|
+
return { ok: true, data: user };
|
|
1961
2085
|
}
|
|
1962
2086
|
};
|
|
1963
2087
|
|
|
@@ -2054,6 +2178,56 @@ var MemberManager = class {
|
|
|
2054
2178
|
this.store.members.set(cacheKey, member);
|
|
2055
2179
|
return { ok: true, data: member };
|
|
2056
2180
|
}
|
|
2181
|
+
async list(options) {
|
|
2182
|
+
let url = `/guilds/${this.guildId}/members`;
|
|
2183
|
+
if (options) {
|
|
2184
|
+
const params = new URLSearchParams();
|
|
2185
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
2186
|
+
if (options.after) params.append("after", options.after);
|
|
2187
|
+
const qs = params.toString();
|
|
2188
|
+
if (qs) url += `?${qs}`;
|
|
2189
|
+
}
|
|
2190
|
+
const result = await this.rest.get(url);
|
|
2191
|
+
if (!result.ok) return result;
|
|
2192
|
+
const members = result.data.map((m) => {
|
|
2193
|
+
const member = buildMember(m, this.guildId, this.store);
|
|
2194
|
+
if (member.user) {
|
|
2195
|
+
this.store.members.set(TongueStore.memberKey(this.guildId, member.user.id), member);
|
|
2196
|
+
}
|
|
2197
|
+
return member;
|
|
2198
|
+
});
|
|
2199
|
+
return { ok: true, data: members };
|
|
2200
|
+
}
|
|
2201
|
+
async search(query, limit) {
|
|
2202
|
+
const params = new URLSearchParams({ query });
|
|
2203
|
+
if (limit) params.append("limit", limit.toString());
|
|
2204
|
+
const result = await this.rest.get(`/guilds/${this.guildId}/members/search?${params.toString()}`);
|
|
2205
|
+
if (!result.ok) return result;
|
|
2206
|
+
const members = result.data.map((m) => {
|
|
2207
|
+
const member = buildMember(m, this.guildId, this.store);
|
|
2208
|
+
if (member.user) {
|
|
2209
|
+
this.store.members.set(TongueStore.memberKey(this.guildId, member.user.id), member);
|
|
2210
|
+
}
|
|
2211
|
+
return member;
|
|
2212
|
+
});
|
|
2213
|
+
return { ok: true, data: members };
|
|
2214
|
+
}
|
|
2215
|
+
async addRole(userId, roleId, reason) {
|
|
2216
|
+
const headers = {};
|
|
2217
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2218
|
+
const result = await this.rest.put(`/guilds/${this.guildId}/members/${userId}/roles/${roleId}`, void 0, headers);
|
|
2219
|
+
return result;
|
|
2220
|
+
}
|
|
2221
|
+
async removeRole(userId, roleId, reason) {
|
|
2222
|
+
const headers = {};
|
|
2223
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2224
|
+
const result = await this.rest.delete(`/guilds/${this.guildId}/members/${userId}/roles/${roleId}`, headers);
|
|
2225
|
+
return result;
|
|
2226
|
+
}
|
|
2227
|
+
async timeout(userId, until, reason) {
|
|
2228
|
+
const isoString = until ? until instanceof Date ? until.toISOString() : new Date(until).toISOString() : null;
|
|
2229
|
+
return this.edit(userId, { communicationDisabledUntil: isoString }, reason);
|
|
2230
|
+
}
|
|
2057
2231
|
};
|
|
2058
2232
|
|
|
2059
2233
|
// src/managers/guild.ts
|
|
@@ -2115,6 +2289,148 @@ var GuildManager = class extends BaseManager {
|
|
|
2115
2289
|
if (result.ok) this.store.guilds.delete(guildId);
|
|
2116
2290
|
return result;
|
|
2117
2291
|
}
|
|
2292
|
+
async listEmojis(guildId) {
|
|
2293
|
+
const result = await this.rest.get(`/guilds/${guildId}/emojis`);
|
|
2294
|
+
if (!result.ok) return result;
|
|
2295
|
+
const emojis = result.data.map((e) => {
|
|
2296
|
+
const emoji = buildEmoji(e);
|
|
2297
|
+
this.store.emojis.set(emoji.id, emoji);
|
|
2298
|
+
return emoji;
|
|
2299
|
+
});
|
|
2300
|
+
return { ok: true, data: emojis };
|
|
2301
|
+
}
|
|
2302
|
+
async fetchEmoji(guildId, emojiId) {
|
|
2303
|
+
const cached = this.store.emojis.get(emojiId);
|
|
2304
|
+
if (cached) return { ok: true, data: cached };
|
|
2305
|
+
const result = await this.rest.get(`/guilds/${guildId}/emojis/${emojiId}`);
|
|
2306
|
+
if (!result.ok) return result;
|
|
2307
|
+
const emoji = buildEmoji(result.data);
|
|
2308
|
+
this.store.emojis.set(emoji.id, emoji);
|
|
2309
|
+
return { ok: true, data: emoji };
|
|
2310
|
+
}
|
|
2311
|
+
async createEmoji(guildId, payload, reason) {
|
|
2312
|
+
const headers = {};
|
|
2313
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2314
|
+
const result = await this.rest.post(`/guilds/${guildId}/emojis`, toSnakeCase(payload), headers);
|
|
2315
|
+
if (!result.ok) return result;
|
|
2316
|
+
const emoji = buildEmoji(result.data);
|
|
2317
|
+
this.store.emojis.set(emoji.id, emoji);
|
|
2318
|
+
return { ok: true, data: emoji };
|
|
2319
|
+
}
|
|
2320
|
+
async editEmoji(guildId, emojiId, payload, reason) {
|
|
2321
|
+
const headers = {};
|
|
2322
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2323
|
+
const result = await this.rest.patch(`/guilds/${guildId}/emojis/${emojiId}`, toSnakeCase(payload), headers);
|
|
2324
|
+
if (!result.ok) return result;
|
|
2325
|
+
const emoji = buildEmoji(result.data);
|
|
2326
|
+
this.store.emojis.set(emoji.id, emoji);
|
|
2327
|
+
return { ok: true, data: emoji };
|
|
2328
|
+
}
|
|
2329
|
+
async deleteEmoji(guildId, emojiId, reason) {
|
|
2330
|
+
const headers = {};
|
|
2331
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2332
|
+
const result = await this.rest.delete(`/guilds/${guildId}/emojis/${emojiId}`, headers);
|
|
2333
|
+
if (result.ok) this.store.emojis.delete(emojiId);
|
|
2334
|
+
return result;
|
|
2335
|
+
}
|
|
2336
|
+
async listStickers(guildId) {
|
|
2337
|
+
const result = await this.rest.get(`/guilds/${guildId}/stickers`);
|
|
2338
|
+
if (!result.ok) return result;
|
|
2339
|
+
const stickers = result.data.map((s) => {
|
|
2340
|
+
const sticker = buildSticker(s);
|
|
2341
|
+
this.store.stickers.set(sticker.id, sticker);
|
|
2342
|
+
return sticker;
|
|
2343
|
+
});
|
|
2344
|
+
return { ok: true, data: stickers };
|
|
2345
|
+
}
|
|
2346
|
+
async fetchSticker(guildId, stickerId) {
|
|
2347
|
+
const cached = this.store.stickers.get(stickerId);
|
|
2348
|
+
if (cached) return { ok: true, data: cached };
|
|
2349
|
+
const result = await this.rest.get(`/guilds/${guildId}/stickers/${stickerId}`);
|
|
2350
|
+
if (!result.ok) return result;
|
|
2351
|
+
const sticker = buildSticker(result.data);
|
|
2352
|
+
this.store.stickers.set(sticker.id, sticker);
|
|
2353
|
+
return { ok: true, data: sticker };
|
|
2354
|
+
}
|
|
2355
|
+
async listBans(guildId, options) {
|
|
2356
|
+
let url = `/guilds/${guildId}/bans`;
|
|
2357
|
+
if (options) {
|
|
2358
|
+
const params = new URLSearchParams();
|
|
2359
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
2360
|
+
if (options.before) params.append("before", options.before);
|
|
2361
|
+
if (options.after) params.append("after", options.after);
|
|
2362
|
+
const qs = params.toString();
|
|
2363
|
+
if (qs) url += `?${qs}`;
|
|
2364
|
+
}
|
|
2365
|
+
const result = await this.rest.get(url);
|
|
2366
|
+
if (!result.ok) return result;
|
|
2367
|
+
const bans = result.data.map((b) => ({
|
|
2368
|
+
reason: b.reason ?? null,
|
|
2369
|
+
user: buildUser(b.user)
|
|
2370
|
+
}));
|
|
2371
|
+
return { ok: true, data: bans };
|
|
2372
|
+
}
|
|
2373
|
+
async fetchBan(guildId, userId) {
|
|
2374
|
+
const result = await this.rest.get(`/guilds/${guildId}/bans/${userId}`);
|
|
2375
|
+
if (!result.ok) return result;
|
|
2376
|
+
const b = result.data;
|
|
2377
|
+
return {
|
|
2378
|
+
ok: true,
|
|
2379
|
+
data: { reason: b.reason ?? null, user: buildUser(b.user) }
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2382
|
+
async getInvites(guildId) {
|
|
2383
|
+
const result = await this.rest.get(`/guilds/${guildId}/invites`);
|
|
2384
|
+
if (!result.ok) return result;
|
|
2385
|
+
const invites = result.data.map((i) => buildInvite(i));
|
|
2386
|
+
return { ok: true, data: invites };
|
|
2387
|
+
}
|
|
2388
|
+
async getVanityURL(guildId) {
|
|
2389
|
+
const result = await this.rest.get(`/guilds/${guildId}/vanity-url`);
|
|
2390
|
+
if (!result.ok) return result;
|
|
2391
|
+
const data = result.data;
|
|
2392
|
+
return { ok: true, data: { code: data.code ?? null, uses: data.uses ?? 0 } };
|
|
2393
|
+
}
|
|
2394
|
+
async getPruneCount(guildId, options) {
|
|
2395
|
+
let url = `/guilds/${guildId}/prune`;
|
|
2396
|
+
if (options) {
|
|
2397
|
+
const params = new URLSearchParams();
|
|
2398
|
+
if (options.days) params.append("days", options.days.toString());
|
|
2399
|
+
if (options.includeRoles) params.append("include_roles", options.includeRoles.join(","));
|
|
2400
|
+
const qs = params.toString();
|
|
2401
|
+
if (qs) url += `?${qs}`;
|
|
2402
|
+
}
|
|
2403
|
+
const result = await this.rest.get(url);
|
|
2404
|
+
if (!result.ok) return result;
|
|
2405
|
+
return { ok: true, data: result.data.pruned ?? 0 };
|
|
2406
|
+
}
|
|
2407
|
+
async beginPrune(guildId, options, reason) {
|
|
2408
|
+
const headers = {};
|
|
2409
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2410
|
+
const result = await this.rest.post(`/guilds/${guildId}/prune`, toSnakeCase(options ?? {}), headers);
|
|
2411
|
+
if (!result.ok) return result;
|
|
2412
|
+
return { ok: true, data: result.data.pruned ?? null };
|
|
2413
|
+
}
|
|
2414
|
+
async fetchAuditLog(guildId, options) {
|
|
2415
|
+
let url = `/guilds/${guildId}/audit-logs`;
|
|
2416
|
+
if (options) {
|
|
2417
|
+
const params = new URLSearchParams();
|
|
2418
|
+
if (options.userId) params.append("user_id", options.userId);
|
|
2419
|
+
if (options.actionType !== void 0) params.append("action_type", options.actionType.toString());
|
|
2420
|
+
if (options.before) params.append("before", options.before);
|
|
2421
|
+
if (options.after) params.append("after", options.after);
|
|
2422
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
2423
|
+
const qs = params.toString();
|
|
2424
|
+
if (qs) url += `?${qs}`;
|
|
2425
|
+
}
|
|
2426
|
+
const result = await this.rest.get(url);
|
|
2427
|
+
if (!result.ok) return result;
|
|
2428
|
+
return { ok: true, data: toCamelCase(result.data) };
|
|
2429
|
+
}
|
|
2430
|
+
async leave(guildId) {
|
|
2431
|
+
const result = await this.rest.delete(`/users/@me/guilds/${guildId}`);
|
|
2432
|
+
return result;
|
|
2433
|
+
}
|
|
2118
2434
|
};
|
|
2119
2435
|
|
|
2120
2436
|
// src/managers/channel.ts
|
|
@@ -2149,6 +2465,35 @@ var ChannelManager = class extends BaseManager {
|
|
|
2149
2465
|
if (result.ok) this.store.channels.delete(channelId);
|
|
2150
2466
|
return result;
|
|
2151
2467
|
}
|
|
2468
|
+
async clone(channelId, options, reason) {
|
|
2469
|
+
const cached = this.store.channels.get(channelId);
|
|
2470
|
+
if (!cached) return { ok: false, status: 404, message: "Channel not found in cache" };
|
|
2471
|
+
const payload = { ...options };
|
|
2472
|
+
if (cached.name !== void 0) payload.name = cached.name;
|
|
2473
|
+
if (cached.type !== void 0) payload.type = cached.type;
|
|
2474
|
+
if (cached.topic !== void 0) payload.topic = cached.topic;
|
|
2475
|
+
if (cached.bitrate !== void 0) payload.bitrate = cached.bitrate;
|
|
2476
|
+
if (cached.userLimit !== void 0) payload.userLimit = cached.userLimit;
|
|
2477
|
+
if (cached.rateLimitPerUser !== void 0) payload.rateLimitPerUser = cached.rateLimitPerUser;
|
|
2478
|
+
if (cached.nsfw !== void 0) payload.nsfw = cached.nsfw;
|
|
2479
|
+
if (cached.position !== void 0) payload.position = cached.position;
|
|
2480
|
+
if (cached.parentId !== void 0) payload.parentId = cached.parentId;
|
|
2481
|
+
if (cached.permissionOverwrites !== void 0) payload.permissionOverwrites = cached.permissionOverwrites;
|
|
2482
|
+
if (!cached.guildId) return { ok: false, status: 400, message: "Cannot clone a DM channel" };
|
|
2483
|
+
return this.create(cached.guildId, payload, reason);
|
|
2484
|
+
}
|
|
2485
|
+
async setPositions(guildId, positions, reason) {
|
|
2486
|
+
const headers = {};
|
|
2487
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2488
|
+
const payload = positions.map((p) => ({
|
|
2489
|
+
id: p.id,
|
|
2490
|
+
...p.position !== void 0 ? { position: p.position } : {},
|
|
2491
|
+
...p.lockPermissions !== void 0 ? { lock_permissions: p.lockPermissions } : {},
|
|
2492
|
+
...p.parentId !== void 0 ? { parent_id: p.parentId } : {}
|
|
2493
|
+
}));
|
|
2494
|
+
const result = await this.rest.patch(`/guilds/${guildId}/channels`, payload, headers);
|
|
2495
|
+
return result;
|
|
2496
|
+
}
|
|
2152
2497
|
async updatePermissions(channelId, overwriteId, payload, reason) {
|
|
2153
2498
|
const headers = {};
|
|
2154
2499
|
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
@@ -2159,6 +2504,125 @@ var ChannelManager = class extends BaseManager {
|
|
|
2159
2504
|
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2160
2505
|
return await this.rest.delete(`/channels/${channelId}/permissions/${overwriteId}`, headers);
|
|
2161
2506
|
}
|
|
2507
|
+
async sendTyping(channelId) {
|
|
2508
|
+
const result = await this.rest.post(`/channels/${channelId}/typing`);
|
|
2509
|
+
return result;
|
|
2510
|
+
}
|
|
2511
|
+
async getInvites(channelId) {
|
|
2512
|
+
const result = await this.rest.get(`/channels/${channelId}/invites`);
|
|
2513
|
+
if (!result.ok) return result;
|
|
2514
|
+
const invites = result.data.map((i) => buildInvite(i));
|
|
2515
|
+
return { ok: true, data: invites };
|
|
2516
|
+
}
|
|
2517
|
+
async createInvite(channelId, options, reason) {
|
|
2518
|
+
const headers = {};
|
|
2519
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2520
|
+
const payload = options ? toSnakeCase(options) : {};
|
|
2521
|
+
const result = await this.rest.post(`/channels/${channelId}/invites`, payload, headers);
|
|
2522
|
+
if (!result.ok) return result;
|
|
2523
|
+
return { ok: true, data: buildInvite(result.data) };
|
|
2524
|
+
}
|
|
2525
|
+
async followAnnouncementChannel(channelId, webhookChannelId) {
|
|
2526
|
+
const result = await this.rest.post(`/channels/${channelId}/followers`, { webhook_channel_id: webhookChannelId });
|
|
2527
|
+
if (!result.ok) return result;
|
|
2528
|
+
const data = result.data;
|
|
2529
|
+
return { ok: true, data: { channelId: data.channel_id, webhookId: data.webhook_id } };
|
|
2530
|
+
}
|
|
2531
|
+
async createThread(channelId, options, reason) {
|
|
2532
|
+
const headers = {};
|
|
2533
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2534
|
+
const result = await this.rest.post(`/channels/${channelId}/threads`, toSnakeCase(options), headers);
|
|
2535
|
+
if (!result.ok) return result;
|
|
2536
|
+
const channel = this.build(result.data);
|
|
2537
|
+
this.store.channels.set(channel.id, channel);
|
|
2538
|
+
return { ok: true, data: channel };
|
|
2539
|
+
}
|
|
2540
|
+
async createThreadFromMessage(channelId, messageId, options, reason) {
|
|
2541
|
+
const headers = {};
|
|
2542
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2543
|
+
const result = await this.rest.post(`/channels/${channelId}/messages/${messageId}/threads`, toSnakeCase(options), headers);
|
|
2544
|
+
if (!result.ok) return result;
|
|
2545
|
+
const channel = this.build(result.data);
|
|
2546
|
+
this.store.channels.set(channel.id, channel);
|
|
2547
|
+
return { ok: true, data: channel };
|
|
2548
|
+
}
|
|
2549
|
+
async joinThread(channelId) {
|
|
2550
|
+
const result = await this.rest.put(`/channels/${channelId}/thread-members/@me`);
|
|
2551
|
+
return result;
|
|
2552
|
+
}
|
|
2553
|
+
async leaveThread(channelId) {
|
|
2554
|
+
const result = await this.rest.delete(`/channels/${channelId}/thread-members/@me`);
|
|
2555
|
+
return result;
|
|
2556
|
+
}
|
|
2557
|
+
async listActiveThreads(guildId) {
|
|
2558
|
+
const result = await this.rest.get(`/guilds/${guildId}/threads/active`);
|
|
2559
|
+
if (!result.ok) return result;
|
|
2560
|
+
const data = result.data;
|
|
2561
|
+
const threads = data.threads.map((t) => {
|
|
2562
|
+
const channel = this.build(t, guildId);
|
|
2563
|
+
this.store.channels.set(channel.id, channel);
|
|
2564
|
+
return channel;
|
|
2565
|
+
});
|
|
2566
|
+
return { ok: true, data: { threads, members: data.members } };
|
|
2567
|
+
}
|
|
2568
|
+
async listArchivedThreads(channelId, type, options) {
|
|
2569
|
+
let url = `/channels/${channelId}/threads/archived/${type}`;
|
|
2570
|
+
if (options) {
|
|
2571
|
+
const params = new URLSearchParams();
|
|
2572
|
+
if (options.before) params.append("before", options.before);
|
|
2573
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
2574
|
+
const qs = params.toString();
|
|
2575
|
+
if (qs) url += `?${qs}`;
|
|
2576
|
+
}
|
|
2577
|
+
const result = await this.rest.get(url);
|
|
2578
|
+
if (!result.ok) return result;
|
|
2579
|
+
const data = result.data;
|
|
2580
|
+
const threads = data.threads.map((t) => {
|
|
2581
|
+
const channel = this.build(t);
|
|
2582
|
+
this.store.channels.set(channel.id, channel);
|
|
2583
|
+
return channel;
|
|
2584
|
+
});
|
|
2585
|
+
return { ok: true, data: { threads, members: data.members, hasMore: data.has_more } };
|
|
2586
|
+
}
|
|
2587
|
+
async addThreadMember(channelId, userId) {
|
|
2588
|
+
const result = await this.rest.put(`/channels/${channelId}/thread-members/${userId}`);
|
|
2589
|
+
return result;
|
|
2590
|
+
}
|
|
2591
|
+
async removeThreadMember(channelId, userId) {
|
|
2592
|
+
const result = await this.rest.delete(`/channels/${channelId}/thread-members/${userId}`);
|
|
2593
|
+
return result;
|
|
2594
|
+
}
|
|
2595
|
+
async createForumThread(channelId, options, reason) {
|
|
2596
|
+
const headers = {};
|
|
2597
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2598
|
+
const messagePayload = {};
|
|
2599
|
+
if (options.message.content) messagePayload.content = options.message.content;
|
|
2600
|
+
if (options.message.embeds) {
|
|
2601
|
+
messagePayload.embeds = options.message.embeds.map(
|
|
2602
|
+
(e) => e && typeof e.toJSON === "function" ? e.toJSON() : e
|
|
2603
|
+
);
|
|
2604
|
+
}
|
|
2605
|
+
if (options.message.components) {
|
|
2606
|
+
messagePayload.components = options.message.components.map((c) => serializeComponent(c));
|
|
2607
|
+
}
|
|
2608
|
+
const payload = {
|
|
2609
|
+
name: options.name,
|
|
2610
|
+
message: messagePayload,
|
|
2611
|
+
...options.autoArchiveDuration !== void 0 ? { auto_archive_duration: options.autoArchiveDuration } : {},
|
|
2612
|
+
...options.rateLimitPerUser !== void 0 ? { rate_limit_per_user: options.rateLimitPerUser } : {},
|
|
2613
|
+
...options.appliedTags ? { applied_tags: options.appliedTags } : {}
|
|
2614
|
+
};
|
|
2615
|
+
let result;
|
|
2616
|
+
if (options.message.files && options.message.files.length > 0) {
|
|
2617
|
+
result = await this.rest.requestWithFiles("POST", `/channels/${channelId}/threads`, payload, options.message.files, headers);
|
|
2618
|
+
} else {
|
|
2619
|
+
result = await this.rest.post(`/channels/${channelId}/threads`, payload, headers);
|
|
2620
|
+
}
|
|
2621
|
+
if (!result.ok) return result;
|
|
2622
|
+
const channel = this.build(result.data);
|
|
2623
|
+
this.store.channels.set(channel.id, channel);
|
|
2624
|
+
return { ok: true, data: channel };
|
|
2625
|
+
}
|
|
2162
2626
|
};
|
|
2163
2627
|
|
|
2164
2628
|
// src/managers/message.ts
|
|
@@ -2182,6 +2646,7 @@ var MessageManager = class {
|
|
|
2182
2646
|
}
|
|
2183
2647
|
async send(channelId, payload) {
|
|
2184
2648
|
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
2649
|
+
let files;
|
|
2185
2650
|
if (typeof payload === "object") {
|
|
2186
2651
|
if (payload.embeds) {
|
|
2187
2652
|
data.embeds = payload.embeds.map((e) => e && typeof e.toJSON === "function" ? e.toJSON() : e);
|
|
@@ -2193,8 +2658,37 @@ var MessageManager = class {
|
|
|
2193
2658
|
data.message_reference = { message_id: payload.reply.messageId, fail_if_not_exists: payload.reply.failIfNotExists ?? true };
|
|
2194
2659
|
delete data.reply;
|
|
2195
2660
|
}
|
|
2661
|
+
if (payload.poll) {
|
|
2662
|
+
data.poll = {
|
|
2663
|
+
question: payload.poll.question,
|
|
2664
|
+
answers: payload.poll.answers.map((a) => ({
|
|
2665
|
+
...a.answerId !== void 0 ? { answer_id: a.answerId } : {},
|
|
2666
|
+
poll_media: a.pollMedia
|
|
2667
|
+
})),
|
|
2668
|
+
...payload.poll.duration !== void 0 ? { duration: payload.poll.duration } : {},
|
|
2669
|
+
...payload.poll.allowMultiselect !== void 0 ? { allow_multiselect: payload.poll.allowMultiselect } : {},
|
|
2670
|
+
...payload.poll.layoutType !== void 0 ? { layout_type: payload.poll.layoutType } : {}
|
|
2671
|
+
};
|
|
2672
|
+
}
|
|
2673
|
+
if (payload.tts !== void 0) data.tts = payload.tts;
|
|
2674
|
+
if (payload.flags !== void 0) data.flags = payload.flags;
|
|
2675
|
+
if (payload.nonce !== void 0) data.nonce = payload.nonce;
|
|
2676
|
+
if (payload.enforceNonce !== void 0) data.enforce_nonce = payload.enforceNonce;
|
|
2677
|
+
if (payload.stickerIds && payload.stickerIds.length > 0) {
|
|
2678
|
+
data.sticker_ids = payload.stickerIds;
|
|
2679
|
+
delete data.stickerIds;
|
|
2680
|
+
}
|
|
2681
|
+
if (payload.files && payload.files.length > 0) {
|
|
2682
|
+
files = payload.files;
|
|
2683
|
+
delete data.files;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
let result;
|
|
2687
|
+
if (files && files.length > 0) {
|
|
2688
|
+
result = await this.rest.requestWithFiles("POST", `/channels/${channelId}/messages`, data, files);
|
|
2689
|
+
} else {
|
|
2690
|
+
result = await this.rest.post(`/channels/${channelId}/messages`, data);
|
|
2196
2691
|
}
|
|
2197
|
-
const result = await this.rest.post(`/channels/${channelId}/messages`, data);
|
|
2198
2692
|
if (!result.ok) return result;
|
|
2199
2693
|
const message = buildMessage(result.data, this.store);
|
|
2200
2694
|
this.store.messages.set(message.id, message);
|
|
@@ -2202,6 +2696,7 @@ var MessageManager = class {
|
|
|
2202
2696
|
}
|
|
2203
2697
|
async edit(channelId, messageId, payload) {
|
|
2204
2698
|
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
2699
|
+
let files;
|
|
2205
2700
|
if (typeof payload === "object") {
|
|
2206
2701
|
if (payload.embeds) {
|
|
2207
2702
|
data.embeds = payload.embeds.map((e) => e && typeof e.toJSON === "function" ? e.toJSON() : e);
|
|
@@ -2209,8 +2704,17 @@ var MessageManager = class {
|
|
|
2209
2704
|
if (payload.components) {
|
|
2210
2705
|
data.components = payload.components.map((c) => serializeComponent(c));
|
|
2211
2706
|
}
|
|
2707
|
+
if (payload.files && payload.files.length > 0) {
|
|
2708
|
+
files = payload.files;
|
|
2709
|
+
delete data.files;
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
let result;
|
|
2713
|
+
if (files && files.length > 0) {
|
|
2714
|
+
result = await this.rest.requestWithFiles("PATCH", `/channels/${channelId}/messages/${messageId}`, data, files);
|
|
2715
|
+
} else {
|
|
2716
|
+
result = await this.rest.patch(`/channels/${channelId}/messages/${messageId}`, data);
|
|
2212
2717
|
}
|
|
2213
|
-
const result = await this.rest.patch(`/channels/${channelId}/messages/${messageId}`, data);
|
|
2214
2718
|
if (!result.ok) return result;
|
|
2215
2719
|
const oldMsg = this.store.messages.get(messageId);
|
|
2216
2720
|
const message = buildMessage(result.data, this.store, oldMsg);
|
|
@@ -2244,43 +2748,139 @@ var MessageManager = class {
|
|
|
2244
2748
|
});
|
|
2245
2749
|
return { ok: true, data: messages };
|
|
2246
2750
|
}
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
constructor(client) {
|
|
2252
|
-
this.client = client;
|
|
2751
|
+
async react(channelId, messageId, emoji) {
|
|
2752
|
+
const encodedEmoji = encodeURIComponent(emoji);
|
|
2753
|
+
const result = await this.rest.put(`/channels/${channelId}/messages/${messageId}/reactions/${encodedEmoji}/@me`);
|
|
2754
|
+
return result;
|
|
2253
2755
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
async
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2756
|
+
async removeReaction(channelId, messageId, emoji, userId = "@me") {
|
|
2757
|
+
const encodedEmoji = encodeURIComponent(emoji);
|
|
2758
|
+
const result = await this.rest.delete(`/channels/${channelId}/messages/${messageId}/reactions/${encodedEmoji}/${userId}`);
|
|
2759
|
+
return result;
|
|
2760
|
+
}
|
|
2761
|
+
async removeAllReactions(channelId, messageId, emoji) {
|
|
2762
|
+
let url = `/channels/${channelId}/messages/${messageId}/reactions`;
|
|
2763
|
+
if (emoji) url += `/${encodeURIComponent(emoji)}`;
|
|
2764
|
+
const result = await this.rest.delete(url);
|
|
2765
|
+
return result;
|
|
2766
|
+
}
|
|
2767
|
+
async getReactions(channelId, messageId, emoji, options) {
|
|
2768
|
+
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}`;
|
|
2769
|
+
if (options) {
|
|
2770
|
+
const params = new URLSearchParams();
|
|
2771
|
+
if (options.after) params.append("after", options.after);
|
|
2772
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
2773
|
+
if (options.type !== void 0) params.append("type", options.type.toString());
|
|
2774
|
+
const qs = params.toString();
|
|
2775
|
+
if (qs) url += `?${qs}`;
|
|
2776
|
+
}
|
|
2777
|
+
const result = await this.rest.get(url);
|
|
2778
|
+
if (!result.ok) return result;
|
|
2779
|
+
const users = result.data.map((userData) => {
|
|
2780
|
+
const user = buildUser(userData);
|
|
2781
|
+
this.store.users.set(user.id, user);
|
|
2782
|
+
return user;
|
|
2783
|
+
});
|
|
2784
|
+
return { ok: true, data: users };
|
|
2785
|
+
}
|
|
2786
|
+
async pin(channelId, messageId) {
|
|
2787
|
+
const result = await this.rest.put(`/channels/${channelId}/pins/${messageId}`);
|
|
2788
|
+
return result;
|
|
2789
|
+
}
|
|
2790
|
+
async unpin(channelId, messageId) {
|
|
2791
|
+
const result = await this.rest.delete(`/channels/${channelId}/pins/${messageId}`);
|
|
2792
|
+
return result;
|
|
2793
|
+
}
|
|
2794
|
+
async getPins(channelId) {
|
|
2795
|
+
const result = await this.rest.get(`/channels/${channelId}/pins`);
|
|
2796
|
+
if (!result.ok) return result;
|
|
2797
|
+
const messages = result.data.map((msgData) => {
|
|
2798
|
+
const msg = buildMessage(msgData, this.store);
|
|
2799
|
+
this.store.messages.set(msg.id, msg);
|
|
2800
|
+
return msg;
|
|
2801
|
+
});
|
|
2802
|
+
return { ok: true, data: messages };
|
|
2803
|
+
}
|
|
2804
|
+
async bulkDelete(channelId, messageIds) {
|
|
2805
|
+
const result = await this.rest.post(`/channels/${channelId}/messages/bulk-delete`, { messages: messageIds });
|
|
2806
|
+
if (result.ok) {
|
|
2807
|
+
for (const id of messageIds) {
|
|
2808
|
+
this.store.messages.delete(id);
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
return result;
|
|
2812
|
+
}
|
|
2813
|
+
async forward(channelId, messageId) {
|
|
2814
|
+
const result = await this.rest.post(`/channels/${channelId}/messages/${messageId}/crosspost`);
|
|
2815
|
+
if (!result.ok) return result;
|
|
2816
|
+
const oldMsg = this.store.messages.get(messageId);
|
|
2817
|
+
const message = buildMessage(result.data, this.store, oldMsg);
|
|
2818
|
+
this.store.messages.set(message.id, message);
|
|
2819
|
+
return { ok: true, data: message };
|
|
2820
|
+
}
|
|
2821
|
+
async endPoll(channelId, messageId) {
|
|
2822
|
+
const result = await this.rest.post(`/channels/${channelId}/polls/${messageId}/expire`);
|
|
2823
|
+
if (!result.ok) return result;
|
|
2824
|
+
const message = buildMessage(result.data, this.store);
|
|
2825
|
+
this.store.messages.set(message.id, message);
|
|
2826
|
+
return { ok: true, data: message };
|
|
2827
|
+
}
|
|
2828
|
+
async getPollAnswerVoters(channelId, messageId, answerId, options) {
|
|
2829
|
+
let url = `/channels/${channelId}/polls/${messageId}/answers/${answerId}`;
|
|
2830
|
+
if (options) {
|
|
2831
|
+
const params = new URLSearchParams();
|
|
2832
|
+
if (options.after) params.append("after", options.after);
|
|
2833
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
2834
|
+
const qs = params.toString();
|
|
2835
|
+
if (qs) url += `?${qs}`;
|
|
2836
|
+
}
|
|
2837
|
+
const result = await this.rest.get(url);
|
|
2838
|
+
if (!result.ok) return result;
|
|
2839
|
+
const data = result.data;
|
|
2840
|
+
const users = data.users.map((u) => {
|
|
2841
|
+
const user = buildUser(u);
|
|
2842
|
+
this.store.users.set(user.id, user);
|
|
2843
|
+
return user;
|
|
2844
|
+
});
|
|
2845
|
+
return { ok: true, data: users };
|
|
2846
|
+
}
|
|
2847
|
+
};
|
|
2848
|
+
|
|
2849
|
+
// src/managers/collector.ts
|
|
2850
|
+
var CollectorManager = class {
|
|
2851
|
+
constructor(client) {
|
|
2852
|
+
this.client = client;
|
|
2853
|
+
}
|
|
2854
|
+
client;
|
|
2855
|
+
/**
|
|
2856
|
+
* Waits for a specified number of messages in a given channel that pass the filter, if the time limit
|
|
2857
|
+
* is reached, resolves with the messages collected so far
|
|
2858
|
+
*/
|
|
2859
|
+
async awaitMessages(channelId, options = {}) {
|
|
2860
|
+
const { filter, max = 1, time = 15e3 } = options;
|
|
2861
|
+
return new Promise((resolve4) => {
|
|
2862
|
+
const messages = [];
|
|
2863
|
+
let timeoutId = null;
|
|
2864
|
+
const handler = (data) => {
|
|
2865
|
+
const msg = data.message;
|
|
2866
|
+
if (msg.channelId !== channelId) return;
|
|
2867
|
+
if (filter && !filter(msg)) return;
|
|
2868
|
+
messages.push(msg);
|
|
2869
|
+
if (messages.length >= max) {
|
|
2870
|
+
cleanup();
|
|
2871
|
+
resolve4(messages);
|
|
2872
|
+
}
|
|
2873
|
+
};
|
|
2874
|
+
const cleanup = () => {
|
|
2875
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
2876
|
+
this.client.off("MESSAGE_CREATE", handler);
|
|
2877
|
+
};
|
|
2878
|
+
this.client.on("MESSAGE_CREATE", handler);
|
|
2879
|
+
if (time > 0) {
|
|
2880
|
+
timeoutId = setTimeout(() => {
|
|
2881
|
+
cleanup();
|
|
2882
|
+
resolve4(messages);
|
|
2883
|
+
}, time);
|
|
2284
2884
|
}
|
|
2285
2885
|
});
|
|
2286
2886
|
}
|
|
@@ -2290,7 +2890,7 @@ var CollectorManager = class {
|
|
|
2290
2890
|
*/
|
|
2291
2891
|
async awaitComponent(messageId, options = {}) {
|
|
2292
2892
|
const { filter, time = 15e3 } = options;
|
|
2293
|
-
return new Promise((
|
|
2893
|
+
return new Promise((resolve4) => {
|
|
2294
2894
|
let timeoutId = null;
|
|
2295
2895
|
const handler = (data) => {
|
|
2296
2896
|
if (data.type !== "INTERACTION_CREATE") return;
|
|
@@ -2309,7 +2909,7 @@ var CollectorManager = class {
|
|
|
2309
2909
|
);
|
|
2310
2910
|
if (filter && !filter(ctx)) return;
|
|
2311
2911
|
cleanup();
|
|
2312
|
-
|
|
2912
|
+
resolve4(ctx);
|
|
2313
2913
|
};
|
|
2314
2914
|
const cleanup = () => {
|
|
2315
2915
|
if (timeoutId) clearTimeout(timeoutId);
|
|
@@ -2319,13 +2919,539 @@ var CollectorManager = class {
|
|
|
2319
2919
|
if (time > 0) {
|
|
2320
2920
|
timeoutId = setTimeout(() => {
|
|
2321
2921
|
cleanup();
|
|
2322
|
-
|
|
2922
|
+
resolve4(null);
|
|
2323
2923
|
}, time);
|
|
2324
2924
|
}
|
|
2325
2925
|
});
|
|
2326
2926
|
}
|
|
2327
2927
|
};
|
|
2328
2928
|
|
|
2929
|
+
// src/managers/webhook.ts
|
|
2930
|
+
var WebhookManager = class {
|
|
2931
|
+
constructor(rest, store) {
|
|
2932
|
+
this.rest = rest;
|
|
2933
|
+
this.store = store;
|
|
2934
|
+
}
|
|
2935
|
+
rest;
|
|
2936
|
+
store;
|
|
2937
|
+
async fetch(webhookId, token) {
|
|
2938
|
+
const url = token ? `/webhooks/${webhookId}/${token}` : `/webhooks/${webhookId}`;
|
|
2939
|
+
const result = await this.rest.get(url);
|
|
2940
|
+
if (!result.ok) return result;
|
|
2941
|
+
return { ok: true, data: buildWebhook(result.data) };
|
|
2942
|
+
}
|
|
2943
|
+
async fetchByChannel(channelId) {
|
|
2944
|
+
const result = await this.rest.get(`/channels/${channelId}/webhooks`);
|
|
2945
|
+
if (!result.ok) return result;
|
|
2946
|
+
const webhooks = result.data.map((w) => buildWebhook(w));
|
|
2947
|
+
return { ok: true, data: webhooks };
|
|
2948
|
+
}
|
|
2949
|
+
async fetchByGuild(guildId) {
|
|
2950
|
+
const result = await this.rest.get(`/guilds/${guildId}/webhooks`);
|
|
2951
|
+
if (!result.ok) return result;
|
|
2952
|
+
const webhooks = result.data.map((w) => buildWebhook(w));
|
|
2953
|
+
return { ok: true, data: webhooks };
|
|
2954
|
+
}
|
|
2955
|
+
async create(channelId, payload, reason) {
|
|
2956
|
+
const headers = {};
|
|
2957
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2958
|
+
const result = await this.rest.post(`/channels/${channelId}/webhooks`, toSnakeCase(payload), headers);
|
|
2959
|
+
if (!result.ok) return result;
|
|
2960
|
+
return { ok: true, data: buildWebhook(result.data) };
|
|
2961
|
+
}
|
|
2962
|
+
async edit(webhookId, payload, token, reason) {
|
|
2963
|
+
const headers = {};
|
|
2964
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2965
|
+
const url = token ? `/webhooks/${webhookId}/${token}` : `/webhooks/${webhookId}`;
|
|
2966
|
+
const result = await this.rest.patch(url, toSnakeCase(payload), headers);
|
|
2967
|
+
if (!result.ok) return result;
|
|
2968
|
+
return { ok: true, data: buildWebhook(result.data) };
|
|
2969
|
+
}
|
|
2970
|
+
async delete(webhookId, token, reason) {
|
|
2971
|
+
const headers = {};
|
|
2972
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2973
|
+
const url = token ? `/webhooks/${webhookId}/${token}` : `/webhooks/${webhookId}`;
|
|
2974
|
+
const result = await this.rest.delete(url, headers);
|
|
2975
|
+
return result;
|
|
2976
|
+
}
|
|
2977
|
+
async execute(webhookId, token, payload, options) {
|
|
2978
|
+
const data = typeof payload === "string" ? { content: payload } : { ...toSnakeCase(payload) };
|
|
2979
|
+
let files;
|
|
2980
|
+
if (typeof payload === "object") {
|
|
2981
|
+
if (payload.embeds) {
|
|
2982
|
+
data.embeds = payload.embeds.map((e) => e && typeof e.toJSON === "function" ? e.toJSON() : e);
|
|
2983
|
+
}
|
|
2984
|
+
if (payload.components) {
|
|
2985
|
+
data.components = payload.components.map((c) => serializeComponent(c));
|
|
2986
|
+
}
|
|
2987
|
+
if (payload.poll) {
|
|
2988
|
+
data.poll = {
|
|
2989
|
+
question: payload.poll.question,
|
|
2990
|
+
answers: payload.poll.answers.map((a) => ({
|
|
2991
|
+
...a.answerId !== void 0 ? { answer_id: a.answerId } : {},
|
|
2992
|
+
poll_media: a.pollMedia
|
|
2993
|
+
})),
|
|
2994
|
+
...payload.poll.duration !== void 0 ? { duration: payload.poll.duration } : {},
|
|
2995
|
+
...payload.poll.allowMultiselect !== void 0 ? { allow_multiselect: payload.poll.allowMultiselect } : {},
|
|
2996
|
+
...payload.poll.layoutType !== void 0 ? { layout_type: payload.poll.layoutType } : {}
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
if (payload.files && payload.files.length > 0) {
|
|
3000
|
+
files = payload.files;
|
|
3001
|
+
delete data.files;
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
let url = `/webhooks/${webhookId}/${token}`;
|
|
3005
|
+
const params = new URLSearchParams();
|
|
3006
|
+
if (options?.wait) params.append("wait", "true");
|
|
3007
|
+
if (options?.threadId) params.append("thread_id", options.threadId);
|
|
3008
|
+
const qs = params.toString();
|
|
3009
|
+
if (qs) url += `?${qs}`;
|
|
3010
|
+
let result;
|
|
3011
|
+
if (files && files.length > 0) {
|
|
3012
|
+
result = await this.rest.requestWithFiles("POST", url, data, files);
|
|
3013
|
+
} else {
|
|
3014
|
+
result = await this.rest.post(url, data);
|
|
3015
|
+
}
|
|
3016
|
+
if (!result.ok) return result;
|
|
3017
|
+
if (options?.wait && result.data) {
|
|
3018
|
+
const message = buildMessage(result.data, this.store);
|
|
3019
|
+
this.store.messages.set(message.id, message);
|
|
3020
|
+
return { ok: true, data: message };
|
|
3021
|
+
}
|
|
3022
|
+
return { ok: true, data: void 0 };
|
|
3023
|
+
}
|
|
3024
|
+
};
|
|
3025
|
+
|
|
3026
|
+
// src/managers/invite.ts
|
|
3027
|
+
var InviteManager = class {
|
|
3028
|
+
constructor(rest) {
|
|
3029
|
+
this.rest = rest;
|
|
3030
|
+
}
|
|
3031
|
+
rest;
|
|
3032
|
+
async fetch(code, options) {
|
|
3033
|
+
let url = `/invites/${code}`;
|
|
3034
|
+
if (options) {
|
|
3035
|
+
const params = new URLSearchParams();
|
|
3036
|
+
if (options.withCounts) params.append("with_counts", "true");
|
|
3037
|
+
if (options.withExpiration) params.append("with_expiration", "true");
|
|
3038
|
+
if (options.guildScheduledEventId) params.append("guild_scheduled_event_id", options.guildScheduledEventId);
|
|
3039
|
+
const qs = params.toString();
|
|
3040
|
+
if (qs) url += `?${qs}`;
|
|
3041
|
+
}
|
|
3042
|
+
const result = await this.rest.get(url);
|
|
3043
|
+
if (!result.ok) return result;
|
|
3044
|
+
return { ok: true, data: buildInvite(result.data) };
|
|
3045
|
+
}
|
|
3046
|
+
async delete(code, reason) {
|
|
3047
|
+
const headers = {};
|
|
3048
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3049
|
+
const result = await this.rest.delete(`/invites/${code}`, headers);
|
|
3050
|
+
if (!result.ok) return result;
|
|
3051
|
+
return { ok: true, data: buildInvite(result.data) };
|
|
3052
|
+
}
|
|
3053
|
+
};
|
|
3054
|
+
|
|
3055
|
+
// src/managers/automod.ts
|
|
3056
|
+
var AutoModerationManager = class {
|
|
3057
|
+
constructor(rest, store) {
|
|
3058
|
+
this.rest = rest;
|
|
3059
|
+
this.store = store;
|
|
3060
|
+
}
|
|
3061
|
+
rest;
|
|
3062
|
+
store;
|
|
3063
|
+
async list(guildId) {
|
|
3064
|
+
const result = await this.rest.get(`/guilds/${guildId}/auto-moderation/rules`);
|
|
3065
|
+
if (!result.ok) return result;
|
|
3066
|
+
const rules = result.data.map((r) => {
|
|
3067
|
+
const rule = buildAutoModRule(r);
|
|
3068
|
+
this.store.autoModRules.set(rule.id, rule);
|
|
3069
|
+
return rule;
|
|
3070
|
+
});
|
|
3071
|
+
return { ok: true, data: rules };
|
|
3072
|
+
}
|
|
3073
|
+
async fetch(guildId, ruleId) {
|
|
3074
|
+
const cached = this.store.autoModRules.get(ruleId);
|
|
3075
|
+
if (cached) return { ok: true, data: cached };
|
|
3076
|
+
const result = await this.rest.get(`/guilds/${guildId}/auto-moderation/rules/${ruleId}`);
|
|
3077
|
+
if (!result.ok) return result;
|
|
3078
|
+
const rule = buildAutoModRule(result.data);
|
|
3079
|
+
this.store.autoModRules.set(rule.id, rule);
|
|
3080
|
+
return { ok: true, data: rule };
|
|
3081
|
+
}
|
|
3082
|
+
async create(guildId, payload, reason) {
|
|
3083
|
+
const headers = {};
|
|
3084
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3085
|
+
const result = await this.rest.post(`/guilds/${guildId}/auto-moderation/rules`, toSnakeCase(payload), headers);
|
|
3086
|
+
if (!result.ok) return result;
|
|
3087
|
+
const rule = buildAutoModRule(result.data);
|
|
3088
|
+
this.store.autoModRules.set(rule.id, rule);
|
|
3089
|
+
return { ok: true, data: rule };
|
|
3090
|
+
}
|
|
3091
|
+
async edit(guildId, ruleId, payload, reason) {
|
|
3092
|
+
const headers = {};
|
|
3093
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3094
|
+
const result = await this.rest.patch(`/guilds/${guildId}/auto-moderation/rules/${ruleId}`, toSnakeCase(payload), headers);
|
|
3095
|
+
if (!result.ok) return result;
|
|
3096
|
+
const rule = buildAutoModRule(result.data);
|
|
3097
|
+
this.store.autoModRules.set(rule.id, rule);
|
|
3098
|
+
return { ok: true, data: rule };
|
|
3099
|
+
}
|
|
3100
|
+
async delete(guildId, ruleId, reason) {
|
|
3101
|
+
const headers = {};
|
|
3102
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3103
|
+
const result = await this.rest.delete(`/guilds/${guildId}/auto-moderation/rules/${ruleId}`, headers);
|
|
3104
|
+
if (result.ok) this.store.autoModRules.delete(ruleId);
|
|
3105
|
+
return result;
|
|
3106
|
+
}
|
|
3107
|
+
};
|
|
3108
|
+
|
|
3109
|
+
// src/managers/scheduled.ts
|
|
3110
|
+
var ScheduledEventManager = class {
|
|
3111
|
+
constructor(rest, store) {
|
|
3112
|
+
this.rest = rest;
|
|
3113
|
+
this.store = store;
|
|
3114
|
+
}
|
|
3115
|
+
rest;
|
|
3116
|
+
store;
|
|
3117
|
+
async list(guildId, withUserCount) {
|
|
3118
|
+
let url = `/guilds/${guildId}/scheduled-events`;
|
|
3119
|
+
if (withUserCount) url += "?with_user_count=true";
|
|
3120
|
+
const result = await this.rest.get(url);
|
|
3121
|
+
if (!result.ok) return result;
|
|
3122
|
+
const events = result.data.map((e) => {
|
|
3123
|
+
const event = buildScheduledEvent(e);
|
|
3124
|
+
this.store.scheduledEvents.set(event.id, event);
|
|
3125
|
+
return event;
|
|
3126
|
+
});
|
|
3127
|
+
return { ok: true, data: events };
|
|
3128
|
+
}
|
|
3129
|
+
async fetch(guildId, eventId, withUserCount) {
|
|
3130
|
+
const cached = this.store.scheduledEvents.get(eventId);
|
|
3131
|
+
if (cached && !withUserCount) return { ok: true, data: cached };
|
|
3132
|
+
let url = `/guilds/${guildId}/scheduled-events/${eventId}`;
|
|
3133
|
+
if (withUserCount) url += "?with_user_count=true";
|
|
3134
|
+
const result = await this.rest.get(url);
|
|
3135
|
+
if (!result.ok) return result;
|
|
3136
|
+
const event = buildScheduledEvent(result.data);
|
|
3137
|
+
this.store.scheduledEvents.set(event.id, event);
|
|
3138
|
+
return { ok: true, data: event };
|
|
3139
|
+
}
|
|
3140
|
+
async create(guildId, payload, reason) {
|
|
3141
|
+
const headers = {};
|
|
3142
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3143
|
+
const result = await this.rest.post(`/guilds/${guildId}/scheduled-events`, toSnakeCase(payload), headers);
|
|
3144
|
+
if (!result.ok) return result;
|
|
3145
|
+
const event = buildScheduledEvent(result.data);
|
|
3146
|
+
this.store.scheduledEvents.set(event.id, event);
|
|
3147
|
+
return { ok: true, data: event };
|
|
3148
|
+
}
|
|
3149
|
+
async edit(guildId, eventId, payload, reason) {
|
|
3150
|
+
const headers = {};
|
|
3151
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3152
|
+
const result = await this.rest.patch(`/guilds/${guildId}/scheduled-events/${eventId}`, toSnakeCase(payload), headers);
|
|
3153
|
+
if (!result.ok) return result;
|
|
3154
|
+
const event = buildScheduledEvent(result.data);
|
|
3155
|
+
this.store.scheduledEvents.set(event.id, event);
|
|
3156
|
+
return { ok: true, data: event };
|
|
3157
|
+
}
|
|
3158
|
+
async delete(guildId, eventId) {
|
|
3159
|
+
const result = await this.rest.delete(`/guilds/${guildId}/scheduled-events/${eventId}`);
|
|
3160
|
+
if (result.ok) this.store.scheduledEvents.delete(eventId);
|
|
3161
|
+
return result;
|
|
3162
|
+
}
|
|
3163
|
+
async getUsers(guildId, eventId, options) {
|
|
3164
|
+
let url = `/guilds/${guildId}/scheduled-events/${eventId}/users`;
|
|
3165
|
+
if (options) {
|
|
3166
|
+
const params = new URLSearchParams();
|
|
3167
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
3168
|
+
if (options.withMember) params.append("with_member", "true");
|
|
3169
|
+
if (options.before) params.append("before", options.before);
|
|
3170
|
+
if (options.after) params.append("after", options.after);
|
|
3171
|
+
const qs = params.toString();
|
|
3172
|
+
if (qs) url += `?${qs}`;
|
|
3173
|
+
}
|
|
3174
|
+
const result = await this.rest.get(url);
|
|
3175
|
+
if (!result.ok) return result;
|
|
3176
|
+
const users = result.data.map((data) => {
|
|
3177
|
+
return {
|
|
3178
|
+
guildScheduledEventId: data.guild_scheduled_event_id,
|
|
3179
|
+
user: buildUser(data.user),
|
|
3180
|
+
member: data.member
|
|
3181
|
+
};
|
|
3182
|
+
});
|
|
3183
|
+
return { ok: true, data: users };
|
|
3184
|
+
}
|
|
3185
|
+
};
|
|
3186
|
+
|
|
3187
|
+
// src/managers/entitlement.ts
|
|
3188
|
+
var EntitlementManager = class {
|
|
3189
|
+
constructor(rest, store) {
|
|
3190
|
+
this.rest = rest;
|
|
3191
|
+
this.store = store;
|
|
3192
|
+
}
|
|
3193
|
+
rest;
|
|
3194
|
+
store;
|
|
3195
|
+
async list(applicationId, options) {
|
|
3196
|
+
let url = `/applications/${applicationId}/entitlements`;
|
|
3197
|
+
if (options) {
|
|
3198
|
+
const params = new URLSearchParams();
|
|
3199
|
+
if (options.userId) params.append("user_id", options.userId);
|
|
3200
|
+
if (options.skuIds) params.append("sku_ids", options.skuIds.join(","));
|
|
3201
|
+
if (options.before) params.append("before", options.before);
|
|
3202
|
+
if (options.after) params.append("after", options.after);
|
|
3203
|
+
if (options.limit) params.append("limit", options.limit.toString());
|
|
3204
|
+
if (options.guildId) params.append("guild_id", options.guildId);
|
|
3205
|
+
if (options.excludeEnded) params.append("exclude_ended", "true");
|
|
3206
|
+
const qs = params.toString();
|
|
3207
|
+
if (qs) url += `?${qs}`;
|
|
3208
|
+
}
|
|
3209
|
+
const result = await this.rest.get(url);
|
|
3210
|
+
if (!result.ok) return result;
|
|
3211
|
+
const entitlements = result.data.map((e) => buildEntitlement(e));
|
|
3212
|
+
return { ok: true, data: entitlements };
|
|
3213
|
+
}
|
|
3214
|
+
async fetch(applicationId, entitlementId) {
|
|
3215
|
+
const result = await this.rest.get(`/applications/${applicationId}/entitlements/${entitlementId}`);
|
|
3216
|
+
if (!result.ok) return result;
|
|
3217
|
+
return { ok: true, data: buildEntitlement(result.data) };
|
|
3218
|
+
}
|
|
3219
|
+
async createTest(applicationId, payload) {
|
|
3220
|
+
const result = await this.rest.post(`/applications/${applicationId}/entitlements`, toSnakeCase(payload));
|
|
3221
|
+
if (!result.ok) return result;
|
|
3222
|
+
return { ok: true, data: buildEntitlement(result.data) };
|
|
3223
|
+
}
|
|
3224
|
+
async deleteTest(applicationId, entitlementId) {
|
|
3225
|
+
const result = await this.rest.delete(`/applications/${applicationId}/entitlements/${entitlementId}`);
|
|
3226
|
+
return result;
|
|
3227
|
+
}
|
|
3228
|
+
};
|
|
3229
|
+
|
|
3230
|
+
// src/managers/stage.ts
|
|
3231
|
+
var StageInstanceManager = class {
|
|
3232
|
+
constructor(rest, store) {
|
|
3233
|
+
this.rest = rest;
|
|
3234
|
+
this.store = store;
|
|
3235
|
+
}
|
|
3236
|
+
rest;
|
|
3237
|
+
store;
|
|
3238
|
+
async fetch(channelId) {
|
|
3239
|
+
const cached = Array.from(this.store.stageInstances.values()).find((s) => s.channelId === channelId);
|
|
3240
|
+
if (cached) return { ok: true, data: cached };
|
|
3241
|
+
const result = await this.rest.get(`/stage-instances/${channelId}`);
|
|
3242
|
+
if (!result.ok) return result;
|
|
3243
|
+
const stage = buildStageInstance(result.data);
|
|
3244
|
+
this.store.stageInstances.set(stage.id, stage);
|
|
3245
|
+
return { ok: true, data: stage };
|
|
3246
|
+
}
|
|
3247
|
+
async create(payload, reason) {
|
|
3248
|
+
const headers = {};
|
|
3249
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3250
|
+
const result = await this.rest.post(`/stage-instances`, toSnakeCase(payload), headers);
|
|
3251
|
+
if (!result.ok) return result;
|
|
3252
|
+
const stage = buildStageInstance(result.data);
|
|
3253
|
+
this.store.stageInstances.set(stage.id, stage);
|
|
3254
|
+
return { ok: true, data: stage };
|
|
3255
|
+
}
|
|
3256
|
+
async edit(channelId, payload, reason) {
|
|
3257
|
+
const headers = {};
|
|
3258
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3259
|
+
const result = await this.rest.patch(`/stage-instances/${channelId}`, toSnakeCase(payload), headers);
|
|
3260
|
+
if (!result.ok) return result;
|
|
3261
|
+
const stage = buildStageInstance(result.data);
|
|
3262
|
+
this.store.stageInstances.set(stage.id, stage);
|
|
3263
|
+
return { ok: true, data: stage };
|
|
3264
|
+
}
|
|
3265
|
+
async delete(channelId, reason) {
|
|
3266
|
+
const headers = {};
|
|
3267
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
3268
|
+
const result = await this.rest.delete(`/stage-instances/${channelId}`, headers);
|
|
3269
|
+
if (result.ok) {
|
|
3270
|
+
const cached = Array.from(this.store.stageInstances.values()).find((s) => s.channelId === channelId);
|
|
3271
|
+
if (cached) this.store.stageInstances.delete(cached.id);
|
|
3272
|
+
}
|
|
3273
|
+
return result;
|
|
3274
|
+
}
|
|
3275
|
+
};
|
|
3276
|
+
|
|
3277
|
+
// src/managers/template.ts
|
|
3278
|
+
var TemplateManager = class {
|
|
3279
|
+
constructor(rest) {
|
|
3280
|
+
this.rest = rest;
|
|
3281
|
+
}
|
|
3282
|
+
rest;
|
|
3283
|
+
async fetch(code) {
|
|
3284
|
+
const result = await this.rest.get(`/guilds/templates/${code}`);
|
|
3285
|
+
if (!result.ok) return result;
|
|
3286
|
+
return { ok: true, data: toCamelCase(result.data) };
|
|
3287
|
+
}
|
|
3288
|
+
async createGuildFromTemplate(code, payload) {
|
|
3289
|
+
const result = await this.rest.post(`/guilds/templates/${code}`, toSnakeCase(payload));
|
|
3290
|
+
return result;
|
|
3291
|
+
}
|
|
3292
|
+
async list(guildId) {
|
|
3293
|
+
const result = await this.rest.get(`/guilds/${guildId}/templates`);
|
|
3294
|
+
if (!result.ok) return result;
|
|
3295
|
+
return { ok: true, data: result.data.map((t) => toCamelCase(t)) };
|
|
3296
|
+
}
|
|
3297
|
+
async create(guildId, payload) {
|
|
3298
|
+
const result = await this.rest.post(`/guilds/${guildId}/templates`, toSnakeCase(payload));
|
|
3299
|
+
if (!result.ok) return result;
|
|
3300
|
+
return { ok: true, data: toCamelCase(result.data) };
|
|
3301
|
+
}
|
|
3302
|
+
async sync(guildId, code) {
|
|
3303
|
+
const result = await this.rest.put(`/guilds/${guildId}/templates/${code}`);
|
|
3304
|
+
if (!result.ok) return result;
|
|
3305
|
+
return { ok: true, data: toCamelCase(result.data) };
|
|
3306
|
+
}
|
|
3307
|
+
async edit(guildId, code, payload) {
|
|
3308
|
+
const result = await this.rest.patch(`/guilds/${guildId}/templates/${code}`, toSnakeCase(payload));
|
|
3309
|
+
if (!result.ok) return result;
|
|
3310
|
+
return { ok: true, data: toCamelCase(result.data) };
|
|
3311
|
+
}
|
|
3312
|
+
async delete(guildId, code) {
|
|
3313
|
+
const result = await this.rest.delete(`/guilds/${guildId}/templates/${code}`);
|
|
3314
|
+
if (!result.ok) return result;
|
|
3315
|
+
return { ok: true, data: toCamelCase(result.data) };
|
|
3316
|
+
}
|
|
3317
|
+
};
|
|
3318
|
+
|
|
3319
|
+
// src/managers/application.ts
|
|
3320
|
+
var ApplicationManager = class {
|
|
3321
|
+
constructor(rest, _client) {
|
|
3322
|
+
this.rest = rest;
|
|
3323
|
+
this._client = _client;
|
|
3324
|
+
}
|
|
3325
|
+
rest;
|
|
3326
|
+
_client;
|
|
3327
|
+
async fetch() {
|
|
3328
|
+
const result = await this.rest.get("/oauth2/applications/@me");
|
|
3329
|
+
if (!result.ok) return result;
|
|
3330
|
+
return { ok: true, data: result.data };
|
|
3331
|
+
}
|
|
3332
|
+
async fetchRoleConnectionMetadata() {
|
|
3333
|
+
if (!this._client.user?.id) {
|
|
3334
|
+
return { ok: false, status: 400, message: "Client not ready" };
|
|
3335
|
+
}
|
|
3336
|
+
const result = await this.rest.get(`/applications/${this._client.user.id}/role-connections/metadata`);
|
|
3337
|
+
if (!result.ok) return result;
|
|
3338
|
+
return { ok: true, data: result.data };
|
|
3339
|
+
}
|
|
3340
|
+
async editRoleConnectionMetadata(records) {
|
|
3341
|
+
if (!this._client.user?.id) {
|
|
3342
|
+
return { ok: false, status: 400, message: "Client not ready" };
|
|
3343
|
+
}
|
|
3344
|
+
const result = await this.rest.put(`/applications/${this._client.user.id}/role-connections/metadata`, records);
|
|
3345
|
+
if (!result.ok) return result;
|
|
3346
|
+
return { ok: true, data: result.data };
|
|
3347
|
+
}
|
|
3348
|
+
};
|
|
3349
|
+
|
|
3350
|
+
// src/builders/attachment.ts
|
|
3351
|
+
import * as fs2 from "fs";
|
|
3352
|
+
import * as path2 from "path";
|
|
3353
|
+
var AttachmentBuilder = class {
|
|
3354
|
+
name;
|
|
3355
|
+
data;
|
|
3356
|
+
description;
|
|
3357
|
+
contentType;
|
|
3358
|
+
constructor(data, options) {
|
|
3359
|
+
if (typeof data === "string") {
|
|
3360
|
+
const resolved = path2.resolve(data);
|
|
3361
|
+
this.data = fs2.readFileSync(resolved);
|
|
3362
|
+
this.name = options?.name ?? path2.basename(resolved);
|
|
3363
|
+
} else {
|
|
3364
|
+
this.data = data;
|
|
3365
|
+
this.name = options?.name ?? "file.bin";
|
|
3366
|
+
}
|
|
3367
|
+
if (options?.description !== void 0) this.description = options.description;
|
|
3368
|
+
if (options?.contentType !== void 0) this.contentType = options.contentType;
|
|
3369
|
+
}
|
|
3370
|
+
setName(name) {
|
|
3371
|
+
this.name = name;
|
|
3372
|
+
return this;
|
|
3373
|
+
}
|
|
3374
|
+
setDescription(description) {
|
|
3375
|
+
this.description = description;
|
|
3376
|
+
return this;
|
|
3377
|
+
}
|
|
3378
|
+
toAttachmentJSON(index) {
|
|
3379
|
+
return {
|
|
3380
|
+
id: index,
|
|
3381
|
+
filename: this.name,
|
|
3382
|
+
...this.description ? { description: this.description } : {}
|
|
3383
|
+
};
|
|
3384
|
+
}
|
|
3385
|
+
};
|
|
3386
|
+
|
|
3387
|
+
// src/managers/soundboard.ts
|
|
3388
|
+
var SoundboardManager = class {
|
|
3389
|
+
constructor(rest) {
|
|
3390
|
+
this.rest = rest;
|
|
3391
|
+
}
|
|
3392
|
+
rest;
|
|
3393
|
+
async send(channelId, soundId, sourceGuildId) {
|
|
3394
|
+
const payload = {
|
|
3395
|
+
sound_id: soundId
|
|
3396
|
+
};
|
|
3397
|
+
if (sourceGuildId !== void 0) payload.source_guild_id = sourceGuildId;
|
|
3398
|
+
const result = await this.rest.post(`/channels/${channelId}/send-soundboard-sound`, payload);
|
|
3399
|
+
return result;
|
|
3400
|
+
}
|
|
3401
|
+
async fetchDefault() {
|
|
3402
|
+
const result = await this.rest.get("/soundboard-default-sounds");
|
|
3403
|
+
if (!result.ok) return result;
|
|
3404
|
+
return { ok: true, data: result.data };
|
|
3405
|
+
}
|
|
3406
|
+
async fetch(guildId, soundId) {
|
|
3407
|
+
if (soundId) {
|
|
3408
|
+
const result = await this.rest.get(`/guilds/${guildId}/soundboard-sounds/${soundId}`);
|
|
3409
|
+
if (!result.ok) return result;
|
|
3410
|
+
return { ok: true, data: result.data };
|
|
3411
|
+
} else {
|
|
3412
|
+
const result = await this.rest.get(`/guilds/${guildId}/soundboard-sounds`);
|
|
3413
|
+
if (!result.ok) return result;
|
|
3414
|
+
return { ok: true, data: result.data.items };
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
async create(guildId, options, reason) {
|
|
3418
|
+
let soundData = options.sound;
|
|
3419
|
+
if (options.sound instanceof AttachmentBuilder) {
|
|
3420
|
+
soundData = `data:${options.sound.contentType ?? "audio/ogg"};base64,${Buffer.from(options.sound.data).toString("base64")}`;
|
|
3421
|
+
}
|
|
3422
|
+
const payload = {
|
|
3423
|
+
name: options.name,
|
|
3424
|
+
sound: soundData
|
|
3425
|
+
};
|
|
3426
|
+
if (options.volume !== void 0) payload.volume = options.volume;
|
|
3427
|
+
if (options.emojiId !== void 0) payload.emoji_id = options.emojiId;
|
|
3428
|
+
if (options.emojiName !== void 0) payload.emoji_name = options.emojiName;
|
|
3429
|
+
const headers = {};
|
|
3430
|
+
if (reason) headers["X-Audit-Log-Reason"] = reason;
|
|
3431
|
+
const result = await this.rest.post(`/guilds/${guildId}/soundboard-sounds`, payload, headers);
|
|
3432
|
+
if (!result.ok) return result;
|
|
3433
|
+
return { ok: true, data: result.data };
|
|
3434
|
+
}
|
|
3435
|
+
async edit(guildId, soundId, options, reason) {
|
|
3436
|
+
const payload = {};
|
|
3437
|
+
if (options.name !== void 0) payload.name = options.name;
|
|
3438
|
+
if (options.volume !== void 0) payload.volume = options.volume;
|
|
3439
|
+
if (options.emojiId !== void 0) payload.emoji_id = options.emojiId;
|
|
3440
|
+
if (options.emojiName !== void 0) payload.emoji_name = options.emojiName;
|
|
3441
|
+
const headers = {};
|
|
3442
|
+
if (reason) headers["X-Audit-Log-Reason"] = reason;
|
|
3443
|
+
const result = await this.rest.patch(`/guilds/${guildId}/soundboard-sounds/${soundId}`, payload, headers);
|
|
3444
|
+
if (!result.ok) return result;
|
|
3445
|
+
return { ok: true, data: result.data };
|
|
3446
|
+
}
|
|
3447
|
+
async delete(guildId, soundId, reason) {
|
|
3448
|
+
const headers = {};
|
|
3449
|
+
if (reason) headers["X-Audit-Log-Reason"] = reason;
|
|
3450
|
+
const result = await this.rest.delete(`/guilds/${guildId}/soundboard-sounds/${soundId}`, headers);
|
|
3451
|
+
return result;
|
|
3452
|
+
}
|
|
3453
|
+
};
|
|
3454
|
+
|
|
2329
3455
|
// src/client/client.ts
|
|
2330
3456
|
var Client = class {
|
|
2331
3457
|
token;
|
|
@@ -2347,6 +3473,15 @@ var Client = class {
|
|
|
2347
3473
|
channels;
|
|
2348
3474
|
messages;
|
|
2349
3475
|
collectors;
|
|
3476
|
+
webhooks;
|
|
3477
|
+
invites;
|
|
3478
|
+
autoMod;
|
|
3479
|
+
scheduledEvents;
|
|
3480
|
+
entitlements;
|
|
3481
|
+
stageInstances;
|
|
3482
|
+
templates;
|
|
3483
|
+
application;
|
|
3484
|
+
soundboard;
|
|
2350
3485
|
listeners = /* @__PURE__ */ new Map();
|
|
2351
3486
|
middlewares = [];
|
|
2352
3487
|
constructor(options) {
|
|
@@ -2363,6 +3498,16 @@ var Client = class {
|
|
|
2363
3498
|
this.channels = new ChannelManager(this.rest, this.cache);
|
|
2364
3499
|
this.messages = new MessageManager(this.rest, this.cache);
|
|
2365
3500
|
this.collectors = new CollectorManager(this);
|
|
3501
|
+
this.webhooks = new WebhookManager(this.rest, this.cache);
|
|
3502
|
+
this.invites = new InviteManager(this.rest);
|
|
3503
|
+
this.autoMod = new AutoModerationManager(this.rest, this.cache);
|
|
3504
|
+
this.scheduledEvents = new ScheduledEventManager(this.rest, this.cache);
|
|
3505
|
+
this.entitlements = new EntitlementManager(this.rest, this.cache);
|
|
3506
|
+
this.stageInstances = new StageInstanceManager(this.rest, this.cache);
|
|
3507
|
+
this.templates = new TemplateManager(this.rest);
|
|
3508
|
+
this.application = new ApplicationManager(this.rest, this);
|
|
3509
|
+
this.soundboard = new SoundboardManager(this.rest);
|
|
3510
|
+
this.gateway = new ChameleonGateway({ token: this.token, intents: this.intents });
|
|
2366
3511
|
let shards = [0];
|
|
2367
3512
|
let totalShards = 1;
|
|
2368
3513
|
if (options.sharding === "auto") {
|
|
@@ -2422,13 +3567,30 @@ var Client = class {
|
|
|
2422
3567
|
this.listeners.get(event).push(listener);
|
|
2423
3568
|
return this;
|
|
2424
3569
|
}
|
|
3570
|
+
/**
|
|
3571
|
+
* register a one-time event listener that automatically removes itself after the first call
|
|
3572
|
+
*/
|
|
3573
|
+
once(event, listener) {
|
|
3574
|
+
const wrapper = (data) => {
|
|
3575
|
+
this.off(event, wrapper);
|
|
3576
|
+
listener(data);
|
|
3577
|
+
};
|
|
3578
|
+
wrapper.__original = listener;
|
|
3579
|
+
return this.on(event, wrapper);
|
|
3580
|
+
}
|
|
2425
3581
|
/**
|
|
2426
3582
|
* remove an event listener
|
|
2427
3583
|
*/
|
|
2428
3584
|
off(event, listener) {
|
|
2429
3585
|
const handlers = this.listeners.get(event);
|
|
2430
3586
|
if (!handlers) return this;
|
|
2431
|
-
const
|
|
3587
|
+
const castListener = listener;
|
|
3588
|
+
let index = handlers.indexOf(castListener);
|
|
3589
|
+
if (index === -1) {
|
|
3590
|
+
index = handlers.findIndex(
|
|
3591
|
+
(h) => h.__original === listener
|
|
3592
|
+
);
|
|
3593
|
+
}
|
|
2432
3594
|
if (index !== -1) {
|
|
2433
3595
|
handlers.splice(index, 1);
|
|
2434
3596
|
}
|
|
@@ -2890,9 +4052,20 @@ var Client = class {
|
|
|
2890
4052
|
break;
|
|
2891
4053
|
}
|
|
2892
4054
|
case "VOICE_STATE_UPDATE": {
|
|
4055
|
+
const guildId = d.guild_id;
|
|
4056
|
+
const userId = d.user_id;
|
|
4057
|
+
const key = guildId ? TongueStore.memberKey(guildId, userId) : userId;
|
|
4058
|
+
const oldVoiceState = this.cache.voiceStates.get(key);
|
|
4059
|
+
const voiceState = buildVoiceState(d, this.cache);
|
|
4060
|
+
if (!d.channel_id) {
|
|
4061
|
+
this.cache.voiceStates.delete(key);
|
|
4062
|
+
} else {
|
|
4063
|
+
this.cache.voiceStates.set(key, voiceState);
|
|
4064
|
+
}
|
|
2893
4065
|
this.dispatch("VOICE_STATE_UPDATE", {
|
|
2894
4066
|
type: "VOICE_STATE_UPDATE",
|
|
2895
|
-
voiceState
|
|
4067
|
+
voiceState,
|
|
4068
|
+
...oldVoiceState ? { oldVoiceState } : {}
|
|
2896
4069
|
});
|
|
2897
4070
|
break;
|
|
2898
4071
|
}
|
|
@@ -3254,6 +4427,301 @@ var Chameleon = class {
|
|
|
3254
4427
|
};
|
|
3255
4428
|
}
|
|
3256
4429
|
};
|
|
4430
|
+
|
|
4431
|
+
// src/utils/bitfield.ts
|
|
4432
|
+
var BitField = class _BitField {
|
|
4433
|
+
static FLAGS = {};
|
|
4434
|
+
bitfield;
|
|
4435
|
+
constructor(bits = 0n) {
|
|
4436
|
+
this.bitfield = this.constructor.resolve(bits);
|
|
4437
|
+
}
|
|
4438
|
+
has(bit) {
|
|
4439
|
+
const resolved = this.constructor.resolve(bit);
|
|
4440
|
+
return (this.bitfield & resolved) === resolved;
|
|
4441
|
+
}
|
|
4442
|
+
any(bit) {
|
|
4443
|
+
const resolved = this.constructor.resolve(bit);
|
|
4444
|
+
return (this.bitfield & resolved) !== 0n;
|
|
4445
|
+
}
|
|
4446
|
+
add(...bits) {
|
|
4447
|
+
let total = 0n;
|
|
4448
|
+
for (const bit of bits) {
|
|
4449
|
+
total |= this.constructor.resolve(bit);
|
|
4450
|
+
}
|
|
4451
|
+
this.bitfield |= total;
|
|
4452
|
+
return this;
|
|
4453
|
+
}
|
|
4454
|
+
remove(...bits) {
|
|
4455
|
+
let total = 0n;
|
|
4456
|
+
for (const bit of bits) {
|
|
4457
|
+
total |= this.constructor.resolve(bit);
|
|
4458
|
+
}
|
|
4459
|
+
this.bitfield &= ~total;
|
|
4460
|
+
return this;
|
|
4461
|
+
}
|
|
4462
|
+
toArray() {
|
|
4463
|
+
const flags = this.constructor.FLAGS;
|
|
4464
|
+
return Object.keys(flags).filter((flag) => this.has(flags[flag]));
|
|
4465
|
+
}
|
|
4466
|
+
serialize() {
|
|
4467
|
+
const flags = this.constructor.FLAGS;
|
|
4468
|
+
const result = {};
|
|
4469
|
+
for (const [flag, value] of Object.entries(flags)) {
|
|
4470
|
+
result[flag] = this.has(value);
|
|
4471
|
+
}
|
|
4472
|
+
return result;
|
|
4473
|
+
}
|
|
4474
|
+
equals(other) {
|
|
4475
|
+
return this.bitfield === this.constructor.resolve(other);
|
|
4476
|
+
}
|
|
4477
|
+
freeze() {
|
|
4478
|
+
return Object.freeze(this);
|
|
4479
|
+
}
|
|
4480
|
+
toString() {
|
|
4481
|
+
return this.bitfield.toString();
|
|
4482
|
+
}
|
|
4483
|
+
toJSON() {
|
|
4484
|
+
return this.toString();
|
|
4485
|
+
}
|
|
4486
|
+
static resolve(bit) {
|
|
4487
|
+
if (typeof bit === "bigint") return bit;
|
|
4488
|
+
if (typeof bit === "number") return BigInt(bit);
|
|
4489
|
+
if (bit instanceof _BitField) return bit.bitfield;
|
|
4490
|
+
if (typeof bit === "string") {
|
|
4491
|
+
const flag = this.FLAGS[bit];
|
|
4492
|
+
if (flag !== void 0) return flag;
|
|
4493
|
+
const parsed = BigInt(bit);
|
|
4494
|
+
return parsed;
|
|
4495
|
+
}
|
|
4496
|
+
if (Array.isArray(bit)) {
|
|
4497
|
+
return bit.reduce((acc, b) => acc | this.resolve(b), 0n);
|
|
4498
|
+
}
|
|
4499
|
+
throw new TypeError(`Cannot resolve BitField from: ${bit}`);
|
|
4500
|
+
}
|
|
4501
|
+
};
|
|
4502
|
+
|
|
4503
|
+
// src/types/permissions.ts
|
|
4504
|
+
var PermissionsBitField = class _PermissionsBitField extends BitField {
|
|
4505
|
+
static FLAGS = { ...DISCORD_PERMISSIONS };
|
|
4506
|
+
static ALL = Object.values(DISCORD_PERMISSIONS).reduce((a, b) => a | b, 0n);
|
|
4507
|
+
get isAdmin() {
|
|
4508
|
+
return this.has("ADMINISTRATOR");
|
|
4509
|
+
}
|
|
4510
|
+
static from(bits) {
|
|
4511
|
+
return new _PermissionsBitField(bits);
|
|
4512
|
+
}
|
|
4513
|
+
};
|
|
4514
|
+
var UserFlagsBitField = class extends BitField {
|
|
4515
|
+
static FLAGS = {
|
|
4516
|
+
STAFF: 1n << 0n,
|
|
4517
|
+
PARTNER: 1n << 1n,
|
|
4518
|
+
HYPESQUAD: 1n << 2n,
|
|
4519
|
+
BUG_HUNTER_LEVEL_1: 1n << 3n,
|
|
4520
|
+
HYPESQUAD_ONLINE_HOUSE_1: 1n << 6n,
|
|
4521
|
+
HYPESQUAD_ONLINE_HOUSE_2: 1n << 7n,
|
|
4522
|
+
HYPESQUAD_ONLINE_HOUSE_3: 1n << 8n,
|
|
4523
|
+
PREMIUM_EARLY_SUPPORTER: 1n << 9n,
|
|
4524
|
+
TEAM_PSEUDO_USER: 1n << 10n,
|
|
4525
|
+
BUG_HUNTER_LEVEL_2: 1n << 14n,
|
|
4526
|
+
VERIFIED_BOT: 1n << 16n,
|
|
4527
|
+
VERIFIED_DEVELOPER: 1n << 17n,
|
|
4528
|
+
CERTIFIED_MODERATOR: 1n << 18n,
|
|
4529
|
+
BOT_HTTP_INTERACTIONS: 1n << 19n,
|
|
4530
|
+
ACTIVE_DEVELOPER: 1n << 22n
|
|
4531
|
+
};
|
|
4532
|
+
};
|
|
4533
|
+
var IntentsBitField = class extends BitField {
|
|
4534
|
+
static FLAGS = {
|
|
4535
|
+
Guilds: 1n << 0n,
|
|
4536
|
+
GuildMembers: 1n << 1n,
|
|
4537
|
+
GuildModeration: 1n << 2n,
|
|
4538
|
+
GuildEmojisAndStickers: 1n << 3n,
|
|
4539
|
+
GuildIntegrations: 1n << 4n,
|
|
4540
|
+
GuildWebhooks: 1n << 5n,
|
|
4541
|
+
GuildInvites: 1n << 6n,
|
|
4542
|
+
GuildVoiceStates: 1n << 7n,
|
|
4543
|
+
GuildPresences: 1n << 8n,
|
|
4544
|
+
GuildMessages: 1n << 9n,
|
|
4545
|
+
GuildMessageReactions: 1n << 10n,
|
|
4546
|
+
GuildMessageTyping: 1n << 11n,
|
|
4547
|
+
DirectMessages: 1n << 12n,
|
|
4548
|
+
DirectMessageReactions: 1n << 13n,
|
|
4549
|
+
DirectMessageTyping: 1n << 14n,
|
|
4550
|
+
MessageContent: 1n << 15n,
|
|
4551
|
+
GuildScheduledEvents: 1n << 16n,
|
|
4552
|
+
AutoModerationConfiguration: 1n << 20n,
|
|
4553
|
+
AutoModerationExecution: 1n << 21n,
|
|
4554
|
+
GuildMessagePolls: 1n << 24n,
|
|
4555
|
+
DirectMessagePolls: 1n << 25n
|
|
4556
|
+
};
|
|
4557
|
+
};
|
|
4558
|
+
function computeBasePermissions(member, guild) {
|
|
4559
|
+
if (member.roles === void 0) return 0n;
|
|
4560
|
+
const userId = member.user?.id;
|
|
4561
|
+
if (userId && userId === guild.ownerId) return PermissionsBitField.ALL;
|
|
4562
|
+
const everyoneRole = guild.roles.find((r) => r.id === guild.id);
|
|
4563
|
+
let permissions = everyoneRole ? BigInt(everyoneRole.permissions) : 0n;
|
|
4564
|
+
for (const roleId of member.roles) {
|
|
4565
|
+
const role = guild.roles.find((r) => r.id === roleId);
|
|
4566
|
+
if (role) permissions |= BigInt(role.permissions);
|
|
4567
|
+
}
|
|
4568
|
+
if ((permissions & DISCORD_PERMISSIONS.ADMINISTRATOR) === DISCORD_PERMISSIONS.ADMINISTRATOR) {
|
|
4569
|
+
return PermissionsBitField.ALL;
|
|
4570
|
+
}
|
|
4571
|
+
return permissions;
|
|
4572
|
+
}
|
|
4573
|
+
function computeChannelPermissions(basePermissions, overwrites, memberRoles, memberId) {
|
|
4574
|
+
if ((basePermissions & DISCORD_PERMISSIONS.ADMINISTRATOR) === DISCORD_PERMISSIONS.ADMINISTRATOR) {
|
|
4575
|
+
return PermissionsBitField.ALL;
|
|
4576
|
+
}
|
|
4577
|
+
let permissions = basePermissions;
|
|
4578
|
+
let allow = 0n;
|
|
4579
|
+
let deny = 0n;
|
|
4580
|
+
for (const overwrite of overwrites) {
|
|
4581
|
+
if (overwrite.type === 0) {
|
|
4582
|
+
if (memberRoles.includes(overwrite.id) || overwrites.indexOf(overwrite) === 0) {
|
|
4583
|
+
if (overwrites.indexOf(overwrite) === 0 && !memberRoles.includes(overwrite.id)) {
|
|
4584
|
+
permissions &= ~BigInt(overwrite.deny);
|
|
4585
|
+
permissions |= BigInt(overwrite.allow);
|
|
4586
|
+
} else {
|
|
4587
|
+
allow |= BigInt(overwrite.allow);
|
|
4588
|
+
deny |= BigInt(overwrite.deny);
|
|
4589
|
+
}
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
}
|
|
4593
|
+
permissions &= ~deny;
|
|
4594
|
+
permissions |= allow;
|
|
4595
|
+
if (memberId) {
|
|
4596
|
+
const memberOverwrite = overwrites.find((ow) => ow.type === 1 && ow.id === memberId);
|
|
4597
|
+
if (memberOverwrite) {
|
|
4598
|
+
permissions &= ~BigInt(memberOverwrite.deny);
|
|
4599
|
+
permissions |= BigInt(memberOverwrite.allow);
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
return permissions;
|
|
4603
|
+
}
|
|
4604
|
+
|
|
4605
|
+
// src/sharding/manager.ts
|
|
4606
|
+
import { EventEmitter } from "events";
|
|
4607
|
+
import { fork } from "child_process";
|
|
4608
|
+
import * as path3 from "path";
|
|
4609
|
+
var Shard = class extends EventEmitter {
|
|
4610
|
+
id;
|
|
4611
|
+
manager;
|
|
4612
|
+
process = null;
|
|
4613
|
+
ready = false;
|
|
4614
|
+
constructor(manager, id) {
|
|
4615
|
+
super();
|
|
4616
|
+
this.manager = manager;
|
|
4617
|
+
this.id = id;
|
|
4618
|
+
}
|
|
4619
|
+
spawn() {
|
|
4620
|
+
return new Promise((resolve4, reject) => {
|
|
4621
|
+
const env = {
|
|
4622
|
+
...process.env,
|
|
4623
|
+
SHARD_ID: this.id.toString(),
|
|
4624
|
+
SHARD_COUNT: this.manager.totalShards.toString(),
|
|
4625
|
+
DISCORD_TOKEN: this.manager.token
|
|
4626
|
+
};
|
|
4627
|
+
this.process = fork(this.manager.file, [], {
|
|
4628
|
+
env
|
|
4629
|
+
});
|
|
4630
|
+
this.process.on("message", (message) => {
|
|
4631
|
+
this.emit("message", message);
|
|
4632
|
+
this.manager.emit("message", this, message);
|
|
4633
|
+
if (message?.type === "ready") {
|
|
4634
|
+
this.ready = true;
|
|
4635
|
+
this.emit("ready");
|
|
4636
|
+
resolve4(this.process);
|
|
4637
|
+
}
|
|
4638
|
+
});
|
|
4639
|
+
this.process.on("exit", (code, signal) => {
|
|
4640
|
+
this.emit("death", this.process);
|
|
4641
|
+
this.manager.emit("shardDeath", this);
|
|
4642
|
+
this.process = null;
|
|
4643
|
+
this.ready = false;
|
|
4644
|
+
if (this.manager.respawn) {
|
|
4645
|
+
console.warn(`[C-Shard] Shard ${this.id} exited with code ${code} (signal: ${signal})`);
|
|
4646
|
+
setTimeout(() => this.spawn().catch(console.error), 5e3);
|
|
4647
|
+
}
|
|
4648
|
+
});
|
|
4649
|
+
this.process.on("error", (err) => {
|
|
4650
|
+
reject(err);
|
|
4651
|
+
});
|
|
4652
|
+
setTimeout(() => {
|
|
4653
|
+
if (!this.ready) {
|
|
4654
|
+
this.ready = true;
|
|
4655
|
+
this.emit("ready");
|
|
4656
|
+
resolve4(this.process);
|
|
4657
|
+
}
|
|
4658
|
+
}, 3e4);
|
|
4659
|
+
});
|
|
4660
|
+
}
|
|
4661
|
+
send(message) {
|
|
4662
|
+
return new Promise((resolve4, reject) => {
|
|
4663
|
+
if (!this.process) return reject(new Error("Shard is not running"));
|
|
4664
|
+
this.process.send(message, (err) => {
|
|
4665
|
+
if (err) reject(err);
|
|
4666
|
+
else resolve4();
|
|
4667
|
+
});
|
|
4668
|
+
});
|
|
4669
|
+
}
|
|
4670
|
+
kill() {
|
|
4671
|
+
if (this.process) {
|
|
4672
|
+
this.process.removeAllListeners();
|
|
4673
|
+
this.process.kill();
|
|
4674
|
+
this.process = null;
|
|
4675
|
+
this.ready = false;
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
};
|
|
4679
|
+
var CShard = class extends EventEmitter {
|
|
4680
|
+
file;
|
|
4681
|
+
totalShards;
|
|
4682
|
+
token;
|
|
4683
|
+
shards = /* @__PURE__ */ new Map();
|
|
4684
|
+
respawn;
|
|
4685
|
+
constructor(file, options) {
|
|
4686
|
+
super();
|
|
4687
|
+
this.file = path3.resolve(file);
|
|
4688
|
+
this.token = options.token;
|
|
4689
|
+
this.totalShards = typeof options.totalShards === "number" ? options.totalShards : 1;
|
|
4690
|
+
this.respawn = options.respawn ?? true;
|
|
4691
|
+
if (options.totalShards === "auto") {
|
|
4692
|
+
this.totalShards = -1;
|
|
4693
|
+
}
|
|
4694
|
+
}
|
|
4695
|
+
async fetchRecommendedShards() {
|
|
4696
|
+
const rest = new ChameleonREST({ token: this.token });
|
|
4697
|
+
const result = await rest.get("/gateway/bot");
|
|
4698
|
+
if (result.ok && result.data && typeof result.data.shards === "number") {
|
|
4699
|
+
return result.data.shards;
|
|
4700
|
+
}
|
|
4701
|
+
console.warn("[Chameleon Sharding] Failed to fetch recommended shards from Discord API. Falling back to 1.");
|
|
4702
|
+
return 1;
|
|
4703
|
+
}
|
|
4704
|
+
async spawn() {
|
|
4705
|
+
if (this.totalShards === -1) {
|
|
4706
|
+
this.totalShards = await this.fetchRecommendedShards();
|
|
4707
|
+
}
|
|
4708
|
+
for (let i = 0; i < this.totalShards; i++) {
|
|
4709
|
+
const shard = new Shard(this, i);
|
|
4710
|
+
this.shards.set(i, shard);
|
|
4711
|
+
this.emit("shardCreate", shard);
|
|
4712
|
+
await shard.spawn();
|
|
4713
|
+
await new Promise((r) => setTimeout(r, 5e3));
|
|
4714
|
+
}
|
|
4715
|
+
return this.shards;
|
|
4716
|
+
}
|
|
4717
|
+
async broadcast(message) {
|
|
4718
|
+
const promises = [];
|
|
4719
|
+
for (const shard of this.shards.values()) {
|
|
4720
|
+
promises.push(shard.send(message));
|
|
4721
|
+
}
|
|
4722
|
+
return Promise.all(promises);
|
|
4723
|
+
}
|
|
4724
|
+
};
|
|
3257
4725
|
export {
|
|
3258
4726
|
AUDIT_LOG_EVENT_TYPES,
|
|
3259
4727
|
ActionRow,
|
|
@@ -3265,17 +4733,22 @@ export {
|
|
|
3265
4733
|
ApplicationEventWebhookStatus,
|
|
3266
4734
|
ApplicationFlag,
|
|
3267
4735
|
ApplicationIntegrationType,
|
|
4736
|
+
ApplicationManager,
|
|
3268
4737
|
ApplicationRoleConnectionMetadataType,
|
|
4738
|
+
AttachmentBuilder,
|
|
3269
4739
|
AttachmentFlag,
|
|
3270
4740
|
AutoModerationActionType,
|
|
3271
4741
|
AutoModerationEventType,
|
|
3272
4742
|
AutoModerationKeywordPresetType,
|
|
4743
|
+
AutoModerationManager,
|
|
3273
4744
|
AutoModerationTriggerType,
|
|
3274
4745
|
BaseInteractionContext,
|
|
3275
4746
|
BaseManager,
|
|
4747
|
+
BitField,
|
|
3276
4748
|
ButtonBuilder,
|
|
3277
4749
|
ButtonStyle,
|
|
3278
4750
|
CHAMELEON_SELF_MAP,
|
|
4751
|
+
CShard,
|
|
3279
4752
|
Chameleon,
|
|
3280
4753
|
ChameleonGateway,
|
|
3281
4754
|
ChameleonREST,
|
|
@@ -3283,6 +4756,7 @@ export {
|
|
|
3283
4756
|
ChannelManager,
|
|
3284
4757
|
ChannelType,
|
|
3285
4758
|
Client,
|
|
4759
|
+
Collection,
|
|
3286
4760
|
CollectorManager,
|
|
3287
4761
|
Colors,
|
|
3288
4762
|
CommandContext,
|
|
@@ -3295,6 +4769,7 @@ export {
|
|
|
3295
4769
|
DefaultMessageNotificationLevel,
|
|
3296
4770
|
EmbedBuilder,
|
|
3297
4771
|
EmbedType,
|
|
4772
|
+
EntitlementManager,
|
|
3298
4773
|
EntitlementType,
|
|
3299
4774
|
ExplicitContentFilterLevel,
|
|
3300
4775
|
ForumLayoutType,
|
|
@@ -3308,6 +4783,8 @@ export {
|
|
|
3308
4783
|
IntegrationExpireBehavior,
|
|
3309
4784
|
IntentBits,
|
|
3310
4785
|
Intents,
|
|
4786
|
+
IntentsBitField,
|
|
4787
|
+
InviteManager,
|
|
3311
4788
|
InviteTargetType,
|
|
3312
4789
|
InviteType,
|
|
3313
4790
|
LobbyMemberFlag,
|
|
@@ -3319,26 +4796,34 @@ export {
|
|
|
3319
4796
|
MessageReferenceType,
|
|
3320
4797
|
MessageType,
|
|
3321
4798
|
ModalBuilder,
|
|
4799
|
+
PermissionsBitField,
|
|
3322
4800
|
PremiumTier,
|
|
3323
4801
|
PremiumType,
|
|
3324
4802
|
RoleManager,
|
|
4803
|
+
ScheduledEventManager,
|
|
3325
4804
|
SelectMenuBuilder,
|
|
4805
|
+
Shard,
|
|
3326
4806
|
SkuFlag,
|
|
3327
4807
|
SkuType,
|
|
3328
4808
|
SortOrderType,
|
|
4809
|
+
SoundboardManager,
|
|
4810
|
+
StageInstanceManager,
|
|
3329
4811
|
StagePrivacyLevel,
|
|
3330
4812
|
StickerFormatType,
|
|
3331
4813
|
StickerType,
|
|
3332
4814
|
SubscriptionStatus,
|
|
3333
4815
|
SystemChannelFlag,
|
|
4816
|
+
TemplateManager,
|
|
3334
4817
|
TextInputBuilder,
|
|
3335
4818
|
Tongue,
|
|
3336
4819
|
TongueStore,
|
|
3337
4820
|
UserFlag,
|
|
4821
|
+
UserFlagsBitField,
|
|
3338
4822
|
UserManager,
|
|
3339
4823
|
VerificationLevel,
|
|
3340
4824
|
VideoQualityMode,
|
|
3341
4825
|
VisibilityType,
|
|
4826
|
+
WebhookManager,
|
|
3342
4827
|
WebhookType,
|
|
3343
4828
|
buildAutoModRule,
|
|
3344
4829
|
buildChannel,
|
|
@@ -3347,6 +4832,7 @@ export {
|
|
|
3347
4832
|
buildGuild,
|
|
3348
4833
|
buildIntegration,
|
|
3349
4834
|
buildInteraction,
|
|
4835
|
+
buildInvite,
|
|
3350
4836
|
buildMember,
|
|
3351
4837
|
buildMessage,
|
|
3352
4838
|
buildRole,
|
|
@@ -3356,7 +4842,10 @@ export {
|
|
|
3356
4842
|
buildStickerItem,
|
|
3357
4843
|
buildUser,
|
|
3358
4844
|
buildVoiceState,
|
|
4845
|
+
buildWebhook,
|
|
3359
4846
|
combinePermissions,
|
|
4847
|
+
computeBasePermissions,
|
|
4848
|
+
computeChannelPermissions,
|
|
3360
4849
|
defineButton,
|
|
3361
4850
|
defineChannelSelect,
|
|
3362
4851
|
defineCommand,
|