dfx 0.0.3 → 0.0.4
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/DiscordShard/commands.js +38 -0
- package/DiscordShard/commands.js.map +1 -0
- package/DiscordShard/commands.ts +40 -0
- package/DiscordShard/heartbeats.js +33 -0
- package/DiscordShard/heartbeats.js.map +1 -0
- package/DiscordShard/heartbeats.ts +70 -0
- package/DiscordShard/identify.js +35 -0
- package/DiscordShard/identify.js.map +1 -0
- package/DiscordShard/identify.ts +76 -0
- package/DiscordShard/index.js +60 -0
- package/DiscordShard/index.js.map +1 -0
- package/DiscordShard/index.ts +110 -0
- package/DiscordShard/invalidSession.js +17 -0
- package/DiscordShard/invalidSession.js.map +1 -0
- package/DiscordShard/invalidSession.ts +25 -0
- package/DiscordShard/utils.js +24 -0
- package/DiscordShard/utils.js.map +1 -0
- package/DiscordShard/utils.ts +47 -0
- package/DiscordWS/index.js +35 -0
- package/DiscordWS/index.js.map +1 -1
- package/DiscordWS/index.ts +79 -0
- package/Log/index.js +19 -0
- package/Log/index.js.map +1 -0
- package/Log/index.ts +20 -0
- package/WS/index.js +12 -13
- package/WS/index.js.map +1 -1
- package/WS/index.ts +19 -27
- package/bot.js +33 -0
- package/bot.js.map +1 -0
- package/bot.ts +51 -0
- package/mod.js +5 -7
- package/mod.js.map +1 -1
- package/mod.ts +6 -22
- package/package.json +19 -2
- package/websocket.js +0 -11
- package/websocket.js.map +0 -1
|
@@ -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,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,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,0BAC1C,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,yBAC/B,CAAA;AAEH,MAAM,SAAS,GAAG,CAAC,GAAmB,EAAE,MAA+B,EAAE,EAAE,EAGvE,CAAC,QADD,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAER,CAAC,KAAK,EAAsB,EAAE,CAC5B,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,cAAS,wBAAC,yBAErD,CAAA;AAEI,MAAM,OAAO,GAAG,CACrB,GAA0B,EAC1B,MAA+B,EAC/B,EAAE,EAqCA,CAAC,CAAC,MAAM,CAjCR,CAAC,MAFD,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAET,CAAC,QAAQ,EAAE,EAAE;IACjB,MAAM,UAAU;IAmBd,gDAAgD;IAChD,CAAC,YAdD,CAAC;IAHD,iCAAiC;IACjC,CAAC,MAHD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAa,qBAAa,CAAC,KAAK,CAAC,EAG5C,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,GAEjB,CAAC,CAAC,EAAE,EAAE;QACrB,MAAM,OAAO,GAAG,CAAC,CAAC,CAAE,CAAC,kBAAkB,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;QACvD,OAAO,CAAC,CAAC,MAAM;QACb,yBAAyB;QACzB,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAC,CAAC,GAI5B,CAAC,QADD,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAC,CAAC,EACtB,GAAG,EAAE,CAAC,CAAC,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,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,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":"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"}
|
|
@@ -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,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,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromDispatch = exports.latest = exports.opCode = 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/utils.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 opCode = (hub) => (code) => (S.filter_(S.fromHub_(hub), (p) => p.op === code));
|
|
13
|
+
exports.opCode = opCode;
|
|
14
|
+
const latest = (f) => T.gen(function* (_) {
|
|
15
|
+
const ref = yield* _(R.makeRef(O.none), fileName_1 + ":24:25");
|
|
16
|
+
return [
|
|
17
|
+
ref,
|
|
18
|
+
S.tap((0, Function_1.flow)(f, O.fold(() => T.unit, (a) => R.set_(ref, O.some(a))))),
|
|
19
|
+
];
|
|
20
|
+
}, fileName_1 + ":23:8");
|
|
21
|
+
exports.latest = latest;
|
|
22
|
+
const fromDispatch = (hub) => (event) => (S.map_(S.filter_(S.fromHub_(hub), (p) => p.t === event), (p) => p.d));
|
|
23
|
+
exports.fromDispatch = fromDispatch;
|
|
24
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAE/D,sEAA+C;AAC/C,uDAAqD;AACrD,kEAA2C;AAQpC,MAAM,MAAM,GACjB,CAAC,GAA0B,EAAE,EAAE,CAC/B,CAAU,IAAmB,EAA4B,EAAE,EAGvD,CAAC,SADD,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EACN,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAC9B,CAAA;AANQ,QAAA,MAAM,UAMd;AAEE,MAAM,MAAM,GAAG,CAAI,CAAqC,EAAE,EAAE,CACjE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;IAChB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAc,CAAC,CAAC,IAAI,CAAC,wBAAC,CAAA;IAEpD,OAAO;QACL,GAAG;QACH,CAAC,CAAC,GAAG,CACH,IAAA,eAAI,EACF,CAAC,EACD,CAAC,CAAC,IAAI,CACJ,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EACZ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAC9B,CACF,CACF;KACO,CAAA;AACZ,CAAC,uBAAC,CAAA;AAhBS,QAAA,MAAM,UAgBf;AAEG,MAAM,YAAY,GACvB,CAAC,GAAwC,EAAE,EAAE,CAC7C,CAAgC,KAAQ,EAAE,EAAE,EAIxC,CAAC,MADD,CAAC,SADD,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EACN,CAAC,CAAC,EAAyC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,GAC9D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAqB,EACrC,CAAA;AAPQ,QAAA,YAAY,gBAOpB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { flow, pipe } from "@effect-ts/core/Function"
|
|
6
|
+
import * as O from "@effect-ts/core/Option"
|
|
7
|
+
import {
|
|
8
|
+
GatewayEvent,
|
|
9
|
+
GatewayEvents,
|
|
10
|
+
GatewayOpcode,
|
|
11
|
+
GatewayPayload,
|
|
12
|
+
} from "../types"
|
|
13
|
+
|
|
14
|
+
export const opCode =
|
|
15
|
+
(hub: H.Hub<GatewayPayload>) =>
|
|
16
|
+
<T = any>(code: GatewayOpcode): S.UIO<GatewayPayload<T>> =>
|
|
17
|
+
pipe(
|
|
18
|
+
S.fromHub_(hub),
|
|
19
|
+
S.filter((p) => p.op === code)
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
export const latest = <T>(f: (p: GatewayPayload) => O.Option<T>) =>
|
|
23
|
+
T.gen(function* (_) {
|
|
24
|
+
const ref = yield* _(R.makeRef<O.Option<T>>(O.none))
|
|
25
|
+
|
|
26
|
+
return [
|
|
27
|
+
ref,
|
|
28
|
+
S.tap(
|
|
29
|
+
flow(
|
|
30
|
+
f,
|
|
31
|
+
O.fold(
|
|
32
|
+
() => T.unit,
|
|
33
|
+
(a) => R.set_(ref, O.some(a))
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
),
|
|
37
|
+
] as const
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export const fromDispatch =
|
|
41
|
+
(hub: H.Hub<GatewayPayload<GatewayEvent>>) =>
|
|
42
|
+
<K extends keyof GatewayEvents>(event: K) =>
|
|
43
|
+
pipe(
|
|
44
|
+
S.fromHub_(hub),
|
|
45
|
+
S.filter((p): p is GatewayPayload<GatewayEvents[K]> => p.t === event),
|
|
46
|
+
S.map((p) => p.d as GatewayEvents[K])
|
|
47
|
+
)
|
package/DiscordWS/index.js
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.open = exports.LiveDiscordWS = exports.DiscordWS = exports.jsonEncoding = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
6
|
+
const fileName_1 = "DiscordWS/index.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 SC = tslib_1.__importStar(require("@effect-ts/core/Effect/Schedule"));
|
|
10
|
+
const Function_1 = require("@effect-ts/core/Function");
|
|
11
|
+
const Has_1 = require("@effect-ts/core/Has");
|
|
12
|
+
const Log_1 = require("../Log");
|
|
13
|
+
const WS = tslib_1.__importStar(require("../WS"));
|
|
14
|
+
exports.jsonEncoding = {
|
|
15
|
+
type: "json",
|
|
16
|
+
encode: (p) => JSON.stringify(p),
|
|
17
|
+
decode: (p) => JSON.parse(p.toString("utf8")),
|
|
18
|
+
};
|
|
19
|
+
const makeOutgoing = (s, e) => (S.map_(s, (data) => {
|
|
20
|
+
if (data === WS.Reconnect) {
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
return e.encode(data);
|
|
24
|
+
}));
|
|
25
|
+
const openImpl = ({ url = "wss://gateway.discord.gg/", version = 9, encoding = exports.jsonEncoding, outgoing, }) => (S.map_(S.retry_(S.onError_(S.unwrap(WS.open(`${url}?v=${version}&encoding=${encoding.type}`, makeOutgoing(outgoing, encoding))), (e) => e._tag === "Fail" ? (0, Log_1.log)(serviceTag, "error", e.value) : T.unit), SC.exponential(250)), encoding.decode));
|
|
26
|
+
// Service definition
|
|
27
|
+
const serviceTag = "DiscordWSService";
|
|
28
|
+
const service = {
|
|
29
|
+
_tag: serviceTag,
|
|
30
|
+
open: openImpl,
|
|
31
|
+
};
|
|
32
|
+
exports.DiscordWS = (0, Has_1.tag)();
|
|
33
|
+
exports.LiveDiscordWS = T.toLayer(exports.DiscordWS)(T.succeed(service, fileName_1 + ":75:60"));
|
|
34
|
+
// Helpers
|
|
35
|
+
const open = (opts) => T.accessService(exports.DiscordWS)(({ open }) => open(opts), fileName_1 + ":79:29");
|
|
36
|
+
exports.open = open;
|
|
2
37
|
//# sourceMappingURL=index.js.map
|
package/DiscordWS/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAC/D,4EAAqD;AACrD,uDAA+C;AAC/C,6CAAyC;AAGzC,gCAA4B;AAE5B,kDAA2B;AAiBd,QAAA,YAAY,GAAa;IACpC,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,CAAA;AAED,MAAM,YAAY,GAAG,CAAC,CAAiB,EAAE,CAAW,EAAqB,EAAE,EAGvE,CAAC,MADD,CAAC,EACK,CAAC,IAAI,EAAE,EAAE;IACb,IAAI,IAAI,KAAK,EAAE,CAAC,SAAS,EAAE;QACzB,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AACvB,CAAC,EACF,CAAA;AAEH,MAAM,QAAQ,GAAG,CAAC,EAChB,GAAG,GAAG,2BAA2B,EACjC,OAAO,GAAG,CAAC,EACX,QAAQ,GAAG,oBAAY,EACvB,QAAQ,GACC,EAAE,EAAE,EAWX,CAAC,MADD,CAAC,QAHD,CAAC,UADD,CAAC,CAAC,MAAM,CAJR,EAAE,CAAC,IAAI,CACL,GAAG,GAAG,MAAM,OAAO,aAAa,QAAQ,CAAC,IAAI,EAAE,EAC/C,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,CACjC,GAES,CAAC,CAAC,EAAE,EAAE,CACd,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAA,SAAG,EAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAExD,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,GACrB,QAAQ,CAAC,MAAM,EACtB,CAAA;AAIH,qBAAqB;AACrB,MAAM,UAAU,GAAG,kBAA2B,CAAA;AAC9C,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,QAAQ;CACN,CAAA;AAGG,QAAA,SAAS,GAAG,IAAA,SAAG,GAAa,CAAA;AAC5B,QAAA,aAAa,GAAG,CAAC,CAAC,OAAO,CAAC,iBAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,wBAAC,CAAC,CAAA;AAErE,UAAU;AACH,MAAM,IAAI,GAAG,CAAC,IAAc,EAAE,EAAE,CACrC,CAAC,CAAC,aAAa,CAAC,iBAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAC,CAAA;AADzC,QAAA,IAAI,QACqC"}
|
package/DiscordWS/index.ts
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect"
|
|
2
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream"
|
|
3
|
+
import * as SC from "@effect-ts/core/Effect/Schedule"
|
|
4
|
+
import { pipe } from "@effect-ts/core/Function"
|
|
5
|
+
import { tag } from "@effect-ts/core/Has"
|
|
6
|
+
import { _A } from "@effect-ts/core/Utils"
|
|
7
|
+
import { RawData } from "ws"
|
|
8
|
+
import { log } from "../Log"
|
|
9
|
+
import { GatewayPayload } from "../types"
|
|
10
|
+
import * as WS from "../WS"
|
|
11
|
+
|
|
12
|
+
export type Message = GatewayPayload | WS.Reconnect
|
|
13
|
+
|
|
14
|
+
export interface OpenOpts {
|
|
15
|
+
url?: string
|
|
16
|
+
version?: number
|
|
17
|
+
encoding?: Encoding
|
|
18
|
+
outgoing: WS.OutboundStream<Message>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Encoding {
|
|
22
|
+
type: "json" | "etf"
|
|
23
|
+
encode: (p: GatewayPayload) => string | Buffer | ArrayBuffer
|
|
24
|
+
decode: (p: RawData) => GatewayPayload
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const jsonEncoding: Encoding = {
|
|
28
|
+
type: "json",
|
|
29
|
+
encode: (p) => JSON.stringify(p),
|
|
30
|
+
decode: (p) => JSON.parse(p.toString("utf8")),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const makeOutgoing = (s: S.UIO<Message>, e: Encoding): WS.OutboundStream =>
|
|
34
|
+
pipe(
|
|
35
|
+
s,
|
|
36
|
+
S.map((data) => {
|
|
37
|
+
if (data === WS.Reconnect) {
|
|
38
|
+
return data
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return e.encode(data)
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const openImpl = ({
|
|
46
|
+
url = "wss://gateway.discord.gg/",
|
|
47
|
+
version = 9,
|
|
48
|
+
encoding = jsonEncoding,
|
|
49
|
+
outgoing,
|
|
50
|
+
}: OpenOpts) =>
|
|
51
|
+
pipe(
|
|
52
|
+
WS.open(
|
|
53
|
+
`${url}?v=${version}&encoding=${encoding.type}`,
|
|
54
|
+
makeOutgoing(outgoing, encoding)
|
|
55
|
+
),
|
|
56
|
+
S.unwrap,
|
|
57
|
+
S.onError((e) =>
|
|
58
|
+
e._tag === "Fail" ? log(serviceTag, "error", e.value) : T.unit
|
|
59
|
+
),
|
|
60
|
+
S.retry(SC.exponential(250)),
|
|
61
|
+
S.map(encoding.decode)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
export type Connection = ReturnType<typeof openImpl>
|
|
65
|
+
|
|
66
|
+
// Service definition
|
|
67
|
+
const serviceTag = "DiscordWSService" as const
|
|
68
|
+
const service = {
|
|
69
|
+
_tag: serviceTag,
|
|
70
|
+
open: openImpl,
|
|
71
|
+
} as const
|
|
72
|
+
type Service = typeof service
|
|
73
|
+
export interface DiscordWS extends Service {}
|
|
74
|
+
export const DiscordWS = tag<DiscordWS>()
|
|
75
|
+
export const LiveDiscordWS = T.toLayer(DiscordWS)(T.succeed(service))
|
|
76
|
+
|
|
77
|
+
// Helpers
|
|
78
|
+
export const open = (opts: OpenOpts) =>
|
|
79
|
+
T.accessService(DiscordWS)(({ open }) => open(opts))
|
package/Log/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.log = exports.LiveLog = exports.Log = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
6
|
+
const fileName_1 = "Log/index.ts";
|
|
7
|
+
const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
|
|
8
|
+
const Has_1 = require("@effect-ts/core/Has");
|
|
9
|
+
const service = {
|
|
10
|
+
_tag: "LogService",
|
|
11
|
+
log: (...args) => T.succeedWith(() => {
|
|
12
|
+
console.error(...args);
|
|
13
|
+
}, fileName_1 + ":8:18"),
|
|
14
|
+
};
|
|
15
|
+
exports.Log = (0, Has_1.tag)();
|
|
16
|
+
exports.LiveLog = T.toLayer(exports.Log)(T.succeed(service, fileName_1 + ":17:48"));
|
|
17
|
+
const log = (...args) => T.accessServiceM(exports.Log)(({ log }) => log(...args), fileName_1 + ":20:24");
|
|
18
|
+
exports.log = log;
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/Log/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,6CAAyC;AAGzC,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE,CACtB,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE;QACjB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;IACxB,CAAC,uBAAC;CACI,CAAA;AAKG,QAAA,GAAG,GAAG,IAAA,SAAG,GAAO,CAAA;AAChB,QAAA,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,WAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,wBAAC,CAAC,CAAA;AAElD,MAAM,GAAG,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE,CACpC,CAAC,CAAC,cAAc,CAAC,WAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,wBAAC,CAAA;AADrC,QAAA,GAAG,OACkC"}
|
package/Log/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect"
|
|
2
|
+
import { tag } from "@effect-ts/core/Has"
|
|
3
|
+
import { _A } from "@effect-ts/core/Utils"
|
|
4
|
+
|
|
5
|
+
const service = {
|
|
6
|
+
_tag: "LogService",
|
|
7
|
+
log: (...args: any[]) =>
|
|
8
|
+
T.succeedWith(() => {
|
|
9
|
+
console.error(...args)
|
|
10
|
+
}),
|
|
11
|
+
} as const
|
|
12
|
+
|
|
13
|
+
type Service = typeof service
|
|
14
|
+
|
|
15
|
+
export interface Log extends Service {}
|
|
16
|
+
export const Log = tag<Log>()
|
|
17
|
+
export const LiveLog = T.toLayer(Log)(T.succeed(service))
|
|
18
|
+
|
|
19
|
+
export const log = (...args: any[]) =>
|
|
20
|
+
T.accessServiceM(Log)(({ log }) => log(...args))
|
package/WS/index.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LiveWS = exports.WS = exports.Reconnect = void 0;
|
|
3
|
+
exports.open = exports.LiveWS = exports.WS = exports.Reconnect = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
6
6
|
const fileName_1 = "WS/index.ts";
|
|
7
7
|
const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
|
|
8
8
|
const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
|
|
9
9
|
const M = tslib_1.__importStar(require("@effect-ts/core/Effect/Managed"));
|
|
10
|
-
const Q = tslib_1.__importStar(require("@effect-ts/core/Effect/Queue"));
|
|
11
10
|
const SC = tslib_1.__importStar(require("@effect-ts/core/Effect/Schedule"));
|
|
12
11
|
const Function_1 = require("@effect-ts/core/Function");
|
|
13
12
|
const Has_1 = require("@effect-ts/core/Has");
|
|
14
13
|
const Ws = tslib_1.__importStar(require("ws"));
|
|
15
14
|
exports.Reconnect = Symbol();
|
|
16
|
-
const
|
|
15
|
+
const openSocket = (url, options) => (M.makeExit_(T.succeedWith(() => new Ws.WebSocket(url, options), fileName_1 + ":25:18"), (ws) => T.succeedWith(() => {
|
|
17
16
|
ws.removeAllListeners();
|
|
18
17
|
ws.close();
|
|
19
|
-
}, fileName_1 + ":
|
|
18
|
+
}, fileName_1 + ":27:20"), fileName_1 + ":26:15"));
|
|
20
19
|
const recv = (ws) => S.async((emit) => {
|
|
21
20
|
ws.on("message", (message) => emit.single(message));
|
|
22
21
|
ws.on("error", (cause) => {
|
|
@@ -40,32 +39,32 @@ const send = (out) => (ws) => (S.drain(S.tap_(S.unwrap(T.map_(T.effectAsync((cb)
|
|
|
40
39
|
cb(T.unit);
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
|
-
}, fileName_1 + ":
|
|
42
|
+
}, fileName_1 + ":54:18"), () => out, fileName_1 + ":63:10")), (data) => T.effectAsync((cb) => {
|
|
44
43
|
if (data === exports.Reconnect) {
|
|
45
44
|
ws.close(1012, "reconnecting");
|
|
46
45
|
cb(T.unit);
|
|
47
46
|
}
|
|
48
47
|
else {
|
|
48
|
+
console.error(data);
|
|
49
49
|
ws.send(data, (err) => {
|
|
50
50
|
if (err) {
|
|
51
|
-
cb(T.fail({ _tag: "write", cause: err }, fileName_1 + ":
|
|
51
|
+
cb(T.fail({ _tag: "write", cause: err }, fileName_1 + ":74:24"));
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
cb(T.unit);
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
}, fileName_1 + ":
|
|
58
|
+
}, fileName_1 + ":66:20"))));
|
|
59
59
|
const duplex = (out) => (ws) => (S.mergeTerminateLeft_(recv(ws), send(out)(ws)));
|
|
60
|
-
const
|
|
61
|
-
const openDuplex = (url, options) => (T.map_(Q.makeUnbounded(), (write) => ({
|
|
62
|
-
read: openDuplexWithQueue(url, write, options),
|
|
63
|
-
write,
|
|
64
|
-
}), fileName_1 + ":109:10"));
|
|
60
|
+
const openDuplex = (url, out, options) => (S.retry_(S.unwrapManaged(M.map_(openSocket(url, options), duplex(out), fileName_1 + ":95:10")), SC.recurWhile((e) => e._tag === "close" && e.code === 1012)));
|
|
65
61
|
const makeWS = T.succeed({
|
|
66
62
|
_tag: "WSService",
|
|
67
63
|
open: openDuplex,
|
|
68
|
-
}, fileName_1 + ":
|
|
64
|
+
}, fileName_1 + ":100:25");
|
|
69
65
|
exports.WS = (0, Has_1.tag)();
|
|
70
66
|
exports.LiveWS = T.toLayer(exports.WS)(makeWS);
|
|
67
|
+
// Helpers
|
|
68
|
+
const open = (url, out, options) => T.accessService(exports.WS)(({ open }) => open(url, out, options), fileName_1 + ":114:25");
|
|
69
|
+
exports.open = open;
|
|
71
70
|
//# sourceMappingURL=index.js.map
|
package/WS/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAC/D,0EAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"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"}
|
package/WS/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as T from "@effect-ts/core/Effect"
|
|
2
2
|
import * as S from "@effect-ts/core/Effect/Experimental/Stream"
|
|
3
3
|
import * as M from "@effect-ts/core/Effect/Managed"
|
|
4
|
-
import * as Q from "@effect-ts/core/Effect/Queue"
|
|
5
4
|
import * as SC from "@effect-ts/core/Effect/Schedule"
|
|
6
5
|
import { pipe } from "@effect-ts/core/Function"
|
|
7
6
|
import { tag } from "@effect-ts/core/Has"
|
|
@@ -14,17 +13,14 @@ export type WsError =
|
|
|
14
13
|
| { _tag: "error"; cause: unknown }
|
|
15
14
|
| { _tag: "write"; cause: unknown }
|
|
16
15
|
|
|
17
|
-
type WebSocketStream = S.Stream<HasClock, WsError,
|
|
16
|
+
export type WebSocketStream<T = Ws.RawData> = S.Stream<HasClock, WsError, T>
|
|
18
17
|
|
|
19
18
|
export const Reconnect = Symbol()
|
|
20
|
-
export type
|
|
19
|
+
export type Reconnect = typeof Reconnect
|
|
20
|
+
export type Message = string | Buffer | ArrayBuffer | Reconnect
|
|
21
|
+
export type OutboundStream<T = Message> = S.UIO<T>
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
read: WebSocketStream
|
|
24
|
-
write: Q.Queue<Message>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const open = (url: string, options?: Ws.ClientOptions) =>
|
|
23
|
+
const openSocket = (url: string, options?: Ws.ClientOptions) =>
|
|
28
24
|
pipe(
|
|
29
25
|
T.succeedWith(() => new Ws.WebSocket(url, options)),
|
|
30
26
|
M.makeExit((ws) =>
|
|
@@ -53,7 +49,7 @@ const recv = (ws: Ws.WebSocket): WebSocketStream =>
|
|
|
53
49
|
)
|
|
54
50
|
})
|
|
55
51
|
|
|
56
|
-
const send = (out:
|
|
52
|
+
const send = (out: OutboundStream) => (ws: Ws.WebSocket) =>
|
|
57
53
|
pipe(
|
|
58
54
|
T.effectAsync<unknown, WsError, void>((cb) => {
|
|
59
55
|
if (ws.readyState & ws.OPEN) {
|
|
@@ -64,7 +60,7 @@ const send = (out: Q.Queue<Message>) => (ws: Ws.WebSocket) =>
|
|
|
64
60
|
})
|
|
65
61
|
}
|
|
66
62
|
}),
|
|
67
|
-
T.map(() =>
|
|
63
|
+
T.map(() => out),
|
|
68
64
|
S.unwrap,
|
|
69
65
|
S.tap((data) =>
|
|
70
66
|
T.effectAsync<unknown, WsError, void>((cb) => {
|
|
@@ -72,6 +68,7 @@ const send = (out: Q.Queue<Message>) => (ws: Ws.WebSocket) =>
|
|
|
72
68
|
ws.close(1012, "reconnecting")
|
|
73
69
|
cb(T.unit)
|
|
74
70
|
} else {
|
|
71
|
+
console.error(data)
|
|
75
72
|
ws.send(data, (err) => {
|
|
76
73
|
if (err) {
|
|
77
74
|
cb(T.fail({ _tag: "write", cause: err }))
|
|
@@ -85,33 +82,21 @@ const send = (out: Q.Queue<Message>) => (ws: Ws.WebSocket) =>
|
|
|
85
82
|
S.drain
|
|
86
83
|
)
|
|
87
84
|
|
|
88
|
-
const duplex = (out:
|
|
85
|
+
const duplex = (out: OutboundStream) => (ws: Ws.WebSocket) =>
|
|
89
86
|
pipe(recv(ws), S.mergeTerminateLeft(send(out)(ws)))
|
|
90
87
|
|
|
91
|
-
const
|
|
88
|
+
const openDuplex = (
|
|
92
89
|
url: string,
|
|
93
|
-
out:
|
|
90
|
+
out: OutboundStream,
|
|
94
91
|
options?: Ws.ClientOptions
|
|
95
92
|
): WebSocketStream =>
|
|
96
93
|
pipe(
|
|
97
|
-
|
|
94
|
+
openSocket(url, options),
|
|
98
95
|
M.map(duplex(out)),
|
|
99
96
|
S.unwrapManaged,
|
|
100
97
|
S.retry(SC.recurWhile((e) => e._tag === "close" && e.code === 1012))
|
|
101
98
|
)
|
|
102
99
|
|
|
103
|
-
const openDuplex = (
|
|
104
|
-
url: string,
|
|
105
|
-
options?: Ws.ClientOptions
|
|
106
|
-
): T.UIO<WebSocketConnection> =>
|
|
107
|
-
pipe(
|
|
108
|
-
Q.makeUnbounded<Message>(),
|
|
109
|
-
T.map((write) => ({
|
|
110
|
-
read: openDuplexWithQueue(url, write, options),
|
|
111
|
-
write,
|
|
112
|
-
}))
|
|
113
|
-
)
|
|
114
|
-
|
|
115
100
|
const makeWS = T.succeed({
|
|
116
101
|
_tag: "WSService",
|
|
117
102
|
open: openDuplex,
|
|
@@ -120,3 +105,10 @@ const makeWS = T.succeed({
|
|
|
120
105
|
export interface WS extends _A<typeof makeWS> {}
|
|
121
106
|
export const WS = tag<WS>()
|
|
122
107
|
export const LiveWS = T.toLayer(WS)(makeWS)
|
|
108
|
+
|
|
109
|
+
// Helpers
|
|
110
|
+
export const open = (
|
|
111
|
+
url: string,
|
|
112
|
+
out: OutboundStream,
|
|
113
|
+
options?: Ws.ClientOptions
|
|
114
|
+
) => T.accessService(WS)(({ open }) => open(url, out, options))
|
package/bot.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
5
|
+
const fileName_1 = "bot.ts";
|
|
6
|
+
const T = tslib_1.__importStar(require("@effect-ts/core/Effect"));
|
|
7
|
+
const S = tslib_1.__importStar(require("@effect-ts/core/Effect/Experimental/Stream"));
|
|
8
|
+
const M = tslib_1.__importStar(require("@effect-ts/core/Effect/Managed"));
|
|
9
|
+
const Function_1 = require("@effect-ts/core/Function");
|
|
10
|
+
const Has_1 = require("@effect-ts/core/Has");
|
|
11
|
+
const R = tslib_1.__importStar(require("@effect-ts/node/Runtime"));
|
|
12
|
+
const Dotemv = tslib_1.__importStar(require("dotenv"));
|
|
13
|
+
const _1 = require(".");
|
|
14
|
+
const Shard = tslib_1.__importStar(require("./DiscordShard"));
|
|
15
|
+
const Log_1 = require("./Log");
|
|
16
|
+
const types_1 = require("./types");
|
|
17
|
+
Dotemv.config();
|
|
18
|
+
const makeBot = (M.map_(Shard.make({
|
|
19
|
+
token: process.env.DISCORD_BOT_TOKEN,
|
|
20
|
+
intents: types_1.GatewayIntents.GUILDS | types_1.GatewayIntents.GUILD_MESSAGES,
|
|
21
|
+
shard: [0, 1],
|
|
22
|
+
}), (bot) => ({
|
|
23
|
+
_tag: "BotService",
|
|
24
|
+
bot,
|
|
25
|
+
}), fileName_1 + ":22:8"));
|
|
26
|
+
const Bot = (0, Has_1.tag)();
|
|
27
|
+
const LiveBot = M.toLayer_(makeBot, Bot);
|
|
28
|
+
const bot = T.accessService(Bot)(({ bot }) => bot, fileName_1 + ":34:33");
|
|
29
|
+
const runBot = T.accessServiceM(Bot)(({ bot }) => bot.run, fileName_1 + ":35:37");
|
|
30
|
+
// logger
|
|
31
|
+
const logger = T.chain_(bot, ({ raw }) => (S.forEach_(S.fromHub_(raw), (p) => (0, Log_1.log)(p))), fileName_1 + ":38:24");
|
|
32
|
+
(R.runMain(T.provideSomeLayer(_1.DefaultEnv[">+>"](LiveBot))(T.zipPar(runBot, fileName_1 + ":47:11")(logger))));
|
|
33
|
+
//# sourceMappingURL=bot.js.map
|
package/bot.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.js","sourceRoot":"","sources":["bot.ts"],"names":[],"mappings":";;;;;AAAA,kEAA2C;AAC3C,sFAA+D;AAC/D,0EAAmD;AACnD,uDAA+C;AAC/C,6CAAyC;AAEzC,mEAA4C;AAC5C,uDAAgC;AAChC,wBAA8B;AAC9B,8DAAuC;AACvC,+BAA2B;AAC3B,mCAAwC;AAExC,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,OAAO,IAMX,CAAC,MALD,KAAK,CAAC,IAAI,CAAC;IACT,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAkB;IACrC,OAAO,EAAE,sBAAc,CAAC,MAAM,GAAG,sBAAc,CAAC,cAAc;IAC9D,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;CACd,CAAC,EAEA,CAAC,GAAG,EAAE,EAAE,CACN,CAAC;IACC,IAAI,EAAE,YAAY;IAClB,GAAG;CACM,CAAA,wBAEhB,CAAA;AAGD,MAAM,GAAG,GAAG,IAAA,SAAG,GAAO,CAAA;AACtB,MAAM,OAAO,GAAG,CAAC,UAAc,OAAO,EAAZ,GAAG,CAAU,CAAA;AACvC,MAAM,GAAG,GAAG,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,wBAAC,CAAA;AAClD,MAAM,MAAM,GAAG,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,wBAAC,CAAA;AAE1D,SAAS;AACT,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAGrC,CAAC,UADD,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EACL,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,SAAG,EAAC,CAAC,CAAC,EACxB,wBACF,CAAA;AAED,CAKE,CAAC,CAAC,OAAO,CADT,CAAC,CAAC,gBAAgB,CAAC,aAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAF9C,CAAC,CAAC,MAAM,CAAC,MAAM,wBAAC,CADhB,MAAM,KAKP"}
|
package/bot.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as T from "@effect-ts/core/Effect"
|
|
2
|
+
import * as S from "@effect-ts/core/Effect/Experimental/Stream"
|
|
3
|
+
import * as M from "@effect-ts/core/Effect/Managed"
|
|
4
|
+
import { pipe } from "@effect-ts/core/Function"
|
|
5
|
+
import { tag } from "@effect-ts/core/Has"
|
|
6
|
+
import { _A } from "@effect-ts/core/Utils"
|
|
7
|
+
import * as R from "@effect-ts/node/Runtime"
|
|
8
|
+
import * as Dotemv from "dotenv"
|
|
9
|
+
import { DefaultEnv } from "."
|
|
10
|
+
import * as Shard from "./DiscordShard"
|
|
11
|
+
import { log } from "./Log"
|
|
12
|
+
import { GatewayIntents } from "./types"
|
|
13
|
+
|
|
14
|
+
Dotemv.config()
|
|
15
|
+
|
|
16
|
+
const makeBot = pipe(
|
|
17
|
+
Shard.make({
|
|
18
|
+
token: process.env.DISCORD_BOT_TOKEN!,
|
|
19
|
+
intents: GatewayIntents.GUILDS | GatewayIntents.GUILD_MESSAGES,
|
|
20
|
+
shard: [0, 1],
|
|
21
|
+
}),
|
|
22
|
+
M.map(
|
|
23
|
+
(bot) =>
|
|
24
|
+
({
|
|
25
|
+
_tag: "BotService",
|
|
26
|
+
bot,
|
|
27
|
+
} as const)
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
interface Bot extends _A<typeof makeBot> {}
|
|
32
|
+
const Bot = tag<Bot>()
|
|
33
|
+
const LiveBot = M.toLayer(Bot)(makeBot)
|
|
34
|
+
const bot = T.accessService(Bot)(({ bot }) => bot)
|
|
35
|
+
const runBot = T.accessServiceM(Bot)(({ bot }) => bot.run)
|
|
36
|
+
|
|
37
|
+
// logger
|
|
38
|
+
const logger = T.chain_(bot, ({ raw }) =>
|
|
39
|
+
pipe(
|
|
40
|
+
S.fromHub_(raw),
|
|
41
|
+
S.forEach((p) => log(p))
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
pipe(
|
|
46
|
+
logger,
|
|
47
|
+
T.zipPar(runBot),
|
|
48
|
+
|
|
49
|
+
T.provideSomeLayer(DefaultEnv[">+>"](LiveBot)),
|
|
50
|
+
R.runMain
|
|
51
|
+
)
|
package/mod.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultEnv = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const tracing_1 = tslib_1.__importStar(require("@effect-ts/core/Tracing"));
|
|
5
6
|
const fileName_1 = "mod.ts";
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const R = tslib_1.__importStar(require("@effect-ts/node/Runtime"));
|
|
7
|
+
const Shard = tslib_1.__importStar(require("./DiscordShard"));
|
|
8
|
+
const DiscordWS_1 = require("./DiscordWS");
|
|
9
|
+
const Log_1 = require("./Log");
|
|
10
10
|
const WS = tslib_1.__importStar(require("./WS"));
|
|
11
|
-
|
|
12
|
-
console.error(data.toString("utf8"));
|
|
13
|
-
}, fileName_1 + ":16:22"))), fileName_1 + ":11:10"))));
|
|
11
|
+
exports.DefaultEnv = WS.LiveWS[">+>"](DiscordWS_1.LiveDiscordWS)[">+>"](Shard.LiveDiscordShard)["+++"](Log_1.LiveLog);
|
|
14
12
|
//# sourceMappingURL=mod.js.map
|
package/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["mod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["mod.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAuC;AACvC,2CAA2C;AAC3C,+BAA+B;AAC/B,iDAA0B;AAEb,QAAA,UAAU,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,yBAAa,CAAC,CACtD,KAAK,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAC9B,KAAK,CAAC,CAAC,aAAO,CAAC,CAAA"}
|
package/mod.ts
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import * as R from "@effect-ts/node/Runtime"
|
|
1
|
+
import * as Shard from "./DiscordShard"
|
|
2
|
+
import { LiveDiscordWS } from "./DiscordWS"
|
|
3
|
+
import { LiveLog } from "./Log"
|
|
5
4
|
import * as WS from "./WS"
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
),
|
|
11
|
-
T.chain(({ read, write }) =>
|
|
12
|
-
pipe(
|
|
13
|
-
read,
|
|
14
|
-
S.retry(exponential(10)),
|
|
15
|
-
S.forEach((data) =>
|
|
16
|
-
T.succeedWith(() => {
|
|
17
|
-
console.error(data.toString("utf8"))
|
|
18
|
-
})
|
|
19
|
-
)
|
|
20
|
-
)
|
|
21
|
-
),
|
|
22
|
-
T.provideSomeLayer(WS.LiveWS),
|
|
23
|
-
R.runMain
|
|
24
|
-
)
|
|
6
|
+
export const DefaultEnv = WS.LiveWS[">+>"](LiveDiscordWS)
|
|
7
|
+
[">+>"](Shard.LiveDiscordShard)
|
|
8
|
+
["+++"](LiveLog)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dfx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Effect-TS discord library",
|
|
5
5
|
"main": "mod.js",
|
|
6
6
|
"author": "Tim Smart <tim.smart@arisechurch.com>",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"prepare": "ttsc",
|
|
10
10
|
"types": "discord-api-codegen ./discord-api-docs -l typescript -o 'imports=Response|./DiscordREST/types' 'endpointReturnType=Response' > types.ts && prettier -w types.ts",
|
|
11
|
-
"clean": "git clean -fxd -e node_modules/ -e .env"
|
|
11
|
+
"clean": "git clean -fxd -e node_modules/ -e .env",
|
|
12
|
+
"dev": "ts-node -C ttypescript mod.ts"
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
14
15
|
"**/*.ts",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"@tim-smart/discord-api-docs-parser": "^0.3.0",
|
|
22
23
|
"@types/ws": "^8.5.3",
|
|
23
24
|
"prettier": "^2.5.1",
|
|
25
|
+
"ts-node": "^10.7.0",
|
|
24
26
|
"ttypescript": "^1.5.13",
|
|
25
27
|
"typescript": "^4.6.2"
|
|
26
28
|
},
|
|
@@ -28,7 +30,22 @@
|
|
|
28
30
|
"@effect-ts/core": "^0.58.0",
|
|
29
31
|
"@effect-ts/node": "^0.38.3",
|
|
30
32
|
"@effect-ts/system": "^0.55.0",
|
|
33
|
+
"dotenv": "^16.0.0",
|
|
31
34
|
"tslib": "^2.3.1",
|
|
32
35
|
"ws": "^8.5.0"
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"require": "./mod.js"
|
|
40
|
+
},
|
|
41
|
+
"./WS": {
|
|
42
|
+
"require": "./WS/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./DiscordShard": {
|
|
45
|
+
"require": "./DiscordShard/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./DiscordWS": {
|
|
48
|
+
"require": "./DiscordWS/index.js"
|
|
49
|
+
}
|
|
33
50
|
}
|
|
34
51
|
}
|
package/websocket.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as tracing_1 from "@effect-ts/core/Tracing";
|
|
2
|
-
const fileName_1 = "websocket.ts";
|
|
3
|
-
import * as Ws from "ws";
|
|
4
|
-
import * as H from "@effect-ts/core/Effect/Hub";
|
|
5
|
-
import * as S from "@effect-ts/core/Effect/Experimental/Stream";
|
|
6
|
-
export const create = (url, options) => {
|
|
7
|
-
const ws = new Ws.WebSocket(url, options);
|
|
8
|
-
const hub = H.makeUnbounded();
|
|
9
|
-
S.fromHub;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=websocket.js.map
|
package/websocket.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["websocket.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AAExB,OAAO,KAAK,CAAC,MAAM,4BAA4B,CAAA;AAC/C,OAAO,KAAK,CAAC,MAAM,4CAA4C,CAAA;AAE/D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,OAA0B,EAAE,EAAE;IAChE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAEzC,MAAM,GAAG,GAAG,CAAC,CAAC,aAAa,EAAI,CAAA;IAE/B,CAAC,CAAC,OAAO,CAAA;AACX,CAAC,CAAA"}
|