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.
- package/DiscordConfig/index.d.ts +39 -0
- package/DiscordConfig/index.js +29 -0
- package/DiscordConfig/index.js.map +1 -0
- package/DiscordGateway/DiscordWS/index.d.ts +23 -0
- package/DiscordGateway/DiscordWS/index.js +26 -0
- package/DiscordGateway/DiscordWS/index.js.map +1 -0
- package/DiscordGateway/Shard/heartbeats.d.ts +3 -0
- package/DiscordGateway/Shard/heartbeats.js +24 -0
- package/DiscordGateway/Shard/heartbeats.js.map +1 -0
- package/DiscordGateway/Shard/identify.d.ts +12 -0
- package/DiscordGateway/Shard/identify.js +30 -0
- package/DiscordGateway/Shard/identify.js.map +1 -0
- package/DiscordGateway/Shard/index.d.ts +9 -0
- package/DiscordGateway/Shard/index.js +52 -0
- package/DiscordGateway/Shard/index.js.map +1 -0
- package/DiscordGateway/Shard/invalidSession.d.ts +3 -0
- package/DiscordGateway/Shard/invalidSession.js +10 -0
- package/DiscordGateway/Shard/invalidSession.js.map +1 -0
- package/DiscordGateway/Shard/sendEvents.d.ts +7 -0
- package/DiscordGateway/Shard/sendEvents.js +26 -0
- package/DiscordGateway/Shard/sendEvents.js.map +1 -0
- package/DiscordGateway/Shard/utils.d.ts +3 -0
- package/DiscordGateway/Shard/utils.js +9 -0
- package/DiscordGateway/Shard/utils.js.map +1 -0
- package/DiscordGateway/ShardStore/index.d.ts +12 -0
- package/DiscordGateway/ShardStore/index.js +22 -0
- package/DiscordGateway/ShardStore/index.js.map +1 -0
- package/DiscordGateway/Sharder/index.d.ts +9 -0
- package/DiscordGateway/Sharder/index.js +61 -0
- package/DiscordGateway/Sharder/index.js.map +1 -0
- package/DiscordGateway/WS/index.d.ts +27 -0
- package/DiscordGateway/WS/index.js +82 -0
- package/DiscordGateway/WS/index.js.map +1 -0
- package/DiscordGateway/index.d.ts +20 -0
- package/DiscordGateway/index.js +27 -0
- package/DiscordGateway/index.js.map +1 -0
- package/DiscordREST/index.d.ts +12 -0
- package/DiscordREST/index.js +85 -0
- package/DiscordREST/index.js.map +1 -0
- package/DiscordREST/types.d.ts +9 -0
- package/DiscordREST/types.js +2 -0
- package/DiscordREST/types.js.map +1 -0
- package/DiscordREST/utils.d.ts +10 -0
- package/DiscordREST/utils.js +22 -0
- package/DiscordREST/utils.js.map +1 -0
- package/Helpers/flags.d.ts +27 -0
- package/Helpers/flags.js +36 -0
- package/Helpers/flags.js.map +1 -0
- package/Helpers/intents.d.ts +24 -0
- package/Helpers/intents.js +28 -0
- package/Helpers/intents.js.map +1 -0
- package/Helpers/interactions.d.ts +73 -0
- package/Helpers/interactions.js +93 -0
- package/Helpers/interactions.js.map +1 -0
- package/Helpers/members.d.ts +9 -0
- package/Helpers/members.js +10 -0
- package/Helpers/members.js.map +1 -0
- package/Helpers/permissions.d.ts +34 -0
- package/Helpers/permissions.js +69 -0
- package/Helpers/permissions.js.map +1 -0
- package/Helpers/ui.d.ts +47 -0
- package/Helpers/ui.js +67 -0
- package/Helpers/ui.js.map +1 -0
- package/Http/index.d.ts +30 -0
- package/Http/index.js +53 -0
- package/Http/index.js.map +1 -0
- package/Interactions/context.d.ts +36 -0
- package/Interactions/context.js +34 -0
- package/Interactions/context.js.map +1 -0
- package/Interactions/definitions.d.ts +60 -0
- package/Interactions/definitions.js +52 -0
- package/Interactions/definitions.js.map +1 -0
- package/Interactions/gateway.d.ts +6 -0
- package/Interactions/gateway.js +21 -0
- package/Interactions/gateway.js.map +1 -0
- package/Interactions/handlers.d.ts +8 -0
- package/Interactions/handlers.js +49 -0
- package/Interactions/handlers.js.map +1 -0
- package/Interactions/index.d.ts +17 -0
- package/Interactions/index.js +39 -0
- package/Interactions/index.js.map +1 -0
- package/Interactions/utils.d.ts +10 -0
- package/Interactions/utils.js +61 -0
- package/Interactions/utils.js.map +1 -0
- package/Interactions/webhook.d.ts +32 -0
- package/Interactions/webhook.js +42 -0
- package/Interactions/webhook.js.map +1 -0
- package/Log/index.d.ts +12 -0
- package/Log/index.js +19 -0
- package/Log/index.js.map +1 -0
- package/RateLimitStore/index.d.ts +24 -0
- package/RateLimitStore/index.js +24 -0
- package/RateLimitStore/index.js.map +1 -0
- package/RateLimitStore/memory.d.ts +2 -0
- package/RateLimitStore/memory.js +31 -0
- package/RateLimitStore/memory.js.map +1 -0
- package/RateLimitStore/utils.d.ts +2 -0
- package/RateLimitStore/utils.js +18 -0
- package/RateLimitStore/utils.js.map +1 -0
- package/common-gateway.d.ts +5 -0
- package/common-gateway.js +6 -0
- package/common-gateway.js.map +1 -0
- package/common.d.ts +28 -0
- package/common.js +16 -0
- package/common.js.map +1 -0
- package/global.d.ts +17 -0
- package/global.js +2 -0
- package/global.js.map +1 -0
- package/index.d.ts +21 -0
- package/index.js +29 -0
- package/index.js.map +1 -0
- package/package.json +2 -6
- package/types.d.ts +4228 -0
- package/types.js +1796 -0
- package/types.js.map +1 -0
- package/utils/effect.d.ts +2 -0
- package/utils/effect.js +2 -0
- package/utils/effect.js.map +1 -0
- package/utils/tsplus.d.ts +13 -0
- package/utils/tsplus.js +2 -0
- package/utils/tsplus.js.map +1 -0
- package/webhooks.d.ts +15 -0
- package/webhooks.js +23 -0
- package/webhooks.js.map +1 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Duration, Discord } from "dfx/common";
|
|
2
|
+
export interface DiscordConfig {
|
|
3
|
+
token: string;
|
|
4
|
+
rest: {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
globalRateLimit: {
|
|
7
|
+
limit: number;
|
|
8
|
+
window: Duration;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
gateway: {
|
|
12
|
+
intents: number;
|
|
13
|
+
presence?: Discord.UpdatePresence;
|
|
14
|
+
shardCount?: number;
|
|
15
|
+
identifyRateLimit: readonly [window: number, limit: number];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare const DiscordConfig: import("../common.js").Tag<DiscordConfig>;
|
|
19
|
+
export interface MakeOpts {
|
|
20
|
+
token: string;
|
|
21
|
+
rest?: Partial<DiscordConfig["rest"]>;
|
|
22
|
+
gateway?: Partial<DiscordConfig["gateway"]>;
|
|
23
|
+
}
|
|
24
|
+
export declare const make: ({ token, rest, gateway }: MakeOpts) => DiscordConfig;
|
|
25
|
+
export declare const makeLayer: (a_0: MakeOpts) => import("../common.js").Layer<never, never, DiscordConfig>;
|
|
26
|
+
export declare const token: import("../common.js").Effect<DiscordConfig, never, string>;
|
|
27
|
+
export declare const rest: import("../common.js").Effect<DiscordConfig, never, {
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
globalRateLimit: {
|
|
30
|
+
limit: number;
|
|
31
|
+
window: Duration;
|
|
32
|
+
};
|
|
33
|
+
}>;
|
|
34
|
+
export declare const gateway: import("../common.js").Effect<DiscordConfig, never, {
|
|
35
|
+
intents: number;
|
|
36
|
+
presence?: import("../types.js").UpdatePresence | undefined;
|
|
37
|
+
shardCount?: number | undefined;
|
|
38
|
+
identifyRateLimit: readonly [window: number, limit: number];
|
|
39
|
+
}>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "dfx/common";
|
|
2
|
+
import * as tsplus_module_2 from "@fp-ts/data/Duration";
|
|
3
|
+
import * as tsplus_module_3 from "@effect/io/Layer";
|
|
4
|
+
import * as tsplus_module_4 from "@fp-ts/data/Function";
|
|
5
|
+
import * as tsplus_module_5 from "@effect/io/Effect";
|
|
6
|
+
const VERSION = 9;
|
|
7
|
+
export const DiscordConfig = tsplus_module_1.Tag();
|
|
8
|
+
export const make = ({ token, rest, gateway }) => ({
|
|
9
|
+
token,
|
|
10
|
+
rest: {
|
|
11
|
+
baseUrl: `https://discord.com/api/v${VERSION}`,
|
|
12
|
+
...(rest ?? {}),
|
|
13
|
+
globalRateLimit: {
|
|
14
|
+
limit: 50,
|
|
15
|
+
window: tsplus_module_2.seconds(1),
|
|
16
|
+
...(rest?.globalRateLimit ?? {}),
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
gateway: {
|
|
20
|
+
intents: tsplus_module_1.Discord.GatewayIntents.GUILDS,
|
|
21
|
+
identifyRateLimit: [5000, 1],
|
|
22
|
+
...(gateway ?? {}),
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
export const makeLayer = tsplus_module_4.flow(make, tsplus_module_3.succeed(DiscordConfig));
|
|
26
|
+
export const token = tsplus_module_5.serviceWith(DiscordConfig)(({ token }) => token);
|
|
27
|
+
export const rest = tsplus_module_5.serviceWith(DiscordConfig)(({ rest }) => rest);
|
|
28
|
+
export const gateway = tsplus_module_5.serviceWith(DiscordConfig)(({ gateway }) => gateway);
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/DiscordConfig/index.ts"],"names":[],"mappings":";;;;;AAAA,MAAM,OAAO,GAAG,CAAC,CAAA;AAmBjB,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAA,GAAG,EAAiB,CAAA;AAQjD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAY,EAAiB,EAAE,CAAC,CAAC;IAC1E,KAAK;IACL,IAAI,EAAE;QACJ,OAAO,EAAE,4BAA4B,OAAO,EAAE;QAC9C,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QACf,eAAe,EAAE;YACf,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,wBAAiB,CAAC,CAAC;YAC3B,GAAG,CAAC,IAAI,EAAE,eAAe,IAAI,EAAE,CAAC;SACjC;KACF;IACD,OAAO,EAAE;QACP,OAAO,EAAE,gBAAA,OAAO,CAAC,cAAc,CAAC,MAAM;QACtC,iBAAiB,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5B,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;KACnB;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,gBAAA,IAAI,CAAC,IAAI,EAAE,wBAAc,aAAa,CAAC,CAAC,CAAA;AAEjE,MAAM,CAAC,MAAM,KAAK,GAAG,4BAAmB,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAA;AAC5E,MAAM,CAAC,MAAM,IAAI,GAAG,4BAAmB,aAAa,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAA;AACzE,MAAM,CAAC,MAAM,OAAO,GAAG,4BAAmB,aAAa,CAAC,CACtD,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CACzB,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="ws" />
|
|
3
|
+
import { Discord, EffectSource } from "dfx/common";
|
|
4
|
+
import { WS } from "dfx/common-gateway";
|
|
5
|
+
import WebSocket from "isomorphic-ws";
|
|
6
|
+
export type Message = Discord.GatewayPayload | WS.Reconnect;
|
|
7
|
+
export interface OpenOpts {
|
|
8
|
+
url?: string;
|
|
9
|
+
version?: number;
|
|
10
|
+
encoding?: DiscordWSCodec;
|
|
11
|
+
}
|
|
12
|
+
export interface DiscordWSCodec {
|
|
13
|
+
type: "json" | "etf";
|
|
14
|
+
encode: (p: Discord.GatewayPayload) => string | Buffer | ArrayBuffer;
|
|
15
|
+
decode: (p: WebSocket.RawData) => Discord.GatewayPayload;
|
|
16
|
+
}
|
|
17
|
+
export declare const DiscordWSCodec: import("../../common.js").Tag<DiscordWSCodec>;
|
|
18
|
+
export declare const LiveJsonDiscordWSCodec: import("../../common.js").Layer<never, never, DiscordWSCodec>;
|
|
19
|
+
export declare const make: ({ url, version, }?: OpenOpts) => import("../../common.js").Effect<import("../../Log/index.js").Log | DiscordWSCodec, never, {
|
|
20
|
+
source: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<any>>;
|
|
21
|
+
sink: import("callbag-effect-ts/Sink").EffectSink<never, never, never, Message>;
|
|
22
|
+
setUrl: (url: string) => import("../../common.js").Effect<never, never, void>;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "dfx/common";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Layer";
|
|
3
|
+
import * as tsplus_module_3 from "dfx/common-gateway";
|
|
4
|
+
import * as tsplus_module_4 from "callbag-effect-ts/Sink/map";
|
|
5
|
+
import * as tsplus_module_5 from "@fp-ts/data/Duration";
|
|
6
|
+
import * as tsplus_module_6 from "@effect/io/Schedule";
|
|
7
|
+
import * as tsplus_module_7 from "callbag-effect-ts/Source/tapError";
|
|
8
|
+
import * as tsplus_module_8 from "callbag-effect-ts/Source/retry";
|
|
9
|
+
import * as tsplus_module_9 from "callbag-effect-ts/Source/map";
|
|
10
|
+
import * as tsplus_module_10 from "@effect/io/Effect";
|
|
11
|
+
import * as tsplus_module_11 from "@effect/io/Ref";
|
|
12
|
+
export const DiscordWSCodec = tsplus_module_1.Tag();
|
|
13
|
+
export const LiveJsonDiscordWSCodec = tsplus_module_2.succeed(DiscordWSCodec)({
|
|
14
|
+
type: "json",
|
|
15
|
+
encode: (p) => JSON.stringify(p),
|
|
16
|
+
decode: (p) => JSON.parse(p.toString("utf8")),
|
|
17
|
+
});
|
|
18
|
+
export const make = ({ url = "wss://gateway.discord.gg/", version = 10, } = {}) => tsplus_module_10.flatMap(encoding => tsplus_module_10.flatMap(urlRef => {
|
|
19
|
+
const setUrl = (url) => tsplus_module_11.set(`${url}?v=${version}&encoding=${encoding.type}`)(urlRef);
|
|
20
|
+
return tsplus_module_10.flatMap(ws => tsplus_module_10.map(log => {
|
|
21
|
+
const source = tsplus_module_9.map(encoding.decode)(tsplus_module_8.retry(tsplus_module_6.exponential(tsplus_module_5.seconds(0.5)))(tsplus_module_7.tapError((e) => log.info("DiscordWS", "ERROR", e))(ws.source)));
|
|
22
|
+
const sink = tsplus_module_4.map((msg) => msg === tsplus_module_3.WS.Reconnect ? msg : encoding.encode(msg))(ws.sink);
|
|
23
|
+
return { source, sink, setUrl };
|
|
24
|
+
})(tsplus_module_10.service(tsplus_module_1.Log.Log)))(tsplus_module_3.WS.make(urlRef, { perMessageDeflate: false }));
|
|
25
|
+
})(tsplus_module_11.make(`${url}?v=${version}&encoding=${encoding.type}`)))(tsplus_module_10.service(DiscordWSCodec));
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/DiscordWS/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAeA,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAA,GAAG,EAAkB,CAAA;AACnD,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAc,cAAc,CAAC,CAAC;IAClE,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC9C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EACnB,GAAG,GAAG,2BAA2B,EACjC,OAAO,GAAG,EAAE,MACA,EAAE,EAAE,EAAE,0BAEV,QAAQ,6BACR,MAAM;IACZ,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE,CAC7B,qBAAW,GAAG,GAAG,MAAM,OAAO,aAAa,QAAQ,CAAC,IAAI,EAAE,EAA1D,MAAM,CAAqD,CAAA;oCAEvD,EAAE,yBAEF,GAAG;QACT,MAAM,MAAM,GAAG,oBAGR,QAAQ,CAAC,MAAM,EAHP,sBAEN,4BAAqB,wBAAiB,GAAG,CAAC,CAAC,EAFrC,yBACH,CAAC,CAAM,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC,EAD1C,EAAE,CAAC,MAAM,CACkC,CACL,CAKpD,CAAA;QAED,MAAM,IAAI,GAAG,oBAAY,CAAC,GAAY,EAAE,EAAE,CACxC,GAAG,KAAK,gBAAA,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EADtC,EAAE,CAAC,IAAI,CAEnB,CAAA;QAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;OAdjB,yBAAe,gBAAA,GAAG,CAAC,GAAG,CAAC,GAFxB,gBAAA,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;GAJzC,sBAAS,GAAG,GAAG,MAAM,OAAO,aAAa,QAAQ,CAAC,IAAI,EAAE,CAAC,GADvD,yBAAe,cAAc,CAAC,CAsBjD,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Ref, Maybe, Effect, EffectSource, Discord } from "dfx/common";
|
|
2
|
+
import { DWS } from "dfx/common-gateway";
|
|
3
|
+
export declare const fromRaw: <R, E>(source: import("callbag-effect-ts/Source").EffectSource<R, E, import("../../types.js").GatewayPayload<any>>, seqRef: Ref<Maybe<number>>) => import("callbag-effect-ts/Source").EffectSource<R, E, import("../DiscordWS/index.js").Message>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@effect/io/Ref";
|
|
2
|
+
import * as tsplus_module_2 from "@fp-ts/data/Option";
|
|
3
|
+
import * as tsplus_module_3 from "@effect/io/Effect";
|
|
4
|
+
import * as tsplus_module_4 from "dfx/common-gateway";
|
|
5
|
+
import * as tsplus_module_5 from "@effect/io/Schedule";
|
|
6
|
+
import * as tsplus_module_6 from "callbag-effect-ts/Source/fromSchedule";
|
|
7
|
+
import * as tsplus_module_7 from "dfx/common";
|
|
8
|
+
import * as tsplus_module_8 from "callbag-effect-ts/Source/tap";
|
|
9
|
+
import * as tsplus_module_9 from "callbag-effect-ts/Source/switchMap";
|
|
10
|
+
import * as tsplus_module_10 from "callbag-effect-ts/Source/mapEffect";
|
|
11
|
+
import * as tsplus_module_11 from "callbag-effect-ts/Source/drain";
|
|
12
|
+
import * as tsplus_module_12 from "callbag-effect-ts/Source/merge";
|
|
13
|
+
import * as tsplus_module_13 from "callbag-effect-ts/Source/unwrap";
|
|
14
|
+
import { millis } from "@fp-ts/data/Duration";
|
|
15
|
+
import * as SendEvents from "./sendEvents.js";
|
|
16
|
+
import * as Utils from "./utils.js";
|
|
17
|
+
const send = (ref, seqRef) => tsplus_module_3.tap(() => tsplus_module_1.set(false)(ref))(tsplus_module_3.map((a) => SendEvents.heartbeat(tsplus_module_2.getOrNull(a)))(tsplus_module_1.get(seqRef)));
|
|
18
|
+
const maybeSend = (ref, seqRef) => tsplus_module_3.flatMap((acked) => acked ? send(ref, seqRef) : tsplus_module_3.succeed(tsplus_module_4.WS.Reconnect))(tsplus_module_1.get(ref));
|
|
19
|
+
export const fromRaw = (source, seqRef) => tsplus_module_13.unwrap(tsplus_module_3.map((ackedRef) => {
|
|
20
|
+
const heartbeats = tsplus_module_10.mapEffect(() => maybeSend(ackedRef, seqRef))(tsplus_module_9.switchMap((p) => tsplus_module_6.fromSchedule(tsplus_module_5.andThen(tsplus_module_5.spaced(millis(p.d.heartbeat_interval)))(tsplus_module_5.duration(millis(p.d.heartbeat_interval * Math.random())))))(tsplus_module_8.tap(() => tsplus_module_1.set(true)(ackedRef))(Utils.opCode(source)(tsplus_module_7.Discord.GatewayOpcode.HELLO))));
|
|
21
|
+
const acks = tsplus_module_11.drain(tsplus_module_8.tap(() => tsplus_module_1.set(true)(ackedRef))(Utils.opCode(source)(tsplus_module_7.Discord.GatewayOpcode.HEARTBEAT_ACK)));
|
|
22
|
+
return tsplus_module_12.merge(acks)(heartbeats);
|
|
23
|
+
})(tsplus_module_1.make(true)));
|
|
24
|
+
//# sourceMappingURL=heartbeats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeats.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Shard/heartbeats.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,MAAM,IAAI,GAAG,CAAC,GAAiB,EAAE,MAA0B,EAAE,EAAE,CAC7D,oBAEO,GAAG,EAAE,CAAC,oBAAQ,KAAK,EAAb,GAAG,CAAW,EAF3B,oBACO,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,2BAAC,CAAC,EAAW,sBAD/C,MAAM,EAC0C,CACpB,CAAA;AAE9B,MAAM,SAAS,GAAG,CAAC,GAAiB,EAAE,MAA0B,EAAE,EAAE,CAClE,wBACE,CAAC,KAAK,EAAqC,EAAE,CAC3C,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,wBAAe,gBAAA,EAAE,CAAC,SAAS,CAAC,sBAF5D,GAAG,EAGF,CAAA;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,MAAkD,EAClD,MAA0B,EAC1B,EAAE,yBACF,oBAAmB,CAAC,QAAQ,EAAE,EAAE;IAC9B,MAAM,UAAU,GAAG,2BAWN,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,EAX3B,0BAIN,CAAC,CAAC,EAAE,EAAE,CACf,6BACE,wBAEU,uBAAgB,MAAM,CAAC,CAAC,CAAC,CAAE,CAAC,kBAAkB,CAAC,CAAC,EAF1D,yBACE,MAAM,CAAC,CAAC,CAAC,CAAE,CAAC,kBAAkB,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAChD,CAA0D,CAC5D,EATc,oBAGZ,GAAG,EAAE,CAAC,oBAAa,IAAI,EAAjB,QAAQ,CAAU,EAHZ,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CACrC,gBAAA,OAAO,CAAC,aAAa,CAAC,KAAK,CAC5B,CAC+B,CAO7B,CAC4C,CAAA;IAE/C,MAAM,IAAI,0BAAG,oBACX,GAAG,EAAE,CAAC,oBAAa,IAAI,EAAjB,QAAQ,CAAU,EADb,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,gBAAA,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAErE,CAAM,CAAA;IAEP,OAAO,uBAAiB,IAAI,EAArB,UAAU,CAAY,CAAA;AAC/B,CAAC,EAnBD,qBAAS,IAAI,CAAC,CAmBZ,CAAO,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Discord, Ref, Maybe, EffectSource } from "dfx/common";
|
|
2
|
+
export interface Options {
|
|
3
|
+
token: string;
|
|
4
|
+
intents: number;
|
|
5
|
+
shard: [number, number];
|
|
6
|
+
presence?: Discord.UpdatePresence;
|
|
7
|
+
}
|
|
8
|
+
export interface Requirements {
|
|
9
|
+
latestReady: Ref<Maybe<Discord.ReadyEvent>>;
|
|
10
|
+
latestSequence: Ref<Maybe<number>>;
|
|
11
|
+
}
|
|
12
|
+
export declare const fromRaw: <R, E>(source: import("callbag-effect-ts/Source").EffectSource<R, E, import("../../types.js").GatewayPayload<any>>, { latestReady, latestSequence, ...opts }: Options & Requirements) => import("callbag-effect-ts/Source").EffectSource<R, E, import("../../types.js").GatewayPayload<any>>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@fp-ts/data/Option";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Ref";
|
|
3
|
+
import * as tsplus_module_3 from "@effect/io/Effect";
|
|
4
|
+
import * as tsplus_module_4 from "dfx/common";
|
|
5
|
+
import * as tsplus_module_5 from "callbag-effect-ts/Source/mapEffect";
|
|
6
|
+
import * as SendEvents from "./sendEvents.js";
|
|
7
|
+
import * as OS from "os";
|
|
8
|
+
import { opCode } from "./utils.js";
|
|
9
|
+
const identify = ({ token, intents, shard, presence }) => SendEvents.identify({
|
|
10
|
+
token,
|
|
11
|
+
intents,
|
|
12
|
+
properties: {
|
|
13
|
+
os: OS.platform(),
|
|
14
|
+
browser: "dfx",
|
|
15
|
+
device: "dfx",
|
|
16
|
+
},
|
|
17
|
+
shard,
|
|
18
|
+
presence,
|
|
19
|
+
});
|
|
20
|
+
const resume = (token, ready, seq) => SendEvents.resume({
|
|
21
|
+
token,
|
|
22
|
+
session_id: ready.session_id,
|
|
23
|
+
seq,
|
|
24
|
+
});
|
|
25
|
+
const identifyOrResume = (opts, ready, seq) => tsplus_module_3.flatMap(readyEvent => tsplus_module_3.map(seqNumber => tsplus_module_1.match(() => identify(opts), ({ readyEvent, seqNumber }) => resume(opts.token, readyEvent, seqNumber))(tsplus_module_1.struct({
|
|
26
|
+
readyEvent,
|
|
27
|
+
seqNumber,
|
|
28
|
+
})))(tsplus_module_2.get(seq)))(tsplus_module_2.get(ready));
|
|
29
|
+
export const fromRaw = (source, { latestReady, latestSequence, ...opts }) => tsplus_module_5.mapEffect(() => identifyOrResume(opts, latestReady, latestSequence))(opCode(source)(tsplus_module_4.Discord.GatewayOpcode.HELLO));
|
|
30
|
+
//# sourceMappingURL=identify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Shard/identify.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY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import { Discord } from "dfx/common";
|
|
3
|
+
export declare const make: (shard: [id: number, count: number]) => import("../../common.js").Effect<import("../../DiscordConfig/index.js").DiscordConfig | import("../../Log/index.js").Log | import("../../RateLimitStore/index.js").RateLimiter | import("../DiscordWS/index.js").DiscordWSCodec, never, {
|
|
4
|
+
run: import("../../common.js").Effect<never, never, readonly [readonly [readonly [readonly [void, void], void], void], void]>;
|
|
5
|
+
raw: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<any>>;
|
|
6
|
+
dispatch: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<import("../../types.js").ReceiveEvent>>;
|
|
7
|
+
send: (p: Discord.GatewayPayload) => void;
|
|
8
|
+
reconnect: () => void;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@effect/io/Effect";
|
|
2
|
+
import * as tsplus_module_2 from "dfx/common-gateway";
|
|
3
|
+
import * as tsplus_module_3 from "callbag-effect-ts/Source/forEach";
|
|
4
|
+
import * as tsplus_module_4 from "dfx/common";
|
|
5
|
+
import * as tsplus_module_5 from "callbag-effect-ts/Source/filter";
|
|
6
|
+
import * as tsplus_module_6 from "callbag-effect-ts/Source/tap";
|
|
7
|
+
import * as tsplus_module_7 from "callbag-effect-ts/Source/run";
|
|
8
|
+
import * as tsplus_module_8 from "@fp-ts/data/Option";
|
|
9
|
+
import * as tsplus_module_9 from "callbag-effect-ts/Source/share";
|
|
10
|
+
import * as tsplus_module_10 from "@fp-ts/data/Duration";
|
|
11
|
+
import * as tsplus_module_11 from "callbag-effect-ts/Source/async";
|
|
12
|
+
import * as Heartbeats from "./heartbeats.js";
|
|
13
|
+
import * as Identify from "./identify.js";
|
|
14
|
+
import * as InvalidSession from "./invalidSession.js";
|
|
15
|
+
import * as Utils from "./utils.js";
|
|
16
|
+
export const make = (shard) => tsplus_module_1.flatMap(({ token, gateway }) => tsplus_module_1.flatMap(socket => {
|
|
17
|
+
const [emit, outgoing] = tsplus_module_11.asyncEmitter();
|
|
18
|
+
return tsplus_module_1.flatMap(limiter => {
|
|
19
|
+
const sendEffect = tsplus_module_7.run(tsplus_module_6.tap(() => limiter.maybeWait("shard.send", tsplus_module_10.minutes(1), 120))(outgoing), socket.sink);
|
|
20
|
+
return tsplus_module_1.flatMap(raw => {
|
|
21
|
+
const sendMessage = (a) => tsplus_module_1.sync(() => {
|
|
22
|
+
emit.data(a);
|
|
23
|
+
});
|
|
24
|
+
return tsplus_module_1.flatMap(([latestReady, updateLatestReady]) => tsplus_module_1.map(([latestSequence, updateLatestSequence]) => {
|
|
25
|
+
const maybeUpdateUrl = (p) => tsplus_module_8.match(() => tsplus_module_1.unit(), (a) => socket.setUrl(a.resume_gateway_url))(tsplus_module_8.map((p) => p.d)(tsplus_module_8.filter((p) => p.op === tsplus_module_4.Discord.GatewayOpcode.DISPATCH && p.t === "READY")(tsplus_module_8.some(p))));
|
|
26
|
+
const updateRefs = tsplus_module_7.runDrain(tsplus_module_6.tap(maybeUpdateUrl)(tsplus_module_6.tap(updateLatestSequence)(tsplus_module_6.tap(updateLatestReady)(raw))));
|
|
27
|
+
// heartbeats
|
|
28
|
+
const heartbeatEffects = tsplus_module_3.forEach(sendMessage)(Heartbeats.fromRaw(raw, latestSequence));
|
|
29
|
+
const dispatch = tsplus_module_5.filter((p) => p.op === tsplus_module_4.Discord.GatewayOpcode.DISPATCH)(raw);
|
|
30
|
+
// identify
|
|
31
|
+
const identifyEffects = tsplus_module_3.forEach(sendMessage)(Identify.fromRaw(raw, {
|
|
32
|
+
token,
|
|
33
|
+
shard,
|
|
34
|
+
intents: gateway.intents,
|
|
35
|
+
presence: gateway.presence,
|
|
36
|
+
latestSequence,
|
|
37
|
+
latestReady,
|
|
38
|
+
}));
|
|
39
|
+
// invalid session
|
|
40
|
+
const invalidEffects = tsplus_module_3.forEach(sendMessage)(InvalidSession.fromRaw(raw, latestReady));
|
|
41
|
+
return {
|
|
42
|
+
run: tsplus_module_1.zipPar(sendEffect)(tsplus_module_1.zipPar(invalidEffects)(tsplus_module_1.zipPar(identifyEffects)(tsplus_module_1.zipPar(heartbeatEffects)(updateRefs)))),
|
|
43
|
+
raw,
|
|
44
|
+
dispatch,
|
|
45
|
+
send: (p) => emit.data(p),
|
|
46
|
+
reconnect: () => emit.data(tsplus_module_2.WS.Reconnect),
|
|
47
|
+
};
|
|
48
|
+
})(Utils.latest((p) => tsplus_module_8.fromNullable(p.s))))(Utils.latest((p) => tsplus_module_8.map((p) => p.d)(tsplus_module_8.filter((p) => p.op === tsplus_module_4.Discord.GatewayOpcode.DISPATCH && p.t === "READY")(tsplus_module_8.some(p)))));
|
|
49
|
+
})(tsplus_module_9.share(socket.source));
|
|
50
|
+
})(tsplus_module_1.service(tsplus_module_4.RateLimitStore.RateLimiter));
|
|
51
|
+
})(tsplus_module_2.DWS.make()))(tsplus_module_1.service(tsplus_module_4.Config.DiscordConfig));
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Shard/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAkC,EAAE,EAAE,0BAEjD,EAAE,KAAK,EAAE,OAAO,EAAE,6BAElB,MAAM;IAEZ,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,+BAA+C,CAAA;mCAClE,OAAO;QACb,MAAM,UAAU,GAAG,oBAAA,oBACZ,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,EAAE,yBAAiB,CAAC,CAAC,EAAE,GAA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+
import { EffectSource, Discord, Ref, Maybe } from "dfx/common";
|
|
2
|
+
import { DWS } from "dfx/common-gateway";
|
|
3
|
+
export declare const fromRaw: <R, E>(raw: import("callbag-effect-ts/Source").EffectSource<R, E, import("../../types.js").GatewayPayload<any>>, latestReady: Ref<Maybe<Discord.ReadyEvent>>) => import("callbag-effect-ts/Source").EffectSource<R, E, import("../DiscordWS/index.js").Message>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "dfx/common-gateway";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import * as tsplus_module_3 from "@fp-ts/data/Option";
|
|
4
|
+
import * as tsplus_module_4 from "@effect/io/Ref";
|
|
5
|
+
import * as tsplus_module_5 from "dfx/common";
|
|
6
|
+
import * as tsplus_module_6 from "callbag-effect-ts/Source/tap";
|
|
7
|
+
import * as tsplus_module_7 from "callbag-effect-ts/Source/map";
|
|
8
|
+
import { opCode } from "./utils.js";
|
|
9
|
+
export const fromRaw = (raw, latestReady) => tsplus_module_7.map(() => tsplus_module_1.WS.Reconnect)(tsplus_module_6.tap((p) => (p.d ? tsplus_module_2.unit() : tsplus_module_4.set(tsplus_module_3.none)(latestReady)))(opCode(raw)(tsplus_module_5.Discord.GatewayOpcode.INVALID_SESSION)));
|
|
10
|
+
//# sourceMappingURL=invalidSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalidSession.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Shard/invalidSession.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,GAA+C,EAC/C,WAA2C,EAC3C,EAAE,CACF,oBAIO,GAAgB,EAAE,CAAC,gBAAA,EAAE,CAAC,SAAS,EAJtC,oBAGO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAa,CAAC,CAAC,CAAC,0CAAA,WAAW,CAAgB,CAAC,EAHjE,MAAM,CAAC,GAAG,CAAC,CACT,gBAAA,OAAO,CAAC,aAAa,CAAC,eAAe,CACtC,CACiE,CAC3B,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Discord } from "dfx/common";
|
|
2
|
+
export declare const heartbeat: (d: Discord.Heartbeat) => Discord.GatewayPayload;
|
|
3
|
+
export declare const identify: (d: Discord.Identify) => Discord.GatewayPayload;
|
|
4
|
+
export declare const resume: (d: Discord.Resume) => Discord.GatewayPayload;
|
|
5
|
+
export declare const requestGuildMembers: (d: Discord.RequestGuildMember) => Discord.GatewayPayload;
|
|
6
|
+
export declare const voiceStateUpdate: (d: Discord.UpdateVoiceState) => Discord.GatewayPayload;
|
|
7
|
+
export declare const presenceUpdate: (d: Discord.UpdatePresence) => Discord.GatewayPayload;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "dfx/common";
|
|
2
|
+
export const heartbeat = (d) => ({
|
|
3
|
+
op: tsplus_module_1.Discord.GatewayOpcode.HEARTBEAT,
|
|
4
|
+
d,
|
|
5
|
+
});
|
|
6
|
+
export const identify = (d) => ({
|
|
7
|
+
op: tsplus_module_1.Discord.GatewayOpcode.IDENTIFY,
|
|
8
|
+
d,
|
|
9
|
+
});
|
|
10
|
+
export const resume = (d) => ({
|
|
11
|
+
op: tsplus_module_1.Discord.GatewayOpcode.RESUME,
|
|
12
|
+
d,
|
|
13
|
+
});
|
|
14
|
+
export const requestGuildMembers = (d) => ({
|
|
15
|
+
op: tsplus_module_1.Discord.GatewayOpcode.REQUEST_GUILD_MEMBERS,
|
|
16
|
+
d,
|
|
17
|
+
});
|
|
18
|
+
export const voiceStateUpdate = (d) => ({
|
|
19
|
+
op: tsplus_module_1.Discord.GatewayOpcode.VOICE_STATE_UPDATE,
|
|
20
|
+
d,
|
|
21
|
+
});
|
|
22
|
+
export const presenceUpdate = (d) => ({
|
|
23
|
+
op: tsplus_module_1.Discord.GatewayOpcode.PRESENCE_UPDATE,
|
|
24
|
+
d,
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=sendEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendEvents.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Shard/sendEvents.ts"],"names":[],"mappings":";AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAoB,EAA0B,EAAE,CAAC,CAAC;IAC1E,EAAE,EAAE,gBAAA,OAAO,CAAC,aAAa,CAAC,SAAS;IACnC,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAmB,EAA0B,EAAE,CAAC,CAAC;IACxE,EAAE,EAAE,gBAAA,OAAO,CAAC,aAAa,CAAC,QAAQ;IAClC,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAiB,EAA0B,EAAE,CAAC,CAAC;IACpE,EAAE,EAAE,gBAAA,OAAO,CAAC,aAAa,CAAC,MAAM;IAChC,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,CAA6B,EACL,EAAE,CAAC,CAAC;IAC5B,EAAE,EAAE,gBAAA,OAAO,CAAC,aAAa,CAAC,qBAAqB;IAC/C,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,CAA2B,EACH,EAAE,CAAC,CAAC;IAC5B,EAAE,EAAE,gBAAA,OAAO,CAAC,aAAa,CAAC,kBAAkB;IAC5C,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,CAAyB,EACD,EAAE,CAAC,CAAC;IAC5B,EAAE,EAAE,gBAAA,OAAO,CAAC,aAAa,CAAC,eAAe;IACzC,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { EffectSource, Discord, Maybe, Ref } from "dfx/common";
|
|
2
|
+
export declare const opCode: <R, E>(source: import("callbag-effect-ts/Source").EffectSource<R, E, import("../../types.js").GatewayPayload<any>>) => <T = any>(code: Discord.GatewayOpcode) => import("callbag-effect-ts/Source").EffectSource<R, E, import("../../types.js").GatewayPayload<T>>;
|
|
3
|
+
export declare const latest: <T>(f: (p: Discord.GatewayPayload) => import("../../common.js").Maybe<T>) => import("../../common.js").Effect<never, never, readonly [import("../../common.js").Ref<import("../../common.js").Maybe<T>>, (p: import("../../types.js").GatewayPayload<any>) => import("../../common.js").Effect<never, never, void>]>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "callbag-effect-ts/Source/filter";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import * as tsplus_module_3 from "@fp-ts/data/Option";
|
|
4
|
+
import * as tsplus_module_4 from "@effect/io/Ref";
|
|
5
|
+
import * as tsplus_module_5 from "@fp-ts/data/Function";
|
|
6
|
+
export const opCode = (source) => (code) => tsplus_module_1.filter((p) => p.op === code)(source);
|
|
7
|
+
const maybeUpdateRef = (f, ref) => tsplus_module_5.flow(f, (o) => tsplus_module_3.match(tsplus_module_2.unit, (a) => tsplus_module_4.set(tsplus_module_3.some(a))(ref))(o));
|
|
8
|
+
export const latest = (f) => tsplus_module_2.map((ref) => [ref, maybeUpdateRef(f, ref)])(tsplus_module_4.make(tsplus_module_3.none));
|
|
9
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Shard/utils.ts"],"names":[],"mappings":";;;;;AAAA,MAAM,CAAC,MAAM,MAAM,GACjB,CAAO,MAAkD,EAAE,EAAE,CAC7D,CAAU,IAA2B,EAAE,EAAE,CACvC,uBAAc,CAAC,CAAC,EAAkC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAAlE,MAAM,CAA6D,CAAA;AAEvE,MAAM,cAAc,GAAG,CACrB,CAA0C,EAC1C,GAAkB,EAClB,EAAE,CAAC,gBAAA,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,4CAAqB,CAAC,CAAC,EAAE,EAAE,CAAC,oBAAQ,qBAAW,CAAC,CAAC,EAArB,GAAG,CAAmB,EAAlD,CAAC,CAAkD,CAAC,CAAA;AAExE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAI,CAA0C,EAAE,EAAE,CACtE,oBACE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,CAAU,EADjD,0CAA8B,CAE7B,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect, Maybe } from "dfx/common";
|
|
2
|
+
export interface ClaimIdContext {
|
|
3
|
+
sharderCount: number;
|
|
4
|
+
totalCount: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ShardStore {
|
|
7
|
+
claimId: (ctx: ClaimIdContext) => Effect<never, never, Maybe<number>>;
|
|
8
|
+
allClaimed: (totalCount: number) => Effect<never, never, boolean>;
|
|
9
|
+
heartbeat?: (shardId: number) => Effect<never, never, void>;
|
|
10
|
+
}
|
|
11
|
+
export declare const ShardStore: import("../../common.js").Tag<ShardStore>;
|
|
12
|
+
export declare const LiveMemoryShardStore: import("../../common.js").Layer<never, never, ShardStore>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "dfx/common";
|
|
2
|
+
import * as tsplus_module_2 from "@fp-ts/data/Option";
|
|
3
|
+
import * as tsplus_module_3 from "@effect/io/Effect";
|
|
4
|
+
import * as tsplus_module_4 from "@effect/io/Layer";
|
|
5
|
+
export const ShardStore = tsplus_module_1.Tag();
|
|
6
|
+
// Very basic shard id store, that does no health checks
|
|
7
|
+
const memoryStore = () => {
|
|
8
|
+
let currentId = 0;
|
|
9
|
+
return {
|
|
10
|
+
claimId: ({ totalCount }) => tsplus_module_3.sync(() => {
|
|
11
|
+
if (currentId >= totalCount) {
|
|
12
|
+
return tsplus_module_2.none;
|
|
13
|
+
}
|
|
14
|
+
const id = currentId;
|
|
15
|
+
currentId++;
|
|
16
|
+
return tsplus_module_2.some(id);
|
|
17
|
+
}),
|
|
18
|
+
allClaimed: (totalCount) => tsplus_module_3.sync(() => currentId >= totalCount),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const LiveMemoryShardStore = tsplus_module_4.sync(ShardStore)(memoryStore);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/ShardStore/index.ts"],"names":[],"mappings":";;;;AAUA,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAA,GAAG,EAAc,CAAA;AAE3C,wDAAwD;AACxD,MAAM,WAAW,GAAG,GAAe,EAAE;IACnC,IAAI,SAAS,GAAG,CAAC,CAAA;IAEjB,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAC1B,qBAAY,GAAG,EAAE;YACf,IAAI,SAAS,IAAI,UAAU,EAAE;gBAC3B,4BAAiB;aAClB;YAED,MAAM,EAAE,GAAG,SAAS,CAAA;YACpB,SAAS,EAAE,CAAA;YACX,OAAO,qBAAW,EAAE,CAAC,CAAA;QACvB,CAAC,CAAC;QAEJ,UAAU,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,qBAAY,GAAG,EAAE,CAAC,SAAS,IAAI,UAAU,CAAC;KACvE,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAW,UAAU,CAAC,CAAC,WAAW,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect, Maybe, EffectSource, Discord } from "dfx/common";
|
|
2
|
+
import { ShardStore } from "../ShardStore/index.js";
|
|
3
|
+
export declare const spawn: import("callbag-effect-ts/Source").EffectSource<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
|
+
run: import("../../common.js").Effect<never, never, readonly [readonly [readonly [readonly [void, void], void], void], void]>;
|
|
5
|
+
raw: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<any>>;
|
|
6
|
+
dispatch: import("callbag-effect-ts/Source").EffectSource<never, never, import("../../types.js").GatewayPayload<import("../../types.js").ReceiveEvent>>;
|
|
7
|
+
send: (p: import("../../types.js").GatewayPayload<any>) => void;
|
|
8
|
+
reconnect: () => void;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "callbag-effect-ts/Source/fromEffect";
|
|
2
|
+
import * as tsplus_module_2 from "callbag-effect-ts/Source/resource";
|
|
3
|
+
import * as tsplus_module_3 from "callbag-effect-ts/Source/map";
|
|
4
|
+
import * as tsplus_module_4 from "@fp-ts/data/Duration";
|
|
5
|
+
import * as tsplus_module_5 from "@fp-ts/data/Option";
|
|
6
|
+
import * as tsplus_module_6 from "callbag-effect-ts/Source/empty";
|
|
7
|
+
import * as tsplus_module_7 from "@effect/io/Effect";
|
|
8
|
+
import * as tsplus_module_8 from "callbag-effect-ts/Source/of";
|
|
9
|
+
import * as tsplus_module_9 from "dfx/common-gateway";
|
|
10
|
+
import * as tsplus_module_10 from "callbag-effect-ts/Source/tap";
|
|
11
|
+
import * as tsplus_module_11 from "callbag-effect-ts/Source/mapEffect";
|
|
12
|
+
import * as tsplus_module_12 from "callbag-effect-ts/Source/groupBy";
|
|
13
|
+
import * as tsplus_module_13 from "callbag-effect-ts/Source/chainPar";
|
|
14
|
+
import * as tsplus_module_14 from "dfx/common";
|
|
15
|
+
import * as tsplus_module_15 from "callbag-effect-ts/Source/drain";
|
|
16
|
+
import * as tsplus_module_16 from "callbag-effect-ts/Source/merge";
|
|
17
|
+
import * as tsplus_module_17 from "callbag-effect-ts/Source/unwrap";
|
|
18
|
+
import { millis } from "@fp-ts/data/Duration";
|
|
19
|
+
import { overridePull } from "callbag-effect-ts/Source";
|
|
20
|
+
import { ShardStore } from "../ShardStore/index.js";
|
|
21
|
+
const configs = (totalCount) => tsplus_module_7.map(store => {
|
|
22
|
+
const claimId = (sharderCount) => tsplus_module_7.flatMap((a) => tsplus_module_5.match(() => tsplus_module_7.delay(tsplus_module_4.minutes(3))(tsplus_module_7.succeed([
|
|
23
|
+
tsplus_module_5.some(sharderCount),
|
|
24
|
+
tsplus_module_6.empty,
|
|
25
|
+
])), (id) => tsplus_module_7.succeed([
|
|
26
|
+
tsplus_module_5.some(sharderCount + 1),
|
|
27
|
+
tsplus_module_8.of(id),
|
|
28
|
+
]))(a))(store
|
|
29
|
+
.claimId({
|
|
30
|
+
totalCount,
|
|
31
|
+
sharderCount,
|
|
32
|
+
}));
|
|
33
|
+
return tsplus_module_3.map((id) => ({
|
|
34
|
+
id,
|
|
35
|
+
totalCount,
|
|
36
|
+
}))(tsplus_module_2.resource(0, (sharderCount) => tsplus_module_1.fromEffect(claimId(sharderCount))));
|
|
37
|
+
})(tsplus_module_7.service(ShardStore));
|
|
38
|
+
const spawnEffect = tsplus_module_7.map(({ gateway, config, configs, limiter }) => {
|
|
39
|
+
const [source, pull] = overridePull(configs, gateway.session_start_limit.max_concurrency);
|
|
40
|
+
return tsplus_module_10.tap(() => tsplus_module_7.sync(pull))(tsplus_module_13.chainPar(([shardConfig, key]) => tsplus_module_11.mapEffect((c) => tsplus_module_9.Shard.make([c.id, c.totalCount]))(tsplus_module_10.tap(() => limiter.maybeWait(`gateway.sharder.${key}`, millis(config.identifyRateLimit[0]), config.identifyRateLimit[1]))(shardConfig)))(tsplus_module_12.groupBy((c) => c.id % c.concurrency)(tsplus_module_3.map((config) => ({
|
|
41
|
+
...config,
|
|
42
|
+
url: gateway.url,
|
|
43
|
+
concurrency: gateway.session_start_limit.max_concurrency,
|
|
44
|
+
}))(source))));
|
|
45
|
+
})(tsplus_module_7.bind("configs", ({ gateway, config }) => configs(config.shardCount ?? gateway.shards))(tsplus_module_7.structPar({
|
|
46
|
+
gateway: tsplus_module_7.catchAll(() => tsplus_module_7.succeed({
|
|
47
|
+
url: "wss://gateway.discord.gg/",
|
|
48
|
+
shards: 1,
|
|
49
|
+
session_start_limit: {
|
|
50
|
+
total: 0,
|
|
51
|
+
remaining: 0,
|
|
52
|
+
reset_after: 0,
|
|
53
|
+
max_concurrency: 1,
|
|
54
|
+
},
|
|
55
|
+
}))(tsplus_module_7.flatMap((r) => r.json)(tsplus_module_14.Rest.rest
|
|
56
|
+
.getGatewayBot())),
|
|
57
|
+
config: tsplus_module_14.Config.gateway,
|
|
58
|
+
limiter: tsplus_module_7.service(tsplus_module_14.RateLimitStore.RateLimiter),
|
|
59
|
+
})));
|
|
60
|
+
export const spawn = tsplus_module_13.chainPar((shard) => tsplus_module_16.merge(tsplus_module_15.drain(tsplus_module_1.fromEffect(shard.run)))(tsplus_module_8.of(shard)))(tsplus_module_17.unwrap(spawnEffect));
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/DiscordGateway/Sharder/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,MAAM,OAAO,GAAG,CAAC,UAAkB,EAAE,EAAE,qBAE7B,KAAK;IACX,MAAM,OAAO,GAAG,CAAC,YAAoB,EAAE,EAAE,CACvC,wBA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="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="ws" />
|
|
3
|
+
import { Ref, EffectSource } from "dfx/common";
|
|
4
|
+
import WebSocket from "isomorphic-ws";
|
|
5
|
+
export declare const Reconnect: unique symbol;
|
|
6
|
+
export type Reconnect = typeof Reconnect;
|
|
7
|
+
export type Message = string | Buffer | ArrayBuffer | Reconnect;
|
|
8
|
+
export declare class WebSocketError {
|
|
9
|
+
readonly reason: unknown;
|
|
10
|
+
readonly _tag = "WebSocketError";
|
|
11
|
+
constructor(reason: unknown);
|
|
12
|
+
}
|
|
13
|
+
export declare class WebSocketCloseError {
|
|
14
|
+
readonly code: number;
|
|
15
|
+
readonly reason: string;
|
|
16
|
+
readonly _tag = "WebSocketCloseError";
|
|
17
|
+
constructor(code: number, reason: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class WebSocketWriteError {
|
|
20
|
+
readonly reason: Error;
|
|
21
|
+
readonly _tag = "WebSocketWriteError";
|
|
22
|
+
constructor(reason: Error);
|
|
23
|
+
}
|
|
24
|
+
export declare const make: (url: Ref<string>, options?: WebSocket.ClientOptions) => import("../../common.js").Effect<import("../../Log/index.js").Log, never, {
|
|
25
|
+
source: import("callbag-effect-ts/Source").EffectSource<never, WebSocketError | WebSocketCloseError | WebSocketWriteError, WebSocket.RawData>;
|
|
26
|
+
sink: import("callbag-effect-ts/Sink").EffectSink<never, never, never, Message>;
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@effect/io/Effect";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Ref";
|
|
3
|
+
import * as tsplus_module_3 from "callbag-effect-ts/Source/async";
|
|
4
|
+
import * as tsplus_module_4 from "callbag-effect-ts/Source/unwrap";
|
|
5
|
+
import * as tsplus_module_5 from "callbag-effect-ts/Source/tap";
|
|
6
|
+
import * as tsplus_module_6 from "callbag-effect-ts/Source/drain";
|
|
7
|
+
import * as tsplus_module_7 from "dfx/common";
|
|
8
|
+
import * as tsplus_module_8 from "@effect/io/Schedule";
|
|
9
|
+
import * as tsplus_module_9 from "callbag-effect-ts/Source/merge";
|
|
10
|
+
import * as tsplus_module_10 from "callbag-effect-ts/Source/unwrapScope";
|
|
11
|
+
import * as tsplus_module_11 from "callbag-effect-ts/Source/retry";
|
|
12
|
+
import WebSocket from "isomorphic-ws";
|
|
13
|
+
export const Reconnect = Symbol();
|
|
14
|
+
const socket = (urlRef, options) => tsplus_module_1.acquireRelease(tsplus_module_1.map(url => new WebSocket(url, options))(tsplus_module_2.get(urlRef)), (ws) => tsplus_module_1.sync(() => {
|
|
15
|
+
ws.close();
|
|
16
|
+
ws.removeAllListeners();
|
|
17
|
+
}));
|
|
18
|
+
export class WebSocketError {
|
|
19
|
+
reason;
|
|
20
|
+
_tag = "WebSocketError";
|
|
21
|
+
constructor(reason) {
|
|
22
|
+
this.reason = reason;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class WebSocketCloseError {
|
|
26
|
+
code;
|
|
27
|
+
reason;
|
|
28
|
+
_tag = "WebSocketCloseError";
|
|
29
|
+
constructor(code, reason) {
|
|
30
|
+
this.code = code;
|
|
31
|
+
this.reason = reason;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const recv = (ws) => tsplus_module_3.async((emit) => {
|
|
35
|
+
ws.on("message", (message) => {
|
|
36
|
+
emit.data(message);
|
|
37
|
+
});
|
|
38
|
+
ws.on("error", (cause) => {
|
|
39
|
+
emit.fail(new WebSocketError(cause));
|
|
40
|
+
});
|
|
41
|
+
ws.on("close", (code, reason) => {
|
|
42
|
+
emit.fail(new WebSocketCloseError(code, reason.toString("utf8")));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
export class WebSocketWriteError {
|
|
46
|
+
reason;
|
|
47
|
+
_tag = "WebSocketWriteError";
|
|
48
|
+
constructor(reason) {
|
|
49
|
+
this.reason = reason;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const send = (ws, out) => tsplus_module_1.map(log => tsplus_module_6.drain(tsplus_module_5.tap((data) => tsplus_module_1.async((resume) => {
|
|
53
|
+
if (data === Reconnect) {
|
|
54
|
+
ws.close(1012, "reconnecting");
|
|
55
|
+
resume(tsplus_module_1.unit());
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
ws.send(data, (err) => {
|
|
59
|
+
resume(err
|
|
60
|
+
? tsplus_module_1.fail(new WebSocketWriteError(err))
|
|
61
|
+
: tsplus_module_1.unit());
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}))(tsplus_module_5.tap((p) => log.debug("WS", "send", p))(tsplus_module_4.unwrap(tsplus_module_1.map(() => out)(tsplus_module_1.async((resume) => {
|
|
65
|
+
if (ws.readyState & ws.OPEN) {
|
|
66
|
+
resume(tsplus_module_1.unit());
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
ws.once("open", () => {
|
|
70
|
+
resume(tsplus_module_1.unit());
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
})))))))(tsplus_module_1.service(tsplus_module_7.Log.Log));
|
|
74
|
+
export const make = (url, options) => (() => {
|
|
75
|
+
const [sink, outbound] = tsplus_module_3.asyncSink();
|
|
76
|
+
return tsplus_module_1.map(log => {
|
|
77
|
+
const withLog = tsplus_module_1.provideService(tsplus_module_7.Log.Log)(log);
|
|
78
|
+
const source = tsplus_module_11.retry(tsplus_module_8.recurWhile((e) => e._tag === "WebSocketCloseError" && e.code === 1012))(tsplus_module_10.unwrapScope(tsplus_module_1.flatMap(ws => tsplus_module_1.map(sendEffect => tsplus_module_9.merge(sendEffect)(recv(ws)))(withLog(send(ws, outbound))))(socket(url, options))));
|
|
79
|
+
return { source, sink };
|
|
80
|
+
})(tsplus_module_1.service(tsplus_module_7.Log.Log));
|
|
81
|
+
})();
|
|
82
|
+
//# sourceMappingURL=index.js.map
|