dfx 0.0.1 → 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/DiscordREST/types.js +6 -0
- package/DiscordREST/types.js.map +1 -0
- 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 +37 -0
- package/DiscordWS/index.js.map +1 -0
- 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/README.md +3 -0
- package/WS/index.js +70 -0
- package/WS/index.js.map +1 -0
- 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 -0
- package/mod.ts +6 -22
- package/package.json +25 -2
- package/types.js +1563 -0
- package/types.js.map +1 -0
- package/.gitmodules +0 -3
- package/.prettierrc.json +0 -4
- package/discord-api-docs/.eslintrc.json +0 -10
- package/discord-api-docs/.gitattributes +0 -11
- package/discord-api-docs/.github/ISSUE_TEMPLATE/api-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/config.yml +0 -20
- package/discord-api-docs/.github/ISSUE_TEMPLATE/developer-site-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/message-components-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/slash-command-bug-report.yml +0 -49
- package/discord-api-docs/.github/workflows/test.yaml +0 -45
- package/discord-api-docs/.prettierignore +0 -1
- package/discord-api-docs/.prettierrc.json +0 -15
- package/discord-api-docs/CODE_OF_CONDUCT.md +0 -75
- package/discord-api-docs/CONTRIBUTING.md +0 -16
- package/discord-api-docs/README.md +0 -35
- package/discord-api-docs/ci/checkLinks.ts +0 -177
- package/discord-api-docs/docs/Change_Log.md +0 -474
- package/discord-api-docs/docs/Intro.md +0 -48
- package/discord-api-docs/docs/Legal.md +0 -154
- package/discord-api-docs/docs/Policy.md +0 -81
- package/discord-api-docs/docs/Reference.md +0 -476
- package/discord-api-docs/docs/Store_Distribution_Agreement.md +0 -179
- package/discord-api-docs/docs/dispatch/Branches_and_Builds.md +0 -654
- package/discord-api-docs/docs/dispatch/Dispatch_and_You.md +0 -17
- package/discord-api-docs/docs/dispatch/Error_Codes.md +0 -26
- package/discord-api-docs/docs/dispatch/Field_Values.md +0 -48
- package/discord-api-docs/docs/dispatch/List_of_Commands.md +0 -315
- package/discord-api-docs/docs/game_and_server_management/Alpha_and_Beta_Testing.md +0 -52
- package/discord-api-docs/docs/game_and_server_management/How_to_Get_Your_Game_on_Discord.md +0 -110
- package/discord-api-docs/docs/game_and_server_management/Special_Channels.md +0 -38
- package/discord-api-docs/docs/game_sdk/Achievements.md +0 -405
- package/discord-api-docs/docs/game_sdk/Activities.md +0 -561
- package/discord-api-docs/docs/game_sdk/Applications.md +0 -237
- package/discord-api-docs/docs/game_sdk/Discord.md +0 -443
- package/discord-api-docs/docs/game_sdk/Discord_Voice.md +0 -289
- package/discord-api-docs/docs/game_sdk/Images.md +0 -196
- package/discord-api-docs/docs/game_sdk/Lobbies.md +0 -1639
- package/discord-api-docs/docs/game_sdk/Networking.md +0 -377
- package/discord-api-docs/docs/game_sdk/Overlay.md +0 -195
- package/discord-api-docs/docs/game_sdk/Relationships.md +0 -234
- package/discord-api-docs/docs/game_sdk/SDK_Starter_Guide.md +0 -310
- package/discord-api-docs/docs/game_sdk/Storage.md +0 -312
- package/discord-api-docs/docs/game_sdk/Store.md +0 -555
- package/discord-api-docs/docs/game_sdk/Users.md +0 -178
- package/discord-api-docs/docs/interactions/Application_Commands.md +0 -1069
- package/discord-api-docs/docs/interactions/Message_Components.md +0 -454
- package/discord-api-docs/docs/interactions/Receiving_and_Responding.md +0 -372
- package/discord-api-docs/docs/interactions/Slash_Commands.md +0 -3
- package/discord-api-docs/docs/resources/Application.md +0 -82
- package/discord-api-docs/docs/resources/Audit_Log.md +0 -223
- package/discord-api-docs/docs/resources/Channel.md +0 -1267
- package/discord-api-docs/docs/resources/Emoji.md +0 -122
- package/discord-api-docs/docs/resources/Guild.md +0 -1157
- package/discord-api-docs/docs/resources/Guild_Scheduled_Event.md +0 -273
- package/discord-api-docs/docs/resources/Guild_Template.md +0 -148
- package/discord-api-docs/docs/resources/Invite.md +0 -150
- package/discord-api-docs/docs/resources/Stage_Instance.md +0 -106
- package/discord-api-docs/docs/resources/Sticker.md +0 -164
- package/discord-api-docs/docs/resources/User.md +0 -205
- package/discord-api-docs/docs/resources/Voice.md +0 -55
- package/discord-api-docs/docs/resources/Webhook.md +0 -281
- package/discord-api-docs/docs/rich_presence/Best_Practices.md +0 -88
- package/discord-api-docs/docs/rich_presence/FAQ.md +0 -45
- package/discord-api-docs/docs/rich_presence/How_To.md +0 -302
- package/discord-api-docs/docs/rich_presence/Launch_Checklist.md +0 -46
- package/discord-api-docs/docs/topics/Certified_Devices.md +0 -200
- package/discord-api-docs/docs/topics/Community_Resources.md +0 -98
- package/discord-api-docs/docs/topics/Gateway.md +0 -1600
- package/discord-api-docs/docs/topics/OAuth2.md +0 -427
- package/discord-api-docs/docs/topics/Opcodes_and_Status_Codes.md +0 -306
- package/discord-api-docs/docs/topics/Permissions.md +0 -229
- package/discord-api-docs/docs/topics/RPC.md +0 -1597
- package/discord-api-docs/docs/topics/Rate_Limits.md +0 -126
- package/discord-api-docs/docs/topics/Teams.md +0 -80
- package/discord-api-docs/docs/topics/Threads.md +0 -163
- package/discord-api-docs/docs/topics/Voice_Connections.md +0 -282
- package/discord-api-docs/images/API_center.gif +0 -0
- package/discord-api-docs/images/ask-to-join.gif +0 -0
- package/discord-api-docs/images/available-published.png +0 -0
- package/discord-api-docs/images/button-styles.png +0 -0
- package/discord-api-docs/images/certified-device.png +0 -0
- package/discord-api-docs/images/command-with-groups-subcommands-parameters.png +0 -0
- package/discord-api-docs/images/command-with-groups-subcommands.png +0 -0
- package/discord-api-docs/images/command.png +0 -0
- package/discord-api-docs/images/cpp-files-sdk.png +0 -0
- package/discord-api-docs/images/create-store-channel.png +0 -0
- package/discord-api-docs/images/deferred-example.png +0 -0
- package/discord-api-docs/images/desktop-select.png +0 -0
- package/discord-api-docs/images/game-overlay-sdk-invite.gif +0 -0
- package/discord-api-docs/images/game-overlay-sdk-voice-settings.png +0 -0
- package/discord-api-docs/images/game-overlay-sdk-voice-widget.png +0 -0
- package/discord-api-docs/images/gift-code-creation.png +0 -0
- package/discord-api-docs/images/lib-linked-sdk.png +0 -0
- package/discord-api-docs/images/message-command.png +0 -0
- package/discord-api-docs/images/mobile-select.png +0 -0
- package/discord-api-docs/images/previous-new-server-background.png +0 -0
- package/discord-api-docs/images/rp-actionable.png +0 -0
- package/discord-api-docs/images/rp-all-fields.png +0 -0
- package/discord-api-docs/images/rp-bad-art.png +0 -0
- package/discord-api-docs/images/rp-good-art.png +0 -0
- package/discord-api-docs/images/rp-legend.png +0 -0
- package/discord-api-docs/images/rp-long-strings.png +0 -0
- package/discord-api-docs/images/rp-non-actionable.png +0 -0
- package/discord-api-docs/images/rp-not-all-fields.png +0 -0
- package/discord-api-docs/images/rp-profile-example-1.png +0 -0
- package/discord-api-docs/images/rp-profile-example-2.png +0 -0
- package/discord-api-docs/images/rp-short-strings.png +0 -0
- package/discord-api-docs/images/server-banner-example.png +0 -0
- package/discord-api-docs/images/server-banner-margin-top.png +0 -0
- package/discord-api-docs/images/sku-management.png +0 -0
- package/discord-api-docs/images/snowflake.png +0 -0
- package/discord-api-docs/images/snowflake_original_size.png +0 -0
- package/discord-api-docs/images/spectate.gif +0 -0
- package/discord-api-docs/images/team-2fa.png +0 -0
- package/discord-api-docs/images/team-make-app.png +0 -0
- package/discord-api-docs/images/team-page.png +0 -0
- package/discord-api-docs/images/transfer-app-to-team.png +0 -0
- package/discord-api-docs/images/user-command.png +0 -0
- package/discord-api-docs/package-lock.json +0 -3186
- package/discord-api-docs/package.json +0 -38
- package/discord-api-docs/tsconfig.eslint.json +0 -4
- package/discord-api-docs/tsconfig.json +0 -19
- package/tsconfig.json +0 -24
|
@@ -0,0 +1,6 @@
|
|
|
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 = "DiscordREST/types.ts";
|
|
6
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
|
|
@@ -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,U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BAAkB,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":";;;;;;AAAA,kEAA2C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EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,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,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
|
+
)
|