dfx 0.9.8 → 0.9.9

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.
Files changed (124) hide show
  1. package/DiscordConfig/index.d.ts +39 -0
  2. package/DiscordConfig/index.js +29 -0
  3. package/DiscordConfig/index.js.map +1 -0
  4. package/DiscordGateway/DiscordWS/index.d.ts +23 -0
  5. package/DiscordGateway/DiscordWS/index.js +26 -0
  6. package/DiscordGateway/DiscordWS/index.js.map +1 -0
  7. package/DiscordGateway/Shard/heartbeats.d.ts +3 -0
  8. package/DiscordGateway/Shard/heartbeats.js +24 -0
  9. package/DiscordGateway/Shard/heartbeats.js.map +1 -0
  10. package/DiscordGateway/Shard/identify.d.ts +12 -0
  11. package/DiscordGateway/Shard/identify.js +30 -0
  12. package/DiscordGateway/Shard/identify.js.map +1 -0
  13. package/DiscordGateway/Shard/index.d.ts +9 -0
  14. package/DiscordGateway/Shard/index.js +52 -0
  15. package/DiscordGateway/Shard/index.js.map +1 -0
  16. package/DiscordGateway/Shard/invalidSession.d.ts +3 -0
  17. package/DiscordGateway/Shard/invalidSession.js +10 -0
  18. package/DiscordGateway/Shard/invalidSession.js.map +1 -0
  19. package/DiscordGateway/Shard/sendEvents.d.ts +7 -0
  20. package/DiscordGateway/Shard/sendEvents.js +26 -0
  21. package/DiscordGateway/Shard/sendEvents.js.map +1 -0
  22. package/DiscordGateway/Shard/utils.d.ts +3 -0
  23. package/DiscordGateway/Shard/utils.js +9 -0
  24. package/DiscordGateway/Shard/utils.js.map +1 -0
  25. package/DiscordGateway/ShardStore/index.d.ts +12 -0
  26. package/DiscordGateway/ShardStore/index.js +22 -0
  27. package/DiscordGateway/ShardStore/index.js.map +1 -0
  28. package/DiscordGateway/Sharder/index.d.ts +9 -0
  29. package/DiscordGateway/Sharder/index.js +61 -0
  30. package/DiscordGateway/Sharder/index.js.map +1 -0
  31. package/DiscordGateway/WS/index.d.ts +27 -0
  32. package/DiscordGateway/WS/index.js +82 -0
  33. package/DiscordGateway/WS/index.js.map +1 -0
  34. package/DiscordGateway/index.d.ts +20 -0
  35. package/DiscordGateway/index.js +27 -0
  36. package/DiscordGateway/index.js.map +1 -0
  37. package/DiscordREST/index.d.ts +12 -0
  38. package/DiscordREST/index.js +85 -0
  39. package/DiscordREST/index.js.map +1 -0
  40. package/DiscordREST/types.d.ts +9 -0
  41. package/DiscordREST/types.js +2 -0
  42. package/DiscordREST/types.js.map +1 -0
  43. package/DiscordREST/utils.d.ts +10 -0
  44. package/DiscordREST/utils.js +22 -0
  45. package/DiscordREST/utils.js.map +1 -0
  46. package/Helpers/flags.d.ts +27 -0
  47. package/Helpers/flags.js +36 -0
  48. package/Helpers/flags.js.map +1 -0
  49. package/Helpers/intents.d.ts +24 -0
  50. package/Helpers/intents.js +28 -0
  51. package/Helpers/intents.js.map +1 -0
  52. package/Helpers/interactions.d.ts +73 -0
  53. package/Helpers/interactions.js +93 -0
  54. package/Helpers/interactions.js.map +1 -0
  55. package/Helpers/members.d.ts +9 -0
  56. package/Helpers/members.js +10 -0
  57. package/Helpers/members.js.map +1 -0
  58. package/Helpers/permissions.d.ts +34 -0
  59. package/Helpers/permissions.js +69 -0
  60. package/Helpers/permissions.js.map +1 -0
  61. package/Helpers/ui.d.ts +47 -0
  62. package/Helpers/ui.js +67 -0
  63. package/Helpers/ui.js.map +1 -0
  64. package/Http/index.d.ts +30 -0
  65. package/Http/index.js +53 -0
  66. package/Http/index.js.map +1 -0
  67. package/Interactions/context.d.ts +36 -0
  68. package/Interactions/context.js +34 -0
  69. package/Interactions/context.js.map +1 -0
  70. package/Interactions/definitions.d.ts +60 -0
  71. package/Interactions/definitions.js +52 -0
  72. package/Interactions/definitions.js.map +1 -0
  73. package/Interactions/gateway.d.ts +6 -0
  74. package/Interactions/gateway.js +21 -0
  75. package/Interactions/gateway.js.map +1 -0
  76. package/Interactions/handlers.d.ts +8 -0
  77. package/Interactions/handlers.js +49 -0
  78. package/Interactions/handlers.js.map +1 -0
  79. package/Interactions/index.d.ts +17 -0
  80. package/Interactions/index.js +39 -0
  81. package/Interactions/index.js.map +1 -0
  82. package/Interactions/utils.d.ts +10 -0
  83. package/Interactions/utils.js +61 -0
  84. package/Interactions/utils.js.map +1 -0
  85. package/Interactions/webhook.d.ts +32 -0
  86. package/Interactions/webhook.js +42 -0
  87. package/Interactions/webhook.js.map +1 -0
  88. package/Log/index.d.ts +12 -0
  89. package/Log/index.js +19 -0
  90. package/Log/index.js.map +1 -0
  91. package/RateLimitStore/index.d.ts +24 -0
  92. package/RateLimitStore/index.js +24 -0
  93. package/RateLimitStore/index.js.map +1 -0
  94. package/RateLimitStore/memory.d.ts +2 -0
  95. package/RateLimitStore/memory.js +31 -0
  96. package/RateLimitStore/memory.js.map +1 -0
  97. package/RateLimitStore/utils.d.ts +2 -0
  98. package/RateLimitStore/utils.js +18 -0
  99. package/RateLimitStore/utils.js.map +1 -0
  100. package/common-gateway.d.ts +5 -0
  101. package/common-gateway.js +6 -0
  102. package/common-gateway.js.map +1 -0
  103. package/common.d.ts +28 -0
  104. package/common.js +16 -0
  105. package/common.js.map +1 -0
  106. package/global.d.ts +17 -0
  107. package/global.js +2 -0
  108. package/global.js.map +1 -0
  109. package/index.d.ts +21 -0
  110. package/index.js +29 -0
  111. package/index.js.map +1 -0
  112. package/package.json +2 -6
  113. package/types.d.ts +4228 -0
  114. package/types.js +1796 -0
  115. package/types.js.map +1 -0
  116. package/utils/effect.d.ts +2 -0
  117. package/utils/effect.js +2 -0
  118. package/utils/effect.js.map +1 -0
  119. package/utils/tsplus.d.ts +13 -0
  120. package/utils/tsplus.js +2 -0
  121. package/utils/tsplus.js.map +1 -0
  122. package/webhooks.d.ts +15 -0
  123. package/webhooks.js +23 -0
  124. package/webhooks.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/WS/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,SAAS,MAAM,eA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AC,CA4BrC,CAAA;AAEJ,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAgB,EAAE,OAAiC,EAAE,EAAE;IAExE,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,2BAAwC,CAAA;+BAC3D,GAAG;QACT,MAAM,OAAO,GAAG,+BAAsB,gBAAA,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;QAEnD,MAAM,MAAM,GAAG,uBAKb,2BACE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,qBAAqB,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAC3D,uDANK,EAAE,wBACF,UAAU,IACT,sBAAe,UAAU,EAAzB,IAAI,CAAC,EAAE,CAAC,CAAkB,EADZ,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,GADnC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,GAOlC,CAAA;QAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;OAbT,wBAAe,gBAAA,GAAG,CAAC,GAAG,CAAC;IAcrC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { EffectSource, Discord, Effect } from "dfx/common";
