dfx 0.0.2 → 0.0.5
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/DiscordREST/types.d.ts +7 -0
- package/DiscordShard/commands.d.ts +7 -0
- package/DiscordShard/commands.js +38 -0
- package/DiscordShard/commands.js.map +1 -0
- package/DiscordShard/commands.ts +40 -0
- package/DiscordShard/heartbeats.d.ts +7 -0
- package/DiscordShard/heartbeats.js +33 -0
- package/DiscordShard/heartbeats.js.map +1 -0
- package/DiscordShard/heartbeats.ts +70 -0
- package/DiscordShard/identify.d.ts +16 -0
- package/DiscordShard/identify.js +35 -0
- package/DiscordShard/identify.js.map +1 -0
- package/DiscordShard/identify.ts +76 -0
- package/DiscordShard/index.d.ts +32 -0
- package/DiscordShard/index.js +60 -0
- package/DiscordShard/index.js.map +1 -0
- package/DiscordShard/index.ts +110 -0
- package/DiscordShard/invalidSession.d.ts +7 -0
- package/DiscordShard/invalidSession.js +17 -0
- package/DiscordShard/invalidSession.js.map +1 -0
- package/DiscordShard/invalidSession.ts +25 -0
- package/DiscordShard/utils.d.ts +9 -0
- package/DiscordShard/utils.js +24 -0
- package/DiscordShard/utils.js.map +1 -0
- package/DiscordShard/utils.ts +47 -0
- package/DiscordWS/index.d.ts +32 -0
- package/DiscordWS/index.js +35 -0
- package/DiscordWS/index.js.map +1 -1
- package/DiscordWS/index.ts +79 -0
- package/Log/index.d.ts +12 -0
- package/Log/index.js +19 -0
- package/Log/index.js.map +1 -0
- package/Log/index.ts +20 -0
- package/WS/index.d.ts +32 -0
- package/WS/index.js +12 -13
- package/WS/index.js.map +1 -1
- package/WS/index.ts +19 -27
- package/bot.d.ts +1 -0
- package/bot.js +33 -0
- package/bot.js.map +1 -0
- package/bot.ts +51 -0
- package/mod.d.ts +3 -0
- package/mod.js +5 -7
- package/mod.js.map +1 -1
- package/mod.ts +6 -22
- package/package.json +22 -3
- package/types.d.ts +3584 -0
- package/discord-api-docs/ci/checkLinks.ts +0 -177
- package/discord-api-docs/index.js +0 -1
- package/websocket.js +0 -11
- package/websocket.js.map +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GatewayPayload, Heartbeat, Identify, RequestGuildMember, Resume, UpdatePresence, UpdateVoiceState } from "../types";
|
|
2
|
+
export declare const heartbeat: (d: Heartbeat) => GatewayPayload;
|
|
3
|
+
export declare const identify: (d: Identify) => GatewayPayload;
|
|
4
|
+
export declare const resume: (d: Resume) => GatewayPayload;
|
|
5
|
+
export declare const requestGuildMembers: (d: RequestGuildMember) => GatewayPayload;
|
|
6
|
+
export declare const voiceStateUpdate: (d: UpdateVoiceState) => GatewayPayload;
|
|
7
|
+
export declare const presenceUpdate: (d: UpdatePresence) => GatewayPayload;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.presenceUpdate = exports.voiceStateUpdate = exports.requestGuildMembers = exports.resume = exports.identify = exports.heartbeat = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
6
|
+
const fileName_1 = "DiscordShard/commands.ts";
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
const heartbeat = (d) => ({
|
|
9
|
+
op: types_1.GatewayOpcode.HEARTBEAT,
|
|
10
|
+
d,
|
|
11
|
+
});
|
|
12
|
+
exports.heartbeat = heartbeat;
|
|
13
|
+
const identify = (d) => ({
|
|
14
|
+
op: types_1.GatewayOpcode.IDENTIFY,
|
|
15
|
+
d,
|
|
16
|
+
});
|
|
17
|
+
exports.identify = identify;
|
|
18
|
+
const resume = (d) => ({
|
|
19
|
+
op: types_1.GatewayOpcode.RESUME,
|
|
20
|
+
d,
|
|
21
|
+
});
|
|
22
|
+
exports.resume = resume;
|
|
23
|
+
const requestGuildMembers = (d) => ({
|
|
24
|
+
op: types_1.GatewayOpcode.REQUEST_GUILD_MEMBERS,
|
|
25
|
+
d,
|
|
26
|
+
});
|
|
27
|
+
exports.requestGuildMembers = requestGuildMembers;
|
|
28
|
+
const voiceStateUpdate = (d) => ({
|
|
29
|
+
op: types_1.GatewayOpcode.VOICE_STATE_UPDATE,
|
|
30
|
+
d,
|
|
31
|
+
});
|
|
32
|
+
exports.voiceStateUpdate = voiceStateUpdate;
|
|
33
|
+
const presenceUpdate = (d) => ({
|
|
34
|
+
op: types_1.GatewayOpcode.PRESENCE_UPDATE,
|
|
35
|
+
d,
|
|
36
|
+
});
|
|
37
|
+
exports.presenceUpdate = presenceUpdate;
|
|
38
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["commands.ts"],"names":[],"mappings":";;;;;;AAAA,oCASiB;AAEV,MAAM,SAAS,GAAG,CAAC,CAAY,EAAkB,EAAE,CAAC,CAAC;IAC1D,EAAE,EAAE,qBAAa,CAAC,SAAS;IAC3B,CAAC;CACF,CAAC,CAAA;AAHW,QAAA,SAAS,aAGpB;AAEK,MAAM,QAAQ,GAAG,CAAC,CAAW,EAAkB,EAAE,CAAC,CAAC;IACxD,EAAE,EAAE,qBAAa,CAAC,QAAQ;IAC1B,CAAC;CACF,CAAC,CAAA;AAHW,QAAA,QAAQ,YAGnB;AAEK,MAAM,MAAM,GAAG,CAAC,CAAS,EAAkB,EAAE,CAAC,CAAC;IACpD,EAAE,EAAE,qBAAa,CAAC,MAAM;IACxB,CAAC;CACF,CAAC,CAAA;AAHW,QAAA,MAAM,UAGjB;AAEK,MAAM,mBAAmB,GAAG,CAAC,CAAqB,EAAkB,EAAE,CAAC,CAAC;IAC7E,EAAE,EAAE,qBAAa,CAAC,qBAAqB;IACvC,CAAC;CACF,CAAC,CAAA;AAHW,QAAA,mBAAmB,uBAG9B;AAEK,MAAM,gBAAgB,GAAG,CAAC,CAAmB,EAAkB,EAAE,CAAC,CAAC;IACxE,EAAE,EAAE,qBAAa,CAAC,kBAAkB;IACpC,CAAC;CACF,CAAC,CAAA;AAHW,QAAA,gBAAgB,oBAG3B;AAEK,MAAM,cAAc,GAAG,CAAC,CAAiB,EAAkB,EAAE,CAAC,CAAC;IACpE,EAAE,EAAE,qBAAa,CAAC,eAAe;IACjC,CAAC;CACF,CAAC,CAAA;AAHW,QAAA,cAAc,kBAGzB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GatewayOpcode,
|
|
3
|
+
GatewayPayload,
|
|
4
|
+
Heartbeat,
|
|
5
|
+
Identify,
|
|
6
|
+
RequestGuildMember,
|
|
7
|
+
Resume,
|
|
8
|
+
UpdatePresence,
|
|
9
|
+
UpdateVoiceState,
|
|
10
|
+
} from "../types"
|
|
11
|
+
|
|
12
|
+
export const heartbeat = (d: Heartbeat): GatewayPayload => ({
|
|
13
|
+
op: GatewayOpcode.HEARTBEAT,
|
|
14
|
+
d,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const identify = (d: Identify): GatewayPayload => ({
|
|
18
|
+
op: GatewayOpcode.IDENTIFY,
|
|
19
|
+
d,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export const resume = (d: Resume): GatewayPayload => ({
|
|
23
|
+
op: GatewayOpcode.RESUME,
|
|
24
|
+
d,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const requestGuildMembers = (d: RequestGuildMember): GatewayPayload => ({
|
|
28
|
+
op: GatewayOpcode.REQUEST_GUILD_MEMBERS,
|
|
29
|
+
d,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export const voiceStateUpdate = (d: UpdateVoiceState): GatewayPayload => ({
|
|
33
|
+
op: GatewayOpcode.VOICE_STATE_UPDATE,
|
|
34
|
+
d,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export const presenceUpdate = (d: UpdatePresence): GatewayPayload => ({
|
|
38
|
+
op: GatewayOpcode.PRESENCE_UPDATE,
|
|
39
|
+
d,
|
|
40
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream";
|
|
2
|
+
import * as H from "@effect-ts/core/Effect/Hub";
|
|
3
|
+
import * as R from "@effect-ts/core/Effect/Ref";
|
|
4
|
+
import * as O from "@effect-ts/core/Option";
|
|
5
|
+
import * as DWS from "../DiscordWS";
|
|
6
|
+
import { GatewayPayload } from "../types";
|
|
7
|
+
export declare const fromHub: (hub: H.Hub<GatewayPayload<any>>, seqRef: R.Ref<O.Option<number>>) => S.Stream<import("@effect-ts/system/Has").Has<import("@effect-ts/system/Clock").Clock>, never, DWS.Message>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromHub = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
6
|
+
const fileName_1 = "DiscordShard/heartbeats.ts";
|
|
7
|
+
const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
|
|
8
|
+
const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
|
|
9
|
+
const R = tslib_1.__importStar(require("@effect-ts/core/Effect/Ref"));
|
|
10
|
+
const Function_1 = require("@effect-ts/core/Function");
|
|
11
|
+
const O = tslib_1.__importStar(require("@effect-ts/core/Option"));
|
|
12
|
+
const types_1 = require("../types");
|
|
13
|
+
const WS_1 = require("../WS");
|
|
14
|
+
const Commands = tslib_1.__importStar(require("./commands"));
|
|
15
|
+
const Utils = tslib_1.__importStar(require("./utils"));
|
|
16
|
+
const send = (ref, seqRef) => (T.tap_(T.map_(R.get(seqRef), (o) => Commands.heartbeat(O.toNullable(o)), fileName_1 + ":16:10"), () => R.set_(ref, false), fileName_1 + ":17:10"));
|
|
17
|
+
const maybeSend = (ref, seqRef) => (T.chain_(R.get(ref), (acked) => acked ? send(ref, seqRef) : T.succeed(WS_1.Reconnect, fileName_1 + ":25:46"), fileName_1 + ":23:12"));
|
|
18
|
+
const fromHub = (hub, seqRef) => (S.unwrap(T.map_(R.makeRef(true), (ackedRef) => {
|
|
19
|
+
const heartbeats = (
|
|
20
|
+
// Map to gateway message depending on ack state
|
|
21
|
+
S.mapEffect_(S.chainParSwitch_(
|
|
22
|
+
// Reset ack state for each hello
|
|
23
|
+
S.tap_(Utils.opCode(hub)(types_1.GatewayOpcode.HELLO), () => R.set_(ackedRef, true)), (p) => {
|
|
24
|
+
const initial = p.d.heartbeat_interval * Math.random();
|
|
25
|
+
return S.merge_(
|
|
26
|
+
// First random heartbeat
|
|
27
|
+
S.fromEffect(T.sleep(initial, fileName_1 + ":47:33")), (S.chain_(S.fromEffect(T.sleep(initial, fileName_1 + ":50:35")), () => S.repeatEffect(T.sleep(p.d.heartbeat_interval, fileName_1 + ":51:51")))));
|
|
28
|
+
}, 1), () => maybeSend(ackedRef, seqRef)));
|
|
29
|
+
const acks = (S.drain(S.tap_(Utils.opCode(hub)(types_1.GatewayOpcode.HEARTBEAT_ACK), () => R.set_(ackedRef, true))));
|
|
30
|
+
return S.merge_(heartbeats, acks);
|
|
31
|
+
}, fileName_1 + ":36:10")));
|
|
32
|
+
exports.fromHub = fromHub;
|
|
33
|
+
//# sourceMappingURL=heartbeats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeats.js","sourceRoot":"","sources":["heartbeats.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAE/D,sEAA+C;AAC/C,uDAA+C;AAC/C,kEAA2C;AAE3C,oCAAoE;AACpE,8BAAiC;AACjC,6DAAsC;AACtC,uDAAgC;AAEhC,MAAM,IAAI,GAAG,CAAC,GAAmB,EAAE,MAA+B,EAAE,EAAE,EAIlE,CAAC,MADD,CAAC,MADD,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EACP,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,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,CAAC,kBAAkB,wBAAC,CAAC,GAEjE,CAAA;IACH,CAAC,EAAE,CAAC,GAGQ,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,EAC9C,CAAA;IAED,MAAM,IAAI,IAGR,CAAC,CAAC,KAAK,CADP,CAAC,MADD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,qBAAa,CAAC,aAAa,CAAC,EACxC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,GAEnC,CAAA;IAED,OAAO,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACnC,CAAC,0BAGF,CAAA;AAzCU,QAAA,OAAO,WAyCjB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect"
|
|
2
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream"
|
|
3
|
+
import * as H from "@effect-ts/core/Effect/Hub"
|
|
4
|
+
import * as R from "@effect-ts/core/Effect/Ref"
|
|
5
|
+
import { pipe } from "@effect-ts/core/Function"
|
|
6
|
+
import * as O from "@effect-ts/core/Option"
|
|
7
|
+
import * as DWS from "../DiscordWS"
|
|
8
|
+
import { GatewayOpcode, GatewayPayload, HelloEvent } from "../types"
|
|
9
|
+
import { Reconnect } from "../WS"
|
|
10
|
+
import * as Commands from "./commands"
|
|
11
|
+
import * as Utils from "./utils"
|
|
12
|
+
|
|
13
|
+
const send = (ref: R.Ref<boolean>, seqRef: R.Ref<O.Option<number>>) =>
|
|
14
|
+
pipe(
|
|
15
|
+
R.get(seqRef),
|
|
16
|
+
T.map((o) => Commands.heartbeat(O.toNullable(o))),
|
|
17
|
+
T.tap(() => R.set_(ref, false))
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const maybeSend = (ref: R.Ref<boolean>, seqRef: R.Ref<O.Option<number>>) =>
|
|
21
|
+
pipe(
|
|
22
|
+
R.get(ref),
|
|
23
|
+
T.chain(
|
|
24
|
+
(acked): T.UIO<DWS.Message> =>
|
|
25
|
+
acked ? send(ref, seqRef) : T.succeed(Reconnect)
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export const fromHub = (
|
|
30
|
+
hub: H.Hub<GatewayPayload>,
|
|
31
|
+
seqRef: R.Ref<O.Option<number>>
|
|
32
|
+
) =>
|
|
33
|
+
pipe(
|
|
34
|
+
R.makeRef(true),
|
|
35
|
+
|
|
36
|
+
T.map((ackedRef) => {
|
|
37
|
+
const heartbeats = pipe(
|
|
38
|
+
Utils.opCode(hub)<HelloEvent>(GatewayOpcode.HELLO),
|
|
39
|
+
|
|
40
|
+
// Reset ack state for each hello
|
|
41
|
+
S.tap(() => R.set_(ackedRef, true)),
|
|
42
|
+
|
|
43
|
+
S.chainParSwitch((p) => {
|
|
44
|
+
const initial = p.d!.heartbeat_interval * Math.random()
|
|
45
|
+
return S.merge_(
|
|
46
|
+
// First random heartbeat
|
|
47
|
+
S.fromEffect(T.sleep(initial)),
|
|
48
|
+
// Repeated heartbeat
|
|
49
|
+
pipe(
|
|
50
|
+
S.fromEffect(T.sleep(initial)),
|
|
51
|
+
S.chain(() => S.repeatEffect(T.sleep(p.d!.heartbeat_interval)))
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
}, 1),
|
|
55
|
+
|
|
56
|
+
// Map to gateway message depending on ack state
|
|
57
|
+
S.mapEffect(() => maybeSend(ackedRef, seqRef))
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const acks = pipe(
|
|
61
|
+
Utils.opCode(hub)(GatewayOpcode.HEARTBEAT_ACK),
|
|
62
|
+
S.tap(() => R.set_(ackedRef, true)),
|
|
63
|
+
S.drain
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return S.merge_(heartbeats, acks)
|
|
67
|
+
}),
|
|
68
|
+
|
|
69
|
+
S.unwrap
|
|
70
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream";
|
|
2
|
+
import * as H from "@effect-ts/core/Effect/Hub";
|
|
3
|
+
import * as R from "@effect-ts/core/Effect/Ref";
|
|
4
|
+
import * as O from "@effect-ts/core/Option";
|
|
5
|
+
import { GatewayPayload, ReadyEvent, UpdatePresence } from "../types";
|
|
6
|
+
export interface Options {
|
|
7
|
+
token: string;
|
|
8
|
+
intents: number;
|
|
9
|
+
shard: [number, number];
|
|
10
|
+
presence?: UpdatePresence;
|
|
11
|
+
}
|
|
12
|
+
export interface Requirements {
|
|
13
|
+
latestReady: R.Ref<O.Option<ReadyEvent>>;
|
|
14
|
+
latestSequence: R.Ref<O.Option<number>>;
|
|
15
|
+
}
|
|
16
|
+
export declare const fromHub: (hub: H.Hub<GatewayPayload<any>>, { latestReady, latestSequence, ...opts }: Options & Requirements) => S.Stream<unknown, never, GatewayPayload<any>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromHub = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
6
|
+
const fileName_1 = "DiscordShard/identify.ts";
|
|
7
|
+
const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
|
|
8
|
+
const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
|
|
9
|
+
const R = tslib_1.__importStar(require("@effect-ts/core/Effect/Ref"));
|
|
10
|
+
const Function_1 = require("@effect-ts/core/Function");
|
|
11
|
+
const O = tslib_1.__importStar(require("@effect-ts/core/Option"));
|
|
12
|
+
const OS = tslib_1.__importStar(require("os"));
|
|
13
|
+
const types_1 = require("../types");
|
|
14
|
+
const Commands = tslib_1.__importStar(require("./commands"));
|
|
15
|
+
const Utils = tslib_1.__importStar(require("./utils"));
|
|
16
|
+
const identify = ({ token, intents, shard, presence }) => Commands.identify({
|
|
17
|
+
token,
|
|
18
|
+
intents,
|
|
19
|
+
properties: {
|
|
20
|
+
$os: OS.platform(),
|
|
21
|
+
$browser: "dfx",
|
|
22
|
+
$device: "dfx",
|
|
23
|
+
},
|
|
24
|
+
shard,
|
|
25
|
+
presence,
|
|
26
|
+
});
|
|
27
|
+
const resume = (token, ready, seq) => Commands.resume({
|
|
28
|
+
token,
|
|
29
|
+
session_id: ready.session_id,
|
|
30
|
+
seq,
|
|
31
|
+
});
|
|
32
|
+
const identifyOrResume = (opts, ready, seq) => (T.map_(T.zip_(R.get(ready), R.get(seq), fileName_1 + ":57:10"), ({ tuple }) => (O.fold_(O.zip_(...tuple), () => identify(opts), ({ tuple }) => resume(opts.token, ...tuple))), fileName_1 + ":58:10"));
|
|
33
|
+
const fromHub = (hub, { latestReady, latestSequence, ...opts }) => (S.mapEffect_(Utils.opCode(hub)(types_1.GatewayOpcode.HELLO), () => identifyOrResume(opts, latestReady, latestSequence)));
|
|
34
|
+
exports.fromHub = fromHub;
|
|
35
|
+
//# sourceMappingURL=identify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identify.js","sourceRoot":"","sources":["identify.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAE/D,sEAA+C;AAC/C,uDAA+C;AAC/C,kEAA2C;AAC3C,+CAAwB;AACxB,oCAMiB;AACjB,6DAAsC;AACtC,uDAAgC;AAchC,MAAM,QAAQ,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAW,EAAE,EAAE,CAChE,QAAQ,CAAC,QAAQ,CAAC;IAChB,KAAK;IACL,OAAO;IACP,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,CAAC,QAAQ,EAAE;QAClB,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,KAAK;KACf;IACD,KAAK;IACL,QAAQ;CACT,CAAC,CAAA;AAEJ,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,KAAiB,EAAE,GAAW,EAAE,EAAE,CAC/D,QAAQ,CAAC,MAAM,CAAC;IACd,KAAK;IACL,UAAU,EAAE,KAAK,CAAC,UAAU;IAC5B,GAAG;CACJ,CAAC,CAAA;AAEJ,MAAM,gBAAgB,GAAG,CACvB,IAAa,EACb,KAAkC,EAClC,GAA4B,EAC5B,EAAE,EAIA,CAAC,MADD,CAAC,MADD,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EACN,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,0BACV,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAGhB,CAAC,OADD,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,EAEd,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EACpB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,EAE9C,yBAEJ,CAAA;AAEI,MAAM,OAAO,GAAG,CACrB,GAA0B,EAC1B,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,IAAI,EAA0B,EAChE,EAAE,EAGA,CAAC,YADD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAa,qBAAa,CAAC,KAAK,CAAC,EACtC,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,EACtE,CAAA;AAPU,QAAA,OAAO,WAOjB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect"
|
|
2
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream"
|
|
3
|
+
import * as H from "@effect-ts/core/Effect/Hub"
|
|
4
|
+
import * as R from "@effect-ts/core/Effect/Ref"
|
|
5
|
+
import { pipe } from "@effect-ts/core/Function"
|
|
6
|
+
import * as O from "@effect-ts/core/Option"
|
|
7
|
+
import * as OS from "os"
|
|
8
|
+
import {
|
|
9
|
+
GatewayOpcode,
|
|
10
|
+
GatewayPayload,
|
|
11
|
+
HelloEvent,
|
|
12
|
+
ReadyEvent,
|
|
13
|
+
UpdatePresence,
|
|
14
|
+
} from "../types"
|
|
15
|
+
import * as Commands from "./commands"
|
|
16
|
+
import * as Utils from "./utils"
|
|
17
|
+
|
|
18
|
+
export interface Options {
|
|
19
|
+
token: string
|
|
20
|
+
intents: number
|
|
21
|
+
shard: [number, number]
|
|
22
|
+
presence?: UpdatePresence
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Requirements {
|
|
26
|
+
latestReady: R.Ref<O.Option<ReadyEvent>>
|
|
27
|
+
latestSequence: R.Ref<O.Option<number>>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const identify = ({ token, intents, shard, presence }: Options) =>
|
|
31
|
+
Commands.identify({
|
|
32
|
+
token,
|
|
33
|
+
intents,
|
|
34
|
+
properties: {
|
|
35
|
+
$os: OS.platform(),
|
|
36
|
+
$browser: "dfx",
|
|
37
|
+
$device: "dfx",
|
|
38
|
+
},
|
|
39
|
+
shard,
|
|
40
|
+
presence,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const resume = (token: string, ready: ReadyEvent, seq: number) =>
|
|
44
|
+
Commands.resume({
|
|
45
|
+
token,
|
|
46
|
+
session_id: ready.session_id,
|
|
47
|
+
seq,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const identifyOrResume = (
|
|
51
|
+
opts: Options,
|
|
52
|
+
ready: R.Ref<O.Option<ReadyEvent>>,
|
|
53
|
+
seq: R.Ref<O.Option<number>>
|
|
54
|
+
) =>
|
|
55
|
+
pipe(
|
|
56
|
+
R.get(ready),
|
|
57
|
+
T.zip(R.get(seq)),
|
|
58
|
+
T.map(({ tuple }) =>
|
|
59
|
+
pipe(
|
|
60
|
+
O.zip_(...tuple),
|
|
61
|
+
O.fold(
|
|
62
|
+
() => identify(opts),
|
|
63
|
+
({ tuple }) => resume(opts.token, ...tuple)
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
export const fromHub = (
|
|
70
|
+
hub: H.Hub<GatewayPayload>,
|
|
71
|
+
{ latestReady, latestSequence, ...opts }: Options & Requirements
|
|
72
|
+
) =>
|
|
73
|
+
pipe(
|
|
74
|
+
Utils.opCode(hub)<HelloEvent>(GatewayOpcode.HELLO),
|
|
75
|
+
S.mapEffect(() => identifyOrResume(opts, latestReady, latestSequence))
|
|
76
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect";
|
|
2
|
+
import * as L from "@effect-ts/core/Effect/Layer";
|
|
3
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream";
|
|
4
|
+
import * as H from "@effect-ts/core/Effect/Hub";
|
|
5
|
+
import * as M from "@effect-ts/core/Effect/Managed";
|
|
6
|
+
import * as DWS from "../DiscordWS";
|
|
7
|
+
import { GatewayEvent, GatewayPayload } from "../types";
|
|
8
|
+
import * as Identify from "./identify";
|
|
9
|
+
declare const makeService: () => {
|
|
10
|
+
readonly _tag: "DiscordShardService";
|
|
11
|
+
readonly make: (opts: Identify.Options) => M.Managed<unknown, never, {
|
|
12
|
+
readonly run: T.RIO<import("@effect-ts/system/Has").Has<DWS.DiscordWS> & import("@effect-ts/system/Has").Has<import("../WS").WS> & import("@effect-ts/system/Clock").HasClock & import("@effect-ts/system/Has").Has<import("../Log").Log> & import("@effect-ts/system/Has").Has<import("@effect-ts/system/Clock").Clock>, void>;
|
|
13
|
+
readonly raw: H.Hub<GatewayPayload<any>>;
|
|
14
|
+
readonly dispatch: H.Hub<GatewayPayload<GatewayEvent>>;
|
|
15
|
+
readonly fromDispatch: <K extends keyof import("../types").GatewayEvents>(event: K) => S.Stream<unknown, never, import("../types").GatewayEvents[K]>;
|
|
16
|
+
readonly send: (p: GatewayPayload) => T.Effect<unknown, never, boolean>;
|
|
17
|
+
readonly reconnect: () => T.Effect<unknown, never, boolean>;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
export interface DiscordShard extends ReturnType<typeof makeService> {
|
|
21
|
+
}
|
|
22
|
+
export declare const DiscordShard: import("@effect-ts/system/Has").Tag<DiscordShard>;
|
|
23
|
+
export declare const LiveDiscordShard: L.Layer<{}, never, import("@effect-ts/system/Has").Has<DiscordShard>>;
|
|
24
|
+
export declare const make: (opts: Identify.Options) => M.Managed<import("@effect-ts/system/Has").Has<DiscordShard>, never, {
|
|
25
|
+
readonly run: T.RIO<import("@effect-ts/system/Has").Has<DWS.DiscordWS> & import("@effect-ts/system/Has").Has<import("../WS").WS> & import("@effect-ts/system/Clock").HasClock & import("@effect-ts/system/Has").Has<import("../Log").Log> & import("@effect-ts/system/Has").Has<import("@effect-ts/system/Clock").Clock>, void>;
|
|
26
|
+
readonly raw: H.Hub<GatewayPayload<any>>;
|
|
27
|
+
readonly dispatch: H.Hub<GatewayPayload<GatewayEvent>>;
|
|
28
|
+
readonly fromDispatch: <K extends keyof import("../types").GatewayEvents>(event: K) => S.Stream<unknown, never, import("../types").GatewayEvents[K]>;
|
|
29
|
+
readonly send: (p: GatewayPayload) => T.Effect<unknown, never, boolean>;
|
|
30
|
+
readonly reconnect: () => T.Effect<unknown, never, boolean>;
|
|
31
|
+
}>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.make = exports.LiveDiscordShard = exports.DiscordShard = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
6
|
+
const fileName_1 = "DiscordShard/index.ts";
|
|
7
|
+
const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
|
|
8
|
+
const L = tslib_1.__importStar(require("@effect-ts/core/Effect/Layer"));
|
|
9
|
+
const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
|
|
10
|
+
const H = tslib_1.__importStar(require("@effect-ts/core/Effect/Hub"));
|
|
11
|
+
const M = tslib_1.__importStar(require("@effect-ts/core/Effect/Managed"));
|
|
12
|
+
const Q = tslib_1.__importStar(require("@effect-ts/core/Effect/Queue"));
|
|
13
|
+
const Function_1 = require("@effect-ts/core/Function");
|
|
14
|
+
const Has_1 = require("@effect-ts/core/Has");
|
|
15
|
+
const O = tslib_1.__importStar(require("@effect-ts/core/Option"));
|
|
16
|
+
const DWS = tslib_1.__importStar(require("../DiscordWS"));
|
|
17
|
+
const types_1 = require("../types");
|
|
18
|
+
const WS_1 = require("../WS");
|
|
19
|
+
const Heartbeats = tslib_1.__importStar(require("./heartbeats"));
|
|
20
|
+
const Identify = tslib_1.__importStar(require("./identify"));
|
|
21
|
+
const Invalid = tslib_1.__importStar(require("./invalidSession"));
|
|
22
|
+
const Utils = tslib_1.__importStar(require("./utils"));
|
|
23
|
+
const makeImpl = (opts) => M.gen(function* (_) {
|
|
24
|
+
const outbound = yield* _(Q.makeUnbounded(), fileName_1 + ":27:30");
|
|
25
|
+
const [latestReady, updateLatestReady] = yield* _(Utils.latest((0, Function_1.flow)(O.fromPredicate((p) => p.op === types_1.GatewayOpcode.DISPATCH && p.t === "READY"), O.map((p) => p.d))), fileName_1 + ":29:54");
|
|
26
|
+
const [latestSequence, updateLatestSequence] = yield* _(Utils.latest((p) => O.fromNullable(p.s)), fileName_1 + ":40:60");
|
|
27
|
+
const hub = yield* _(H.makeUnbounded(), fileName_1 + ":44:25");
|
|
28
|
+
const publishToHub = (S.forEach_(updateLatestReady(updateLatestSequence(S.unwrap(DWS.open({
|
|
29
|
+
outgoing: S.fromQueue_(outbound),
|
|
30
|
+
})))), (p) => H.publish_(hub, p)));
|
|
31
|
+
const dispatch = (H.filterOutput_(hub, (p) => p.op === types_1.GatewayOpcode.DISPATCH));
|
|
32
|
+
const fromDispatch = Utils.fromDispatch(dispatch);
|
|
33
|
+
// heartbeats
|
|
34
|
+
const heartbeatEffects = (S.forEach_(Heartbeats.fromHub(hub, latestSequence), (p) => Q.offer_(outbound, p)));
|
|
35
|
+
// identify
|
|
36
|
+
const identifyEffects = (S.forEach_(Identify.fromHub(hub, {
|
|
37
|
+
...opts,
|
|
38
|
+
latestSequence,
|
|
39
|
+
latestReady,
|
|
40
|
+
}), (p) => Q.offer_(outbound, p)));
|
|
41
|
+
// invalid session
|
|
42
|
+
const invalidEffects = (S.forEach_(Invalid.fromHub(hub, latestReady), (p) => Q.offer_(outbound, p)));
|
|
43
|
+
return {
|
|
44
|
+
run: (T.ignore(T.zipPar(invalidEffects, fileName_1 + ":88:17")(T.zipPar(identifyEffects, fileName_1 + ":87:17")(T.zipPar(heartbeatEffects, fileName_1 + ":86:17")(publishToHub))), fileName_1 + ":89:17")),
|
|
45
|
+
raw: hub,
|
|
46
|
+
dispatch,
|
|
47
|
+
fromDispatch,
|
|
48
|
+
send: (p) => Q.offer_(outbound, p),
|
|
49
|
+
reconnect: () => Q.offer_(outbound, WS_1.Reconnect),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
const makeService = () => ({
|
|
53
|
+
_tag: "DiscordShardService",
|
|
54
|
+
make: makeImpl,
|
|
55
|
+
});
|
|
56
|
+
exports.DiscordShard = (0, Has_1.tag)();
|
|
57
|
+
exports.LiveDiscordShard = L.fromValue(exports.DiscordShard)(makeService());
|
|
58
|
+
const make = (opts) => M.accessServiceM(exports.DiscordShard)(({ make }) => make(opts));
|
|
59
|
+
exports.make = make;
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,wEAAiD;AACjD,sFAA+D;AAE/D,sEAA+C;AAC/C,0EAAmD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CAAC;QAClD,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAS,CAAC;KACtC,CAAA;AACZ,CAAC,CAAC,CAAA;AAEJ,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,CAAC;IACC,IAAI,EAAE,qBAAqB;IAC3B,IAAI,EAAE,QAAQ;CACL,CAAA,CAAA;AAGA,QAAA,YAAY,GAAG,IAAA,SAAG,GAAgB,CAAA;AAClC,QAAA,gBAAgB,GAAG,CAAC,CAAC,SAAS,CAAC,oBAAY,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;AAEjE,MAAM,IAAI,GAAG,CAAC,IAAsB,EAAE,EAAE,CAC7C,CAAC,CAAC,cAAc,CAAC,oBAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AAD7C,QAAA,IAAI,QACyC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect"
|
|
2
|
+
import * as L from "@effect-ts/core/Effect/Layer"
|
|
3
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream"
|
|
4
|
+
import * as SK from "@effect-ts/core/Effect/Experimental/Stream/Sink"
|
|
5
|
+
import * as H from "@effect-ts/core/Effect/Hub"
|
|
6
|
+
import * as M from "@effect-ts/core/Effect/Managed"
|
|
7
|
+
import * as Q from "@effect-ts/core/Effect/Queue"
|
|
8
|
+
import { flow, pipe } from "@effect-ts/core/Function"
|
|
9
|
+
import { tag } from "@effect-ts/core/Has"
|
|
10
|
+
import * as O from "@effect-ts/core/Option"
|
|
11
|
+
import { _A } from "@effect-ts/core/Utils"
|
|
12
|
+
import * as DWS from "../DiscordWS"
|
|
13
|
+
import {
|
|
14
|
+
GatewayEvent,
|
|
15
|
+
GatewayOpcode,
|
|
16
|
+
GatewayPayload,
|
|
17
|
+
ReadyEvent,
|
|
18
|
+
} from "../types"
|
|
19
|
+
import { Reconnect } from "../WS"
|
|
20
|
+
import * as Heartbeats from "./heartbeats"
|
|
21
|
+
import * as Identify from "./identify"
|
|
22
|
+
import * as Invalid from "./invalidSession"
|
|
23
|
+
import * as Utils from "./utils"
|
|
24
|
+
|
|
25
|
+
const makeImpl = (opts: Identify.Options) =>
|
|
26
|
+
M.gen(function* (_) {
|
|
27
|
+
const outbound = yield* _(Q.makeUnbounded<DWS.Message>())
|
|
28
|
+
|
|
29
|
+
const [latestReady, updateLatestReady] = yield* _(
|
|
30
|
+
Utils.latest(
|
|
31
|
+
flow(
|
|
32
|
+
O.fromPredicate(
|
|
33
|
+
(p): p is GatewayPayload<ReadyEvent> =>
|
|
34
|
+
p.op === GatewayOpcode.DISPATCH && p.t === "READY"
|
|
35
|
+
),
|
|
36
|
+
O.map((p) => p.d!)
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
const [latestSequence, updateLatestSequence] = yield* _(
|
|
41
|
+
Utils.latest((p) => O.fromNullable(p.s))
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
const hub = yield* _(H.makeUnbounded<GatewayPayload>())
|
|
45
|
+
const publishToHub = pipe(
|
|
46
|
+
DWS.open({
|
|
47
|
+
outgoing: S.fromQueue_(outbound),
|
|
48
|
+
}),
|
|
49
|
+
S.unwrap,
|
|
50
|
+
updateLatestSequence,
|
|
51
|
+
updateLatestReady,
|
|
52
|
+
S.forEach((p) => H.publish_(hub, p))
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
const dispatch: H.Hub<GatewayPayload<GatewayEvent>> = pipe(
|
|
56
|
+
hub,
|
|
57
|
+
H.filterOutput((p) => p.op === GatewayOpcode.DISPATCH)
|
|
58
|
+
)
|
|
59
|
+
const fromDispatch = Utils.fromDispatch(dispatch)
|
|
60
|
+
|
|
61
|
+
// heartbeats
|
|
62
|
+
const heartbeatEffects = pipe(
|
|
63
|
+
Heartbeats.fromHub(hub, latestSequence),
|
|
64
|
+
S.forEach((p) => Q.offer_(outbound, p))
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
// identify
|
|
68
|
+
const identifyEffects = pipe(
|
|
69
|
+
Identify.fromHub(hub, {
|
|
70
|
+
...opts,
|
|
71
|
+
latestSequence,
|
|
72
|
+
latestReady,
|
|
73
|
+
}),
|
|
74
|
+
S.forEach((p) => Q.offer_(outbound, p))
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
// invalid session
|
|
78
|
+
const invalidEffects = pipe(
|
|
79
|
+
Invalid.fromHub(hub, latestReady),
|
|
80
|
+
S.forEach((p) => Q.offer_(outbound, p))
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
run: pipe(
|
|
85
|
+
publishToHub,
|
|
86
|
+
T.zipPar(heartbeatEffects),
|
|
87
|
+
T.zipPar(identifyEffects),
|
|
88
|
+
T.zipPar(invalidEffects),
|
|
89
|
+
T.ignore
|
|
90
|
+
),
|
|
91
|
+
raw: hub,
|
|
92
|
+
dispatch,
|
|
93
|
+
fromDispatch,
|
|
94
|
+
send: (p: GatewayPayload) => Q.offer_(outbound, p),
|
|
95
|
+
reconnect: () => Q.offer_(outbound, Reconnect),
|
|
96
|
+
} as const
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const makeService = () =>
|
|
100
|
+
({
|
|
101
|
+
_tag: "DiscordShardService",
|
|
102
|
+
make: makeImpl,
|
|
103
|
+
} as const)
|
|
104
|
+
|
|
105
|
+
export interface DiscordShard extends ReturnType<typeof makeService> {}
|
|
106
|
+
export const DiscordShard = tag<DiscordShard>()
|
|
107
|
+
export const LiveDiscordShard = L.fromValue(DiscordShard)(makeService())
|
|
108
|
+
|
|
109
|
+
export const make = (opts: Identify.Options) =>
|
|
110
|
+
M.accessServiceM(DiscordShard)(({ make }) => make(opts))
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream";
|
|
2
|
+
import * as H from "@effect-ts/core/Effect/Hub";
|
|
3
|
+
import * as R from "@effect-ts/core/Effect/Ref";
|
|
4
|
+
import * as O from "@effect-ts/core/Option";
|
|
5
|
+
import { Message } from "../DiscordWS";
|
|
6
|
+
import { GatewayPayload, ReadyEvent } from "../types";
|
|
7
|
+
export declare const fromHub: (hub: H.Hub<GatewayPayload<any>>, latestReady: R.Ref<O.Option<ReadyEvent>>) => S.Stream<unknown, never, Message>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromHub = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
6
|
+
const fileName_1 = "DiscordShard/invalidSession.ts";
|
|
7
|
+
const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
|
|
8
|
+
const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
|
|
9
|
+
const R = tslib_1.__importStar(require("@effect-ts/core/Effect/Ref"));
|
|
10
|
+
const Function_1 = require("@effect-ts/core/Function");
|
|
11
|
+
const O = tslib_1.__importStar(require("@effect-ts/core/Option"));
|
|
12
|
+
const types_1 = require("../types");
|
|
13
|
+
const WS_1 = require("../WS");
|
|
14
|
+
const Utils = tslib_1.__importStar(require("./utils"));
|
|
15
|
+
const fromHub = (hub, latestReady) => (S.map_(S.tap_(Utils.opCode(hub)(types_1.GatewayOpcode.INVALID_SESSION), (p) => (p.d ? T.unit : R.set_(latestReady, O.none))), () => WS_1.Reconnect));
|
|
16
|
+
exports.fromHub = fromHub;
|
|
17
|
+
//# sourceMappingURL=invalidSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalidSession.js","sourceRoot":"","sources":["invalidSession.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAE/D,sEAA+C;AAC/C,uDAA+C;AAC/C,kEAA2C;AAE3C,oCAKiB;AACjB,8BAAiC;AACjC,uDAAgC;AAEzB,MAAM,OAAO,GAAG,CACrB,GAA0B,EAC1B,WAAwC,EACxC,EAAE,EAIA,CAAC,MADD,CAAC,MADD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAsB,qBAAa,CAAC,eAAe,CAAC,EAC/D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GACnD,GAAY,EAAE,CAAC,cAAS,EAC/B,CAAA;AARU,QAAA,OAAO,WAQjB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect"
|
|
2
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream"
|
|
3
|
+
import * as H from "@effect-ts/core/Effect/Hub"
|
|
4
|
+
import * as R from "@effect-ts/core/Effect/Ref"
|
|
5
|
+
import { pipe } from "@effect-ts/core/Function"
|
|
6
|
+
import * as O from "@effect-ts/core/Option"
|
|
7
|
+
import { Message } from "../DiscordWS"
|
|
8
|
+
import {
|
|
9
|
+
GatewayOpcode,
|
|
10
|
+
GatewayPayload,
|
|
11
|
+
InvalidSessionEvent,
|
|
12
|
+
ReadyEvent,
|
|
13
|
+
} from "../types"
|
|
14
|
+
import { Reconnect } from "../WS"
|
|
15
|
+
import * as Utils from "./utils"
|
|
16
|
+
|
|
17
|
+
export const fromHub = (
|
|
18
|
+
hub: H.Hub<GatewayPayload>,
|
|
19
|
+
latestReady: R.Ref<O.Option<ReadyEvent>>
|
|
20
|
+
) =>
|
|
21
|
+
pipe(
|
|
22
|
+
Utils.opCode(hub)<InvalidSessionEvent>(GatewayOpcode.INVALID_SESSION),
|
|
23
|
+
S.tap((p) => (p.d ? T.unit : R.set_(latestReady, O.none))),
|
|
24
|
+
S.map((): Message => Reconnect)
|
|
25
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect";
|
|
2
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream";
|
|
3
|
+
import * as H from "@effect-ts/core/Effect/Hub";
|
|
4
|
+
import * as R from "@effect-ts/core/Effect/Ref";
|
|
5
|
+
import * as O from "@effect-ts/core/Option";
|
|
6
|
+
import { GatewayEvent, GatewayEvents, GatewayOpcode, GatewayPayload } from "../types";
|
|
7
|
+
export declare const opCode: (hub: H.Hub<GatewayPayload<any>>) => <T = any>(code: GatewayOpcode) => S.UIO<GatewayPayload<T>>;
|
|
8
|
+
export declare const latest: <T>(f: (p: GatewayPayload) => O.Option<T>) => T.Effect<unknown, never, readonly [R.Ref<O.Option<T>>, <R, E>(self: S.Stream<R, E, GatewayPayload<any>>) => S.Stream<R, E, GatewayPayload<any>>]>;
|
|
9
|
+
export declare const fromDispatch: (hub: H.Hub<GatewayPayload<GatewayEvent>>) => <K extends keyof GatewayEvents>(event: K) => S.Stream<unknown, never, GatewayEvents[K]>;
|