2
+ import { Success } from "dfx/utils/effect";
3
+ export declare const make: import("../common.js").Effect<import("./ShardStore/index.js").ShardStore | import("../index.js").DiscordREST | import("../DiscordConfig/index.js").DiscordConfig | import("../Log/index.js").Log | import("../RateLimitStore/index.js").RateLimiter | import("./DiscordWS/index.js").DiscordWSCodec, never, {
4
+ shards: import("callbag-effect-ts/Source").EffectSource<never, never, {
5
+ run: import("../common.js").Effect<never, never, readonly [readonly [readonly [readonly [void, void], void], void], void]>;
6
+ raw: import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").GatewayPayload<any>>;
7
+ dispatch: import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").GatewayPayload<import("../types.js").ReceiveEvent>>;
8
+ send: (p: import("../types.js").GatewayPayload<any>) => void;
9
+ reconnect: () => void;
10
+ }>;
11
+ raw: import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").GatewayPayload<any>>;
12
+ dispatch: import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").GatewayPayload<import("../types.js").ReceiveEvent>>;
13
+ fromDispatch: <K extends keyof import("../types.js").ReceiveEvents>(event: K) => import("callbag-effect-ts/Source").EffectSource<never, never, import("../types.js").ReceiveEvents[K]>;
14
+ handleDispatch: <K_1 extends keyof import("../types.js").ReceiveEvents, R1, E1, A>(event: K_1, handle: (event: import("../types.js").ReceiveEvents[K_1]) => import("../common.js").Effect<R1, E1, A>) => import("../common.js").Effect<R1, E1, void>;
15
+ }>;
16
+ export interface DiscordGateway extends Success<typeof make> {
17
+ }
18
+ export declare const DiscordGateway: import("../common.js").Tag<DiscordGateway>;
19
+ export declare const LiveDiscordGateway: import("../common.js").Layer<import("./ShardStore/index.js").ShardStore | import("../index.js").DiscordREST | import("../DiscordConfig/index.js").DiscordConfig | import("../Log/index.js").Log | import("../RateLimitStore/index.js").RateLimiter | import("./DiscordWS/index.js").DiscordWSCodec, never, DiscordGateway>;
20
+ export declare const handleDispatch: <K extends keyof import("../types.js").ReceiveEvents, R1, E1, A>(event: K, handle: (event: import("../types.js").ReceiveEvents[K]) => import("../common.js").Effect<R1, E1, A>) => import("../common.js").Effect<DiscordGateway | R1, E1, void>;
@@ -0,0 +1,27 @@
1
+ import * as tsplus_module_1 from "callbag-effect-ts/Source/filter";
2
+ import * as tsplus_module_2 from "callbag-effect-ts/Source/map";
3
+ import * as tsplus_module_3 from "callbag-effect-ts/Source/fromEffect";
4
+ import * as tsplus_module_4 from "callbag-effect-ts/Source/chainPar";
5
+ import * as tsplus_module_5 from "callbag-effect-ts/Source/run";
6
+ import * as tsplus_module_6 from "callbag-effect-ts/Source/share";
7
+ import * as tsplus_module_7 from "@effect/io/Effect";
8
+ import * as tsplus_module_8 from "dfx/common";
9
+ import * as tsplus_module_9 from "@effect/io/Layer";
10
+ import { spawn } from "./Sharder/index.js";
11
+ const fromDispatchFactory = (source) => (event) => tsplus_module_2.map((p) => p.d)(tsplus_module_1.filter((p) => p.t === event)(source));
12
+ const handleDispatchFactory = (source) => (event, handle) => tsplus_module_5.runDrain(tsplus_module_4.chainPar((a) => tsplus_module_3.fromEffect(handle(a.d)))(tsplus_module_1.filter((p) => p.t === event)(source)));
13
+ export const make = tsplus_module_7.flatMap(shards => tsplus_module_7.flatMap(raw => tsplus_module_7.map(dispatch => {
14
+ const fromDispatch = fromDispatchFactory(dispatch);
15
+ const handleDispatch = handleDispatchFactory(dispatch);
16
+ return {
17
+ shards,
18
+ raw,
19
+ dispatch,
20
+ fromDispatch,
21
+ handleDispatch,
22
+ };
23
+ })(tsplus_module_6.share(tsplus_module_4.chainPar((s) => s.dispatch)(shards))))(tsplus_module_6.share(tsplus_module_4.chainPar((s) => s.raw)(shards))))(tsplus_module_6.share(spawn));
24
+ export const DiscordGateway = tsplus_module_8.Tag();
25
+ export const LiveDiscordGateway = tsplus_module_9.fromEffect(DiscordGateway)(make);
26
+ export const handleDispatch = (event, handle) => tsplus_module_7.serviceWithEffect(DiscordGateway)((a) => a.handleDispatch(event, handle));
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/DiscordGateway/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,mBAAmB,GACvB,CACE,MAAwE,EACxE,EAAE,CACJ,CACE,KAAQ,EACsC,EAAE,CAChD,oBAAwC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAS,EAA1D,uBAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,EAAlC,MAAM,CAA6B,CAAwB,CAAA;AAE/D,MAAM,qBAAqB,GACzB,CACE,MAAwE,EACxE,EAAE,CACJ,CACE,KAAQ,EACR,MAA8D,EAChC,EAAE,0BAChC,yBAEY,CAAC,CAAC,EAAE,EAAE,CAAC,2BAAwB,MAAM,CAAC,CAAC,CAAC,CAAQ,CAAC,CAAC,EAF9D,uBACU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,EAD9B,MAAM,CACyB,CACgC,CAAS,CAAA;AAE5E,MAAM,CAAC,MAAM,IAAI,2BACT,MAAM,4BACN,GAAG,wBACH,QAAQ;IACd,MAAM,YAAY,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IAClD,MAAM,cAAc,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAA;IAEtD,OAAO;QACL,MAAM;QACN,GAAG;QACH,QAAQ;QACR,YAAY;QACZ,cAAc;KACf,CAAA;yBAVkB,yBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAjC,MAAM,CAA4B,0BADvC,yBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAA5B,MAAM,CAAuB,0BAD1B,KAAK,EAatB,CAAA;AAGF,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAA,GAAG,EAAkB,CAAA;AACnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,2BAAiB,cAAc,CAAC,CAAC,IAAI,CAAC,CAAA;AAExE,MAAM,CAAC,MAAM,cAAc,GAAG,CAM5B,KAAQ,EACR,MAA8D,EAC9D,EAAE,CACF,kCAAyB,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAC7C,CAAC,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAChC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { Effect, Http } from "dfx/common";
2
+ import { Success } from "dfx/utils/effect";
3
+ import { ResponseWithData } from "./types.js";
4
+ declare const make: import("../common.js").Effect<import("../DiscordConfig/index.js").DiscordConfig | import("../Log/index.js").Log | import("dfx/RateLimitStore/index").RateLimitStore | import("dfx/RateLimitStore/index").RateLimiter, never, {
5
+ request: <A = unknown>(path: string, init?: RequestInit) => import("../common.js").Effect<never, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError, ResponseWithData<A>>;
6
+ }>;
7
+ export interface DiscordREST extends Success<typeof make> {
8
+ }
9
+ export declare const DiscordREST: import("../common.js").Tag<DiscordREST>;
10
+ export declare const LiveDiscordREST: import("../common.js").Layer<import("../DiscordConfig/index.js").DiscordConfig | import("../Log/index.js").Log | import("dfx/RateLimitStore/index").RateLimitStore | import("dfx/RateLimitStore/index").RateLimiter, never, DiscordREST>;
11
+ export declare const rest: import("../types.js").Endpoints<RequestInit>;
12
+ export {};
@@ -0,0 +1,85 @@
1
+ import * as tsplus_module_1 from "@effect/io/Effect";
2
+ import * as tsplus_module_2 from "dfx/common";
3
+ import * as tsplus_module_3 from "@fp-ts/data/Equal";
4
+ import * as tsplus_module_4 from "@fp-ts/data/Option";
5
+ import * as tsplus_module_5 from "@effect/io/Layer";
6
+ import { millis } from "@fp-ts/data/Duration";
7
+ import { rateLimitFromHeaders, routeFromConfig } from "./utils.js";
8
+ import Pkg from "../../package.json" assert { type: "json" };
9
+ const make = tsplus_module_1.flatMap(({ token, rest }) => tsplus_module_1.flatMap(log => tsplus_module_1.flatMap(store => tsplus_module_1.map(({ maybeWait }) => {
10
+ const globalRateLimit = maybeWait("rest.global", rest.globalRateLimit.window, rest.globalRateLimit.limit);
11
+ const requestRateLimit = (path, init) => (() => {
12
+ const route = routeFromConfig(path, init);
13
+ return tsplus_module_1.flatMap(maybeBucket => {
14
+ const bucket = tsplus_module_4.getOrElse(() => ({
15
+ key: `?.${tsplus_module_3.hash(route)}`,
16
+ resetAfter: 5000,
17
+ limit: 1,
18
+ }))(maybeBucket);
19
+ const resetAfter = millis(bucket.resetAfter);
20
+ return tsplus_module_1.map(() => void 0)(maybeWait(`rest.bucket.${bucket.key}`, resetAfter, bucket.limit));
21
+ })(store.getBucketForRoute(route));
22
+ })();
23
+ const updateBuckets = (path, init, response) => tsplus_module_1.ignore((() => {
24
+ const route = routeFromConfig(path, init);
25
+ return tsplus_module_1.flatMap(({ bucket, retryAfter, limit, remaining }) => {
26
+ const effectsToRun = [store.putBucketRoute(route, bucket)];
27
+ return tsplus_module_1.flatMap(hasBucket => {
28
+ if (!hasBucket || limit - 1 === remaining) {
29
+ effectsToRun.push(store.putBucket({
30
+ key: bucket,
31
+ resetAfter: retryAfter.millis,
32
+ limit: !hasBucket && remaining > 0 ? remaining : limit,
33
+ }));
34
+ }
35
+ return tsplus_module_1.map(() => void 0)(tsplus_module_1.collectAllParDiscard(effectsToRun));
36
+ })(store.hasBucket(bucket));
37
+ })(tsplus_module_1.fromOption(rateLimitFromHeaders(response.headers)));
38
+ })());
39
+ const request = (path, init = {}) => tsplus_module_1.tap(({ response }) => updateBuckets(path, init, response))(tsplus_module_1.catchTag("StatusCodeError", (e) => e.code === 429
40
+ ? tsplus_module_1.flatMap(() => tsplus_module_1.flatMap(() => request(path, init))(updateBuckets(path, init, e.response)))(log.debug("DiscordREST", "429", path)) : tsplus_module_1.fail(e))(tsplus_module_1.flatMap(() => tsplus_module_2.Http.requestWithJson(`${rest.baseUrl}${path}`, {
41
+ ...init,
42
+ headers: {
43
+ ...(init?.headers ?? {}),
44
+ Authorization: `Bot ${token}`,
45
+ "User-Agent": `DiscordBot (https://github.com/tim-smart/dfx, ${Pkg.version})`,
46
+ },
47
+ }))(tsplus_module_1.tap(() => globalRateLimit)(requestRateLimit(path, init)))));
48
+ return { request };
49
+ })(tsplus_module_1.service(tsplus_module_2.RateLimitStore.RateLimiter)))(tsplus_module_1.service(tsplus_module_2.RateLimitStore.RateLimitStore)))(tsplus_module_1.service(tsplus_module_2.Log.Log)))(tsplus_module_1.service(tsplus_module_2.Config.DiscordConfig));
50
+ export const DiscordREST = tsplus_module_2.Tag();
51
+ export const LiveDiscordREST = tsplus_module_5.fromEffect(DiscordREST)(make);
52
+ export const rest = tsplus_module_2.Discord.createRoutes(({ method, url, params, options = {} }) => tsplus_module_1.serviceWithEffect(DiscordREST)(({ request }) => {
53
+ const hasBody = method !== "GET" && method !== "DELETE";
54
+ let hasFormData = typeof options?.body?.append === "function";
55
+ let body = undefined;
56
+ const headers = {};
57
+ if (hasBody && !hasFormData) {
58
+ headers["content-type"] = "application/json";
59
+ }
60
+ const qs = new URLSearchParams();
61
+ if (!hasBody) {
62
+ Object.entries((params ?? {})).forEach(([key, value]) => {
63
+ qs.append(key, value);
64
+ });
65
+ }
66
+ else if (hasFormData) {
67
+ body = options.body;
68
+ if (params) {
69
+ ;
70
+ body.append("payload_json", JSON.stringify(params));
71
+ }
72
+ }
73
+ else if (params) {
74
+ body = JSON.stringify(params);
75
+ }
76
+ else {
77
+ body = options.body;
78
+ }
79
+ return request(`${url}?${qs.toString()}`, {
80
+ method,
81
+ headers,
82
+ body,
83
+ });
84
+ }));
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/DiscordREST/index.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAG7C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,GAAG,MAAM,oBAAoB,CAAC,SAAS,IAAI,EAAE,MAAM,EAAE,CAAA;AAE5D,MAAM,IAAI,4BACF,EAAE,KAAK,EAAE,IAAI,EAAE,6BAEf,GAAG,4BACH,KAAK,yBACL,EAAE,SAAS,EAAE;IAEnB,MAAM,eAAe,GAAG,SAAS,CAC/B,aAAa,EACb,IAAI,CAAC,eAAe,CAAC,MAAM,EAC3B,IAAI,CAAC,eAAe,CAAC,KAAK,CAC3B,CAAA;IAED,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,IAAiB,EAAE,EAAE;QAEzD,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,EAAE,IAA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,GAAG,GAAG,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE;QACxC,MAAM;QACN,OAAO;QACP,IAAI;KACL,CAAC,CAAA;AACJ,CAAC,CAAC,CACL,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Effect, Http } from "dfx/common";
2
+ import { DiscordREST } from "./index.js";
3
+ export interface ResponseWithData<A> {
4
+ response: Response;
5
+ json: Effect<never, Http.JsonParseError, A>;
6
+ text: Effect<never, never, string>;
7
+ blob: Effect<never, Http.BlobError, Blob>;
8
+ }
9
+ export type RestResponse<T> = Effect<DiscordREST, Http.FetchError | Http.StatusCodeError | Http.JsonParseError, ResponseWithData<T>>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/DiscordREST/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ export declare const routeFromConfig: (path: string, init: RequestInit) => string;
2
+ export declare const numberHeader: (headers: Headers) => (key: string) => import("../common.js").Maybe<number>;
3
+ export declare const retryAfter: (headers: Headers) => import("../common.js").Maybe<import("../common.js").Duration>;
4
+ export declare const rateLimitFromHeaders: (headers: Headers) => import("../common.js").Maybe<{
5
+ readonly bucket: string;
6
+ readonly retryAfter: import("../common.js").Duration;
7
+ readonly limit: number;
8
+ readonly remaining: number;
9
+ }>;
10
+ export type RateLimitDetails = ReturnType<typeof rateLimitFromHeaders>;
@@ -0,0 +1,22 @@
1
+ import * as tsplus_module_1 from "@fp-ts/data/Option";
2
+ import * as tsplus_module_2 from "@fp-ts/data/Duration";
3
+ const majorResources = ["channels", "guilds", "webhooks"];
4
+ export const routeFromConfig = (path, init) => {
5
+ const method = (init?.method ?? "get").toLowerCase();
6
+ // Only keep major ID's
7
+ const routeURL = path
8
+ .split("?")[0]
9
+ .replace(/\/([A-Za-z]+)\/(\d{16,21}|@me)/g, (match, resource) => majorResources.includes(resource) ? match : `/${resource}`)
10
+ // Strip reactions
11
+ .replace(/\/reactions\/(.*)/, "/reactions");
12
+ return `${method}-${routeURL}`;
13
+ };
14
+ export const numberHeader = (headers) => (key) => tsplus_module_1.filter((n) => !isNaN(n))(tsplus_module_1.map(parseFloat)(tsplus_module_1.fromNullable(headers.get(key))));
15
+ export const retryAfter = (headers) => tsplus_module_1.map(tsplus_module_2.seconds)(tsplus_module_1.catchAll(() => numberHeader(headers)("retry-after"))(numberHeader(headers)("x-ratelimit-reset-after")));
16
+ export const rateLimitFromHeaders = (headers) => tsplus_module_1.struct({
17
+ bucket: tsplus_module_1.fromNullable(headers.get("x-ratelimit-bucket")),
18
+ retryAfter: retryAfter(headers),
19
+ limit: numberHeader(headers)("x-ratelimit-limit"),
20
+ remaining: numberHeader(headers)("x-ratelimit-remaining"),
21
+ });
22
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/DiscordREST/utils.ts"],"names":[],"mappings":";;AAAA,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAA;AAElE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,IAAiB,EAAE,EAAE;IACjE,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;IAEpD,uBAAuB;IACvB,MAAM,QAAQ,GAAG,IAAI;SAClB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SACb,OAAO,CAAC,iCAAiC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAC9D,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAC3D;QACD,kBAAkB;SACjB,OAAO,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAA;IAE7C,OAAO,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAChE,uBAEU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAF1B,oBACO,UAAU,EADjB,6BAAmB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAClB,CACS,CAAA;AAE7B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAgB,EAAE,EAAE,CAC7C,6CAAA,yBACY,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EADtD,YAAY,CAAC,OAAO,CAAC,CAAC,yBAAyB,CAAC,CACO,CAC/B,CAAA;AAE1B,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,OAAgB,EAAE,EAAE,CACvD,uBAAa;IACX,MAAM,EAAE,6BAAmB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAC7D,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC;IAC/B,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC;IACjD,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,uBAAuB,CAAC;CAC1D,CAAC,CAAA"}
@@ -0,0 +1,27 @@
1
+ export type Flags<T extends number | bigint> = Record<string, T>;
2
+ /**
3
+ * Returns all the flags OR'ed together.
4
+ */
5
+ export declare function all(flags: Flags<number>): number;
6
+ export declare function all(flags: Flags<bigint>): bigint;
7
+ /**
8
+ * Returns a function that converts a bitfield to a list of flag names.
9
+ */
10
+ export declare function toList<T extends Flags<number>>(flags: T): (bitfield: number) => (keyof T)[];
11
+ export declare function toList<T extends Flags<bigint>>(flags: T): (bitfield: bigint) => (keyof T)[];
12
+ /**
13
+ * Returns a function that converts a list of flags names to a bigint bitfield.
14
+ */
15
+ export declare const fromListBigint: <T extends Flags<bigint>>(flags: T) => (list: (keyof T)[]) => bigint;
16
+ /**
17
+ * Returns a function that converts a list of flags names to a bitfield.
18
+ */
19
+ export declare const fromList: <T extends Flags<number>>(flags: T) => (list: (keyof T)[]) => number;
20
+ /**
21
+ * Checks if a bigint bitfield contains and a flag value.
22
+ */
23
+ export declare const hasBigInt: (flag: bigint | string) => (bits: bigint | string) => boolean;
24
+ /**
25
+ * Checks if a bitfield contains and a flag value.
26
+ */
27
+ export declare const has: (flag: number | string) => (bits: number | string) => boolean;
@@ -0,0 +1,36 @@
1
+ export function all(flags) {
2
+ return Object.values(flags).reduce((acc, flag) => acc | flag);
3
+ }
4
+ export function toList(flags) {
5
+ const entries = Object.entries(flags);
6
+ return (val) => entries.reduce((acc, [key, flag]) => ((val & flag) === flag ? [...acc, key] : acc), []);
7
+ }
8
+ /**
9
+ * Returns a function that converts a list of flags names to a bigint bitfield.
10
+ */
11
+ export const fromListBigint = (flags) => (list) => list.reduce((acc, key) => acc | flags[key], BigInt(0));
12
+ /**
13
+ * Returns a function that converts a list of flags names to a bitfield.
14
+ */
15
+ export const fromList = (flags) => (list) => list.reduce((acc, key) => acc | flags[key], 0);
16
+ /**
17
+ * Checks if a bigint bitfield contains and a flag value.
18
+ */
19
+ export const hasBigInt = (flag) => {
20
+ const flagBigInt = BigInt(flag);
21
+ return (bits) => {
22
+ const bitsBigInt = BigInt(bits);
23
+ return (bitsBigInt & flagBigInt) === flagBigInt;
24
+ };
25
+ };
26
+ /**
27
+ * Checks if a bitfield contains and a flag value.
28
+ */
29
+ export const has = (flag) => {
30
+ const flagNumber = +flag;
31
+ return (bits) => {
32
+ const bitsNumber = +bits;
33
+ return (bitsNumber & flagNumber) === flagNumber;
34
+ };
35
+ };
36
+ //# sourceMappingURL=flags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flags.js","sourceRoot":"","sources":["../../src/Helpers/flags.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,GAAG,CAAC,KAAi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AAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;QAC/B,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC,KAAK,UAAU,CAAA;IACjD,CAAC,CAAA;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,IAAqB,EAAE,EAAE;IAC3C,MAAM,UAAU,GAAG,CAAC,IAAI,CAAA;IACxB,OAAO,CAAC,IAAqB,EAAE,EAAE;QAC/B,MAAM,UAAU,GAAG,CAAC,IAAI,CAAA;QACxB,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC,KAAK,UAAU,CAAA;IACjD,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * All the intents
3
+ */
4
+ export declare const ALL: number;
5
+ /**
6
+ * Privileged intents
7
+ */
8
+ export declare const PRIVILEGED: number;
9
+ /**
10
+ * Un-privileged intents
11
+ */
12
+ export declare const UNPRIVILEGED: number;
13
+ /**
14
+ * Function that converts a intents bitfield value to a list of intent names.
15
+ */
16
+ export declare const toList: (bitfield: number) => ("GUILDS" | "GUILD_MEMBERS" | "GUILD_BANS" | "GUILD_EMOJIS_AND_STICKERS" | "GUILD_INTEGRATIONS" | "GUILD_WEBHOOKS" | "GUILD_INVITES" | "GUILD_VOICE_STATES" | "GUILD_PRESENCES" | "GUILD_MESSAGES" | "GUILD_MESSAGE_REACTIONS" | "GUILD_MESSAGE_TYPING" | "DIRECT_MESSAGES" | "DIRECT_MESSAGE_REACTIONS" | "DIRECT_MESSAGE_TYPING" | "MESSAGE_CONTENT" | "GUILD_SCHEDULED_EVENTS" | "AUTO_MODERATION_CONFIGURATION" | "AUTO_MODERATION_EXECUTION")[];
17
+ /**
18
+ * Function that converts a list of intent names to a bitfield value.
19
+ */
20
+ export declare const fromList: (list: ("GUILDS" | "GUILD_MEMBERS" | "GUILD_BANS" | "GUILD_EMOJIS_AND_STICKERS" | "GUILD_INTEGRATIONS" | "GUILD_WEBHOOKS" | "GUILD_INVITES" | "GUILD_VOICE_STATES" | "GUILD_PRESENCES" | "GUILD_MESSAGES" | "GUILD_MESSAGE_REACTIONS" | "GUILD_MESSAGE_TYPING" | "DIRECT_MESSAGES" | "DIRECT_MESSAGE_REACTIONS" | "DIRECT_MESSAGE_TYPING" | "MESSAGE_CONTENT" | "GUILD_SCHEDULED_EVENTS" | "AUTO_MODERATION_CONFIGURATION" | "AUTO_MODERATION_EXECUTION")[]) => number;
21
+ /**
22
+ * Check if an intent flag exists in the permissions.
23
+ */
24
+ export declare const has: (flag: string | number) => (bits: string | number) => boolean;
@@ -0,0 +1,28 @@
1
+ import * as tsplus_module_1 from "dfx/common";
2
+ /**
3
+ * All the intents
4
+ */
5
+ export const ALL = tsplus_module_1.Flags.all(tsplus_module_1.Discord.GatewayIntents);
6
+ /**
7
+ * Privileged intents
8
+ */
9
+ export const PRIVILEGED = tsplus_module_1.Discord.GatewayIntents.GUILD_PRESENCES |
10
+ tsplus_module_1.Discord.GatewayIntents.GUILD_MEMBERS |
11
+ tsplus_module_1.Discord.GatewayIntents.MESSAGE_CONTENT;
12
+ /**
13
+ * Un-privileged intents
14
+ */
15
+ export const UNPRIVILEGED = ALL ^ PRIVILEGED;
16
+ /**
17
+ * Function that converts a intents bitfield value to a list of intent names.
18
+ */
19
+ export const toList = tsplus_module_1.Flags.toList(tsplus_module_1.Discord.GatewayIntents);
20
+ /**
21
+ * Function that converts a list of intent names to a bitfield value.
22
+ */
23
+ export const fromList = tsplus_module_1.Flags.fromList(tsplus_module_1.Discord.GatewayIntents);
24
+ /**
25
+ * Check if an intent flag exists in the permissions.
26
+ */
27
+ export const has = tsplus_module_1.Flags.has;
28
+ //# sourceMappingURL=intents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intents.js","sourceRoot":"","sources":["../../src/Helpers/intents.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,gBAAA,KAAK,CAAC,GAAG,CAAC,gBAAA,OAAO,CAAC,cAAc,CAAC,CAAA;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GACrB,gBAAA,OAAO,CAAC,cAAc,CAAC,eAAe;IACtC,gBAAA,OAAO,CAAC,cAAc,CAAC,aAAa;IACpC,gBAAA,OAAO,CAAC,cAAc,CAAC,eAAe,CAAA;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,GAAG,UAAU,CAAA;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,gBAAA,KAAK,CAAC,MAAM,CAAC,gBAAA,OAAO,CAAC,cAAc,CAAC,CAAA;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAA,KAAK,CAAC,QAAQ,CAAC,gBAAA,OAAO,CAAC,cAAc,CAAC,CAAA;AAE9D;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,gBAAA,KAAK,CAAC,GAAG,CAAA"}
@@ -0,0 +1,73 @@
1
+ import { Discord, Maybe } from "dfx/common";
2
+ /**
3
+ * Maybe find a sub-command within the interaction options.
4
+ */
5
+ export declare const allSubCommands: (interaction: Discord.ApplicationCommandDatum) => readonly import("../types.js").ApplicationCommandInteractionDataOption[];
6
+ /**
7
+ * Maybe find a sub-command within the interaction options.
8
+ */
9
+ export declare const findSubCommand: (name: string) => (interaction: Discord.ApplicationCommandDatum) => import("../common.js").Maybe<import("../types.js").ApplicationCommandInteractionDataOption>;
10
+ /**
11
+ * If the sub-command exists return `true`, else `false`.
12
+ */
13
+ export declare const isSubCommand: (name: string) => (interaction: import("../types.js").ApplicationCommandDatum) => boolean;
14
+ /**
15
+ * Maybe get the options for a sub-command
16
+ */
17
+ export declare const subCommandOptions: (name: string) => (interaction: import("../types.js").ApplicationCommandDatum) => import("../common.js").Maybe<import("../types.js").ApplicationCommandInteractionDataOption[]>;
18
+ /**
19
+ * A lens for accessing nested options in a interaction.
20
+ */
21
+ export declare const optionsWithNested: (data: Pick<Discord.ApplicationCommandDatum, "options">) => Discord.ApplicationCommandInteractionDataOption[];
22
+ /**
23
+ * Return the interaction options as a name / value map.
24
+ */
25
+ export declare const transformOptions: (options: Discord.ApplicationCommandInteractionDataOption[]) => Record<string, string | undefined>;
26
+ /**
27
+ * Return the interaction options as a name / value map.
28
+ */
29
+ export declare const optionsMap: (data: Pick<import("../types.js").ApplicationCommandDatum, "options">) => Record<string, string | undefined>;
30
+ /**
31
+ * Try find a matching option from the interaction.
32
+ */
33
+ export declare const getOption: (name: string) => (data: Pick<import("../types.js").ApplicationCommandDatum, "options">) => import("../common.js").Maybe<import("../types.js").ApplicationCommandInteractionDataOption>;
34
+ /**
35
+ * Try find a matching option from the interaction.
36
+ */
37
+ export declare const focusedOption: (data: Pick<import("../types.js").ApplicationCommandDatum, "options">) => import("../common.js").Maybe<import("../types.js").ApplicationCommandInteractionDataOption>;
38
+ /**
39
+ * Try find a matching option value from the interaction.
40
+ */
41
+ export declare const optionValue: (name: string) => (data: Pick<import("../types.js").ApplicationCommandDatum, "options">) => import("../common.js").Maybe<string>;
42
+ /**
43
+ * Try extract resolved data
44
+ */
45
+ export declare const resolved: (data: Discord.ApplicationCommandDatum) => import("../common.js").Maybe<import("../types.js").ResolvedDatum>;
46
+ /**
47
+ * Try find a matching option value from the interaction.
48
+ */
49
+ export declare const resolveOptionValue: <T>(name: string, f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined) => (a: Discord.ApplicationCommandDatum) => import("../common.js").Maybe<T>;
50
+ /**
51
+ * A lens for accessing the components in a interaction.
52
+ */
53
+ export declare const components: (a: Discord.ModalSubmitDatum) => Discord.Component[];
54
+ /**
55
+ * A lens for accessing the components in a interaction.
56
+ */
57
+ export declare const componentsWithValue: (a: import("../types.js").ModalSubmitDatum) => readonly import("../types.js").Component[];
58
+ /**
59
+ * Return the interaction components as an id / value map.
60
+ */
61
+ export declare const transformComponents: (options: Discord.Component[]) => Record<string, string | undefined>;
62
+ /**
63
+ * Return the interaction components as an id / value map.
64
+ */
65
+ export declare const componentsMap: (a: import("../types.js").ModalSubmitDatum) => Record<string, string | undefined>;
66
+ /**
67
+ * Try find a matching component from the interaction.
68
+ */
69
+ export declare const getComponent: (id: string) => (a: import("../types.js").ModalSubmitDatum) => import("../common.js").Maybe<import("../types.js").Component>;
70
+ /**
71
+ * Try find a matching component value from the interaction.
72
+ */
73
+ export declare const componentValue: (id: string) => (a: import("../types.js").ModalSubmitDatum) => import("../common.js").Maybe<string>;
@@ -0,0 +1,93 @@
1
+ import * as tsplus_module_1 from "dfx/common";
2
+ import * as tsplus_module_2 from "@fp-ts/data/Function";
3
+ import * as tsplus_module_3 from "@fp-ts/data/Option";
4
+ import * as Arr from "@fp-ts/data/ReadonlyArray";
5
+ /**
6
+ * Maybe find a sub-command within the interaction options.
7
+ */
8
+ export const allSubCommands = (interaction) => tsplus_module_2.pipe(optionsWithNested(interaction), Arr.filter((o) => o.type === tsplus_module_1.Discord.ApplicationCommandOptionType.SUB_COMMAND));
9
+ /**
10
+ * Maybe find a sub-command within the interaction options.
11
+ */
12
+ export const findSubCommand = (name) => (interaction) => tsplus_module_2.pipe(optionsWithNested(interaction), Arr.findFirst((o) => o.type === tsplus_module_1.Discord.ApplicationCommandOptionType.SUB_COMMAND &&
13
+ o.name === name));
14
+ /**
15
+ * If the sub-command exists return `true`, else `false`.
16
+ */
17
+ export const isSubCommand = (name) => tsplus_module_2.flow(findSubCommand(name), (o) => tsplus_module_3.isSome(o));
18
+ /**
19
+ * Maybe get the options for a sub-command
20
+ */
21
+ export const subCommandOptions = (name) => tsplus_module_2.flow(findSubCommand(name), (o) => tsplus_module_3.flatMapNullable((o) => o.options)(o));
22
+ /**
23
+ * A lens for accessing nested options in a interaction.
24
+ */
25
+ export const optionsWithNested = (data) => {
26
+ const optsFromOption = (opt) => tsplus_module_3.match(() => [], tsplus_module_2.identity)(tsplus_module_3.map((opts) => [...opts, ...opts.flatMap(optsFromOption)])(tsplus_module_3.fromNullable(opt.options)));
27
+ return tsplus_module_3.getOrElse(() => [])(tsplus_module_3.map((opts) => [...opts, ...opts.flatMap(optsFromOption)])(tsplus_module_3.fromNullable(data.options)));
28
+ };
29
+ /**
30
+ * Return the interaction options as a name / value map.
31
+ */
32
+ export const transformOptions = (options) => options.reduce((map, option) => ({
33
+ ...map,
34
+ [option.name]: option.value,
35
+ }), {});
36
+ /**
37
+ * Return the interaction options as a name / value map.
38
+ */
39
+ export const optionsMap = tsplus_module_2.flow(optionsWithNested, transformOptions);
40
+ /**
41
+ * Try find a matching option from the interaction.
42
+ */
43
+ export const getOption = (name) => tsplus_module_2.flow(optionsWithNested, Arr.findFirst((o) => o.name === name));
44
+ /**
45
+ * Try find a matching option from the interaction.
46
+ */
47
+ export const focusedOption = tsplus_module_2.flow(optionsWithNested, Arr.findFirst((o) => o.focused === true));
48
+ /**
49
+ * Try find a matching option value from the interaction.
50
+ */
51
+ export const optionValue = (name) => tsplus_module_2.flow(getOption(name), (o) => tsplus_module_3.flatMapNullable((o) => o.value)(o));
52
+ /**
53
+ * Try extract resolved data
54
+ */
55
+ export const resolved = (data) => tsplus_module_3.fromNullable(data.resolved);
56
+ /**
57
+ * Try find a matching option value from the interaction.
58
+ */
59
+ export const resolveOptionValue = (name, f) => (a) => tsplus_module_3.flatMap(id => tsplus_module_3.flatMap(data => tsplus_module_3.fromNullable(f(id, data)))(resolved(a)))(tsplus_module_3.flatMapNullable(({ value }) => value)(getOption(name)(a)));
60
+ const extractComponents = (c) => {
61
+ if ("components" in c) {
62
+ return [...c.components, ...c.components.flatMap(extractComponents)];
63
+ }
64
+ return [];
65
+ };
66
+ /**
67
+ * A lens for accessing the components in a interaction.
68
+ */
69
+ export const components = (a) => [
70
+ ...a.components,
71
+ ...a.components.flatMap(extractComponents),
72
+ ];
73
+ /**
74
+ * A lens for accessing the components in a interaction.
75
+ */
76
+ export const componentsWithValue = tsplus_module_2.flow(components, Arr.filter((c) => "value" in c && c.value !== undefined));
77
+ /**
78
+ * Return the interaction components as an id / value map.
79
+ */
80
+ export const transformComponents = (options) => options.reduce((map, c) => (c.custom_id ? { ...map, [c.custom_id]: c.value } : map), {});
81
+ /**
82
+ * Return the interaction components as an id / value map.
83
+ */
84
+ export const componentsMap = tsplus_module_2.flow(components, transformComponents);
85
+ /**
86
+ * Try find a matching component from the interaction.
87
+ */
88
+ export const getComponent = (id) => tsplus_module_2.flow(components, Arr.findFirst((o) => o.custom_id === id));
89
+ /**
90
+ * Try find a matching component value from the interaction.
91
+ */
92
+ export const componentValue = (id) => tsplus_module_2.flow(getComponent(id), (o) => tsplus_module_3.flatMapNullable((o) => o.value)(o));
93
+ //# sourceMappingURL=interactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactions.js","sourceRoot":"","sources":["../../src/Helpers/interactions.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,GAAG,MAAM,2BAA2B,CAAA;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,WAA4C,EAAE,EAAE,CAC7E,gBAAA,IAAI,CACF,iBAAiB,CAAC,WAAW,CAAC,EAC9B,GAAG,CAAC,MAAM,CACR,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAA,OAAO,CAAC,4BAA4B,CAAC,WAAW,CACnE,CACF,CAAA;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,WAA4C,EAAE,EAAE,CACjE,gBAAA,IAAI,CACF,iBAAiB,CAAC,WAAW,CAAC,EAC9B,GAAG,CAAC,SAAS,CACX,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI,KAAK,gBAAA,OAAO,CAAC,4BAA4B,CAAC,WAAW;IAC3D,CAAC,CAAC,IAAI,KAAK,IAAI,CAClB,CACF,CAAA;AAEL;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE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C,SAAS,KAAK,EAAE,CAAC,CAChE,CAAA;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE,CAC3C,gBAAA,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAC3B,gCAAkB,CAAC,CAAC,EAAE,EAAE,CAAE,CAAuB,CAAC,KAAK,EAAvD,CAAC,CAAuD,CACzD,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Discord } from "dfx/common";
2
+ /**
3
+ * From a list of roles, filter out the ones the guild member has.
4
+ */
5
+ export declare const roles: (roles: Discord.Role[]) => (member: Discord.GuildMember) => import("../types.js").Role[];
6
+ /**
7
+ * Type-guard function for checking if the object is a guild member
8
+ */
9
+ export declare const is: (thing: unknown) => thing is import("../types.js").GuildMember;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * From a list of roles, filter out the ones the guild member has.
3
+ */
4
+ export const roles = (roles) => (member) => roles.filter((role) => member.roles.includes(role.id) || role.name === "@everyone");
5
+ /**
6
+ * Type-guard function for checking if the object is a guild member
7
+ */
8
+ export const is = (thing) => Object.prototype.hasOwnProperty.call(thing, "roles") &&
9
+ Object.prototype.hasOwnProperty.call(thing, "joined_at");
10
+ //# sourceMappingURL=members.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"members.js","sourceRoot":"","sources":["../../src/Helpers/members.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAqB,EAAE,EAAE,CAAC,CAAC,MAA2B,EAAE,EAAE,CAC9E,KAAK,CAAC,MAAM,CACV,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,CACtE,CAAA;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAc,EAAgC,EAAE,CACjE,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;IACpD,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA"}
@@ -0,0 +1,34 @@
1
+ import { Discord } from "dfx/common";
2
+ /**
3
+ * A constant of all the permissions
4
+ */
5
+ export declare const ALL: bigint;
6
+ /**
7
+ * Check if a flag exists in the permissions.
8
+ */
9
+ export declare const has: (flag: string | bigint) => (bits: string | bigint) => boolean;
10
+ /**
11
+ * Convert a permissions bitfield to a list of flag names.
12
+ */
13
+ export declare const toList: (bitfield: bigint) => ("CREATE_INSTANT_INVITE" | "KICK_MEMBERS" | "BAN_MEMBERS" | "ADMINISTRATOR" | "MANAGE_CHANNELS" | "MANAGE_GUILD" | "ADD_REACTIONS" | "VIEW_AUDIT_LOG" | "PRIORITY_SPEAKER" | "STREAM" | "VIEW_CHANNEL" | "SEND_MESSAGES" | "SEND_TTS_MESSAGES" | "MANAGE_MESSAGES" | "EMBED_LINKS" | "ATTACH_FILES" | "READ_MESSAGE_HISTORY" | "MENTION_EVERYONE" | "USE_EXTERNAL_EMOJIS" | "VIEW_GUILD_INSIGHTS" | "CONNECT" | "SPEAK" | "MUTE_MEMBERS" | "DEAFEN_MEMBERS" | "MOVE_MEMBERS" | "USE_VAD" | "CHANGE_NICKNAME" | "MANAGE_NICKNAMES" | "MANAGE_ROLES" | "MANAGE_WEBHOOKS" | "MANAGE_EMOJIS_AND_STICKERS" | "USE_APPLICATION_COMMANDS" | "REQUEST_TO_SPEAK" | "MANAGE_EVENTS" | "MANAGE_THREADS" | "CREATE_PUBLIC_THREADS" | "CREATE_PRIVATE_THREADS" | "USE_EXTERNAL_STICKERS" | "SEND_MESSAGES_IN_THREADS" | "USE_EMBEDDED_ACTIVITIES" | "MODERATE_MEMBERS")[];
14
+ /**
15
+ * Convert a list of flag names to a bitfield.
16
+ */
17
+ export declare const fromList: (list: ("CREATE_INSTANT_INVITE" | "KICK_MEMBERS" | "BAN_MEMBERS" | "ADMINISTRATOR" | "MANAGE_CHANNELS" | "MANAGE_GUILD" | "ADD_REACTIONS" | "VIEW_AUDIT_LOG" | "PRIORITY_SPEAKER" | "STREAM" | "VIEW_CHANNEL" | "SEND_MESSAGES" | "SEND_TTS_MESSAGES" | "MANAGE_MESSAGES" | "EMBED_LINKS" | "ATTACH_FILES" | "READ_MESSAGE_HISTORY" | "MENTION_EVERYONE" | "USE_EXTERNAL_EMOJIS" | "VIEW_GUILD_INSIGHTS" | "CONNECT" | "SPEAK" | "MUTE_MEMBERS" | "DEAFEN_MEMBERS" | "MOVE_MEMBERS" | "USE_VAD" | "CHANGE_NICKNAME" | "MANAGE_NICKNAMES" | "MANAGE_ROLES" | "MANAGE_WEBHOOKS" | "MANAGE_EMOJIS_AND_STICKERS" | "USE_APPLICATION_COMMANDS" | "REQUEST_TO_SPEAK" | "MANAGE_EVENTS" | "MANAGE_THREADS" | "CREATE_PUBLIC_THREADS" | "CREATE_PRIVATE_THREADS" | "USE_EXTERNAL_STICKERS" | "SEND_MESSAGES_IN_THREADS" | "USE_EMBEDDED_ACTIVITIES" | "MODERATE_MEMBERS")[]) => bigint;
18
+ /**
19
+ * Reduce a list of roles to a bitfield of all the permissions added together.
20
+ */
21
+ export declare const forRoles: (roles: Discord.Role[]) => bigint;
22
+ /**
23
+ * From a list of roles, calculate the permissions bitfield for the member.
24
+ */
25
+ export declare const forMember: (roles: Discord.Role[]) => (member: Discord.GuildMember) => bigint;
26
+ /**
27
+ * From a list of roles and a channel, calculate the permission bitfield for
28
+ * the guild member or role for that channel.
29
+ */
30
+ export declare const forChannel: (roles: Discord.Role[]) => ({ guild_id, permission_overwrites: overwrites }: Discord.Channel) => (memberOrRole: Discord.GuildMember | Discord.Role) => bigint;
31
+ /**
32
+ * Apply permission overwrites to a bitfield.
33
+ */
34
+ export declare const applyOverwrites: (permissions: bigint) => (overwrites: Discord.Overwrite[]) => bigint;