@erinjs/core 1.0.0 → 1.2.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/{core/LICENSE → LICENSE} +203 -203
- package/README.md +46 -0
- package/dist/index.d.mts +2084 -0
- package/dist/index.d.ts +2084 -0
- package/dist/index.js +3867 -0
- package/dist/index.mjs +3809 -0
- package/package.json +50 -15
- package/core/.changeset/README.md +0 -8
- package/core/.changeset/community-bootstrap-release.md +0 -17
- package/core/.changeset/config.json +0 -11
- package/core/.changeset/no-changelog.js +0 -16
- package/core/.changeset/pre.json +0 -17
- package/core/.editorconfig +0 -13
- package/core/.gitattributes +0 -2
- package/core/.github/CODE_OF_CONDUCT.md +0 -23
- package/core/.github/FUNDING.yml +0 -7
- package/core/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- package/core/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
- package/core/.github/PULL_REQUEST_TEMPLATE.md +0 -16
- package/core/.github/dependabot.yml +0 -16
- package/core/.github/workflows/autoapp.yml +0 -16
- package/core/.github/workflows/ci.yml +0 -187
- package/core/.github/workflows/codeql.yml +0 -30
- package/core/.github/workflows/deploy-docs.yml +0 -54
- package/core/.github/workflows/publish.yml +0 -43
- package/core/.lintstagedrc.json +0 -4
- package/core/.nvmrc +0 -1
- package/core/.prettierignore +0 -8
- package/core/.prettierrc +0 -11
- package/core/CONTRIBUTING.md +0 -70
- package/core/README.md +0 -61
- package/core/SECURITY.md +0 -21
- package/core/apps/docs/index.html +0 -28
- package/core/apps/docs/middleware.ts +0 -21
- package/core/apps/docs/package.json +0 -33
- package/core/apps/docs/public/@flux.png +0 -0
- package/core/apps/docs/public/docs/latest/guides.json +0 -1420
- package/core/apps/docs/public/docs/latest/main.json +0 -14981
- package/core/apps/docs/public/docs/latest/rag-index.json +0 -1
- package/core/apps/docs/public/docs/v1.0.5/guides.json +0 -226
- package/core/apps/docs/public/docs/v1.0.5/main.json +0 -7920
- package/core/apps/docs/public/docs/v1.0.6/guides.json +0 -226
- package/core/apps/docs/public/docs/v1.0.6/main.json +0 -7920
- package/core/apps/docs/public/docs/v1.0.7/guides.json +0 -259
- package/core/apps/docs/public/docs/v1.0.7/main.json +0 -8652
- package/core/apps/docs/public/docs/v1.0.8/guides.json +0 -313
- package/core/apps/docs/public/docs/v1.0.8/main.json +0 -9618
- package/core/apps/docs/public/docs/v1.0.9/guides.json +0 -319
- package/core/apps/docs/public/docs/v1.0.9/main.json +0 -10694
- package/core/apps/docs/public/docs/v1.1.0/guides.json +0 -589
- package/core/apps/docs/public/docs/v1.1.0/main.json +0 -12576
- package/core/apps/docs/public/docs/v1.1.2/guides.json +0 -650
- package/core/apps/docs/public/docs/v1.1.2/main.json +0 -13239
- package/core/apps/docs/public/docs/v1.1.3/guides.json +0 -650
- package/core/apps/docs/public/docs/v1.1.3/main.json +0 -13239
- package/core/apps/docs/public/docs/v1.1.4/guides.json +0 -708
- package/core/apps/docs/public/docs/v1.1.4/main.json +0 -13231
- package/core/apps/docs/public/docs/v1.1.5/guides.json +0 -1035
- package/core/apps/docs/public/docs/v1.1.5/main.json +0 -13838
- package/core/apps/docs/public/docs/v1.1.6/guides.json +0 -1041
- package/core/apps/docs/public/docs/v1.1.6/main.json +0 -14313
- package/core/apps/docs/public/docs/v1.1.8/guides.json +0 -1047
- package/core/apps/docs/public/docs/v1.1.8/main.json +0 -14421
- package/core/apps/docs/public/docs/v1.1.9/guides.json +0 -1047
- package/core/apps/docs/public/docs/v1.1.9/main.json +0 -14421
- package/core/apps/docs/public/docs/v1.2.0/guides.json +0 -1212
- package/core/apps/docs/public/docs/v1.2.0/main.json +0 -14663
- package/core/apps/docs/public/docs/v1.2.1/guides.json +0 -1293
- package/core/apps/docs/public/docs/v1.2.1/main.json +0 -14828
- package/core/apps/docs/public/docs/v1.2.2/guides.json +0 -1293
- package/core/apps/docs/public/docs/v1.2.2/main.json +0 -15025
- package/core/apps/docs/public/docs/v1.2.3/guides.json +0 -1420
- package/core/apps/docs/public/docs/v1.2.3/main.json +0 -14954
- package/core/apps/docs/public/docs/v1.2.4/guides.json +0 -1420
- package/core/apps/docs/public/docs/v1.2.4/main.json +0 -14981
- package/core/apps/docs/public/docs/versions.json +0 -24
- package/core/apps/docs/public/flux.png +0 -0
- package/core/apps/docs/public/locales/en.json +0 -50
- package/core/apps/docs/public/locales/guides-en.json +0 -512
- package/core/apps/docs/public/robots.txt +0 -4
- package/core/apps/docs/public/sitemap.xml +0 -33
- package/core/apps/docs/src/App.vue +0 -538
- package/core/apps/docs/src/components/ApiCategorySection.vue +0 -42
- package/core/apps/docs/src/components/ApiDiscordCompat.vue +0 -65
- package/core/apps/docs/src/components/ApiEndpointCard.vue +0 -313
- package/core/apps/docs/src/components/ApiSchemaBlock.vue +0 -131
- package/core/apps/docs/src/components/CodeBlock.vue +0 -177
- package/core/apps/docs/src/components/CommunityCallout.vue +0 -90
- package/core/apps/docs/src/components/ConstructorSection.vue +0 -82
- package/core/apps/docs/src/components/DocDescription.vue +0 -40
- package/core/apps/docs/src/components/FluxerLogo.vue +0 -3
- package/core/apps/docs/src/components/Footer.vue +0 -106
- package/core/apps/docs/src/components/GuideCodeBlock.vue +0 -102
- package/core/apps/docs/src/components/GuideDiscordCompat.vue +0 -77
- package/core/apps/docs/src/components/GuideDiscordCompatCallout.vue +0 -83
- package/core/apps/docs/src/components/GuideTable.vue +0 -77
- package/core/apps/docs/src/components/GuideTip.vue +0 -38
- package/core/apps/docs/src/components/MethodsSection.vue +0 -195
- package/core/apps/docs/src/components/ParamsTable.vue +0 -70
- package/core/apps/docs/src/components/PropertiesSection.vue +0 -143
- package/core/apps/docs/src/components/SearchBar.vue +0 -76
- package/core/apps/docs/src/components/SearchModal.vue +0 -361
- package/core/apps/docs/src/components/SidebarNav.vue +0 -225
- package/core/apps/docs/src/components/SponsorBanner.vue +0 -153
- package/core/apps/docs/src/components/TypeSignature.vue +0 -187
- package/core/apps/docs/src/components/VersionPicker.vue +0 -191
- package/core/apps/docs/src/composables/useSearchIndex.ts +0 -144
- package/core/apps/docs/src/composables/useVersionedPath.ts +0 -20
- package/core/apps/docs/src/data/apiEndpoints.ts +0 -1073
- package/core/apps/docs/src/data/changelog.ts +0 -717
- package/core/apps/docs/src/data/guides.ts +0 -2362
- package/core/apps/docs/src/env.d.ts +0 -7
- package/core/apps/docs/src/locales/guides-en.json +0 -512
- package/core/apps/docs/src/main.ts +0 -27
- package/core/apps/docs/src/pages/ApiReferenceLayout.vue +0 -175
- package/core/apps/docs/src/pages/ApiReferencePage.vue +0 -128
- package/core/apps/docs/src/pages/Changelog.vue +0 -288
- package/core/apps/docs/src/pages/ClassPage.vue +0 -319
- package/core/apps/docs/src/pages/ClassesList.vue +0 -100
- package/core/apps/docs/src/pages/DocsLayout.vue +0 -127
- package/core/apps/docs/src/pages/GuidePage.vue +0 -279
- package/core/apps/docs/src/pages/GuidesIndex.vue +0 -166
- package/core/apps/docs/src/pages/GuidesLayout.vue +0 -245
- package/core/apps/docs/src/pages/Home.vue +0 -125
- package/core/apps/docs/src/pages/NotFound.vue +0 -57
- package/core/apps/docs/src/pages/TypedefPage.vue +0 -230
- package/core/apps/docs/src/pages/TypedefsList.vue +0 -168
- package/core/apps/docs/src/pages/VersionLayout.vue +0 -15
- package/core/apps/docs/src/router.ts +0 -73
- package/core/apps/docs/src/stores/docs.ts +0 -54
- package/core/apps/docs/src/stores/guides.ts +0 -53
- package/core/apps/docs/src/stores/version.ts +0 -67
- package/core/apps/docs/src/styles/main.css +0 -278
- package/core/apps/docs/src/styles/prism.css +0 -95
- package/core/apps/docs/src/types/doc-schema.ts +0 -112
- package/core/apps/docs/tsconfig.json +0 -17
- package/core/apps/docs/tsconfig.node.json +0 -10
- package/core/apps/docs/vite.config.d.ts +0 -2
- package/core/apps/docs/vite.config.js +0 -26
- package/core/apps/docs/vite.config.ts +0 -28
- package/core/apps/docs-vitepress/.vitepress/config.ts +0 -141
- package/core/apps/docs-vitepress/api-data/latest/main.json +0 -15035
- package/core/apps/docs-vitepress/api-data/v1.2.4/main.json +0 -15035
- package/core/apps/docs-vitepress/api-data/versions.json +0 -6
- package/core/apps/docs-vitepress/index.md +0 -15
- package/core/apps/docs-vitepress/package-lock.json +0 -2924
- package/core/apps/docs-vitepress/package.json +0 -20
- package/core/apps/docs-vitepress/public/CNAME +0 -1
- package/core/apps/docs-vitepress/scripts/generate-api.ts +0 -243
- package/core/apps/docs-vitepress/scripts/migrate-guides.ts +0 -129
- package/core/apps/docs-vitepress/tsconfig.json +0 -11
- package/core/apps/docs-vitepress/v/latest/guides/attachments-by-url.md +0 -57
- package/core/apps/docs-vitepress/v/latest/guides/attachments.md +0 -62
- package/core/apps/docs-vitepress/v/latest/guides/basic-bot.md +0 -49
- package/core/apps/docs-vitepress/v/latest/guides/channels.md +0 -180
- package/core/apps/docs-vitepress/v/latest/guides/deprecated-apis.md +0 -58
- package/core/apps/docs-vitepress/v/latest/guides/discord-js-compatibility.md +0 -42
- package/core/apps/docs-vitepress/v/latest/guides/editing-embeds.md +0 -65
- package/core/apps/docs-vitepress/v/latest/guides/embed-media.md +0 -87
- package/core/apps/docs-vitepress/v/latest/guides/embeds.md +0 -166
- package/core/apps/docs-vitepress/v/latest/guides/emojis.md +0 -77
- package/core/apps/docs-vitepress/v/latest/guides/events.md +0 -202
- package/core/apps/docs-vitepress/v/latest/guides/gifs.md +0 -47
- package/core/apps/docs-vitepress/v/latest/guides/installation.md +0 -10
- package/core/apps/docs-vitepress/v/latest/guides/moderation.md +0 -89
- package/core/apps/docs-vitepress/v/latest/guides/permissions.md +0 -130
- package/core/apps/docs-vitepress/v/latest/guides/prefix-commands.md +0 -41
- package/core/apps/docs-vitepress/v/latest/guides/profile-urls.md +0 -58
- package/core/apps/docs-vitepress/v/latest/guides/reactions.md +0 -69
- package/core/apps/docs-vitepress/v/latest/guides/roles.md +0 -130
- package/core/apps/docs-vitepress/v/latest/guides/sending-without-reply.md +0 -172
- package/core/apps/docs-vitepress/v/latest/guides/voice.md +0 -109
- package/core/apps/docs-vitepress/v/latest/guides/wait-for-guilds.md +0 -37
- package/core/apps/docs-vitepress/v/latest/guides/webhook-attachments-embeds.md +0 -73
- package/core/apps/docs-vitepress/v/latest/guides/webhooks.md +0 -131
- package/core/eslint.config.js +0 -80
- package/core/examples/.env.example +0 -22
- package/core/examples/README.md +0 -68
- package/core/examples/first-steps-bot.js +0 -118
- package/core/examples/minimal-bot.js +0 -17
- package/core/examples/moderation-bot.js +0 -209
- package/core/examples/package.json +0 -14
- package/core/examples/ping-bot.js +0 -1146
- package/core/examples/reaction-bot.js +0 -70
- package/core/examples/reaction-roles-bot.js +0 -140
- package/core/examples/webhook-bot.js +0 -239
- package/core/flux.png +0 -0
- package/core/package.json +0 -78
- package/core/packages/builders/package.json +0 -51
- package/core/packages/builders/src/index.ts +0 -13
- package/core/packages/builders/src/messages/AttachmentBuilder.test.ts +0 -79
- package/core/packages/builders/src/messages/AttachmentBuilder.ts +0 -69
- package/core/packages/builders/src/messages/EmbedBuilder.test.ts +0 -266
- package/core/packages/builders/src/messages/EmbedBuilder.ts +0 -239
- package/core/packages/builders/src/messages/MessagePayload.test.ts +0 -118
- package/core/packages/builders/src/messages/MessagePayload.ts +0 -122
- package/core/packages/builders/tsconfig.json +0 -9
- package/core/packages/builders/tsup.config.ts +0 -9
- package/core/packages/builders/vitest.config.ts +0 -9
- package/core/packages/collection/package.json +0 -47
- package/core/packages/collection/src/Collection.test.ts +0 -232
- package/core/packages/collection/src/Collection.ts +0 -196
- package/core/packages/collection/src/index.ts +0 -1
- package/core/packages/collection/tsconfig.json +0 -9
- package/core/packages/collection/tsup.config.ts +0 -9
- package/core/packages/collection/vitest.config.ts +0 -9
- package/core/packages/docgen/package.json +0 -26
- package/core/packages/docgen/src/extract.ts +0 -262
- package/core/packages/docgen/src/formatType.ts +0 -24
- package/core/packages/docgen/src/index.ts +0 -103
- package/core/packages/docgen/src/schema.ts +0 -100
- package/core/packages/docgen/src/visitor.ts +0 -147
- package/core/packages/docgen/tsconfig.json +0 -9
- package/core/packages/docgen/tsup.config.ts +0 -9
- package/core/packages/fluxer-core/README.md +0 -26
- package/core/packages/fluxer-core/package.json +0 -60
- package/core/packages/fluxer-core/src/client/ChannelManager.ts +0 -143
- package/core/packages/fluxer-core/src/client/Client.gateway.test.ts +0 -84
- package/core/packages/fluxer-core/src/client/Client.resolveEmoji.test.ts +0 -45
- package/core/packages/fluxer-core/src/client/Client.ts +0 -558
- package/core/packages/fluxer-core/src/client/ClientUser.ts +0 -40
- package/core/packages/fluxer-core/src/client/EventHandlerRegistry.ts +0 -469
- package/core/packages/fluxer-core/src/client/GuildManager.ts +0 -79
- package/core/packages/fluxer-core/src/client/GuildMemberManager.ts +0 -91
- package/core/packages/fluxer-core/src/client/MessageManager.ts +0 -58
- package/core/packages/fluxer-core/src/client/UsersManager.ts +0 -122
- package/core/packages/fluxer-core/src/errors/ErrorCodes.test.ts +0 -19
- package/core/packages/fluxer-core/src/errors/ErrorCodes.ts +0 -12
- package/core/packages/fluxer-core/src/errors/FluxerError.test.ts +0 -32
- package/core/packages/fluxer-core/src/errors/FluxerError.ts +0 -15
- package/core/packages/fluxer-core/src/index.ts +0 -85
- package/core/packages/fluxer-core/src/structures/Base.ts +0 -7
- package/core/packages/fluxer-core/src/structures/Channel.ts +0 -508
- package/core/packages/fluxer-core/src/structures/Guild.test.ts +0 -189
- package/core/packages/fluxer-core/src/structures/Guild.ts +0 -734
- package/core/packages/fluxer-core/src/structures/GuildBan.ts +0 -35
- package/core/packages/fluxer-core/src/structures/GuildEmoji.ts +0 -57
- package/core/packages/fluxer-core/src/structures/GuildMember.test.ts +0 -203
- package/core/packages/fluxer-core/src/structures/GuildMember.ts +0 -213
- package/core/packages/fluxer-core/src/structures/GuildMemberRoleManager.ts +0 -121
- package/core/packages/fluxer-core/src/structures/GuildSticker.ts +0 -56
- package/core/packages/fluxer-core/src/structures/Invite.test.ts +0 -103
- package/core/packages/fluxer-core/src/structures/Invite.ts +0 -121
- package/core/packages/fluxer-core/src/structures/Message.test.ts +0 -109
- package/core/packages/fluxer-core/src/structures/Message.ts +0 -397
- package/core/packages/fluxer-core/src/structures/MessageReaction.ts +0 -72
- package/core/packages/fluxer-core/src/structures/PartialMessage.ts +0 -12
- package/core/packages/fluxer-core/src/structures/Role.test.ts +0 -77
- package/core/packages/fluxer-core/src/structures/Role.ts +0 -112
- package/core/packages/fluxer-core/src/structures/User.test.ts +0 -110
- package/core/packages/fluxer-core/src/structures/User.ts +0 -109
- package/core/packages/fluxer-core/src/structures/Webhook.test.ts +0 -109
- package/core/packages/fluxer-core/src/structures/Webhook.ts +0 -258
- package/core/packages/fluxer-core/src/util/Constants.test.ts +0 -16
- package/core/packages/fluxer-core/src/util/Constants.ts +0 -7
- package/core/packages/fluxer-core/src/util/Events.ts +0 -46
- package/core/packages/fluxer-core/src/util/MessageCollector.ts +0 -87
- package/core/packages/fluxer-core/src/util/Options.ts +0 -33
- package/core/packages/fluxer-core/src/util/ReactionCollector.ts +0 -116
- package/core/packages/fluxer-core/src/util/cdn.test.ts +0 -108
- package/core/packages/fluxer-core/src/util/cdn.ts +0 -130
- package/core/packages/fluxer-core/src/util/guildUtils.ts +0 -33
- package/core/packages/fluxer-core/src/util/messageUtils.test.ts +0 -74
- package/core/packages/fluxer-core/src/util/messageUtils.ts +0 -119
- package/core/packages/fluxer-core/src/util/permissions.test.ts +0 -95
- package/core/packages/fluxer-core/src/util/permissions.ts +0 -43
- package/core/packages/fluxer-core/tsconfig.json +0 -9
- package/core/packages/fluxer-core/tsup.config.ts +0 -9
- package/core/packages/fluxer-core/vitest.config.ts +0 -9
- package/core/packages/rest/package.json +0 -52
- package/core/packages/rest/src/REST.test.ts +0 -64
- package/core/packages/rest/src/REST.ts +0 -90
- package/core/packages/rest/src/RateLimitManager.test.ts +0 -71
- package/core/packages/rest/src/RateLimitManager.ts +0 -60
- package/core/packages/rest/src/RequestManager.test.ts +0 -87
- package/core/packages/rest/src/RequestManager.ts +0 -172
- package/core/packages/rest/src/errors/FluxerAPIError.test.ts +0 -57
- package/core/packages/rest/src/errors/FluxerAPIError.ts +0 -21
- package/core/packages/rest/src/errors/HTTPError.test.ts +0 -55
- package/core/packages/rest/src/errors/HTTPError.ts +0 -25
- package/core/packages/rest/src/errors/RateLimitError.test.ts +0 -41
- package/core/packages/rest/src/errors/RateLimitError.ts +0 -15
- package/core/packages/rest/src/errors/index.ts +0 -3
- package/core/packages/rest/src/index.ts +0 -6
- package/core/packages/rest/src/utils/constants.test.ts +0 -31
- package/core/packages/rest/src/utils/constants.ts +0 -5
- package/core/packages/rest/src/utils/files.test.ts +0 -37
- package/core/packages/rest/src/utils/files.ts +0 -75
- package/core/packages/rest/tsconfig.json +0 -9
- package/core/packages/rest/tsup.config.ts +0 -9
- package/core/packages/rest/vitest.config.ts +0 -9
- package/core/packages/types/package.json +0 -46
- package/core/packages/types/src/api/ban.ts +0 -8
- package/core/packages/types/src/api/channel.ts +0 -65
- package/core/packages/types/src/api/embed.ts +0 -82
- package/core/packages/types/src/api/emoji.ts +0 -12
- package/core/packages/types/src/api/errors.ts +0 -68
- package/core/packages/types/src/api/gateway.ts +0 -14
- package/core/packages/types/src/api/guild.ts +0 -123
- package/core/packages/types/src/api/index.ts +0 -15
- package/core/packages/types/src/api/instance.ts +0 -32
- package/core/packages/types/src/api/interaction.ts +0 -26
- package/core/packages/types/src/api/invite.ts +0 -28
- package/core/packages/types/src/api/message.ts +0 -140
- package/core/packages/types/src/api/role.ts +0 -41
- package/core/packages/types/src/api/sticker.ts +0 -14
- package/core/packages/types/src/api/user.ts +0 -79
- package/core/packages/types/src/api/webhook.ts +0 -41
- package/core/packages/types/src/common/index.ts +0 -1
- package/core/packages/types/src/common/snowflake.test.ts +0 -9
- package/core/packages/types/src/common/snowflake.ts +0 -8
- package/core/packages/types/src/gateway/events.ts +0 -189
- package/core/packages/types/src/gateway/index.ts +0 -3
- package/core/packages/types/src/gateway/opcodes.ts +0 -17
- package/core/packages/types/src/gateway/payloads.ts +0 -481
- package/core/packages/types/src/index.ts +0 -4
- package/core/packages/types/src/rest/index.ts +0 -1
- package/core/packages/types/src/rest/routes.test.ts +0 -169
- package/core/packages/types/src/rest/routes.ts +0 -109
- package/core/packages/types/tsconfig.json +0 -9
- package/core/packages/types/tsup.config.ts +0 -9
- package/core/packages/types/vitest.config.ts +0 -9
- package/core/packages/util/package.json +0 -51
- package/core/packages/util/src/BitField.test.ts +0 -96
- package/core/packages/util/src/BitField.ts +0 -105
- package/core/packages/util/src/MessageFlagsBitField.test.ts +0 -42
- package/core/packages/util/src/MessageFlagsBitField.ts +0 -20
- package/core/packages/util/src/PermissionsBitField.test.ts +0 -79
- package/core/packages/util/src/PermissionsBitField.ts +0 -97
- package/core/packages/util/src/SnowflakeUtil.test.ts +0 -69
- package/core/packages/util/src/SnowflakeUtil.ts +0 -65
- package/core/packages/util/src/UserFlagsBitField.test.ts +0 -39
- package/core/packages/util/src/UserFlagsBitField.ts +0 -48
- package/core/packages/util/src/deprecation.test.ts +0 -44
- package/core/packages/util/src/deprecation.ts +0 -28
- package/core/packages/util/src/emojiShortcodes.generated.ts +0 -5
- package/core/packages/util/src/emojiShortcodes.test.ts +0 -41
- package/core/packages/util/src/emojiShortcodes.ts +0 -22
- package/core/packages/util/src/formatters.test.ts +0 -65
- package/core/packages/util/src/formatters.ts +0 -35
- package/core/packages/util/src/index.ts +0 -34
- package/core/packages/util/src/resolvers.test.ts +0 -198
- package/core/packages/util/src/resolvers.ts +0 -127
- package/core/packages/util/src/tenorUtils.test.ts +0 -75
- package/core/packages/util/src/tenorUtils.ts +0 -86
- package/core/packages/util/tsconfig.json +0 -9
- package/core/packages/util/tsup.config.ts +0 -9
- package/core/packages/util/vitest.config.ts +0 -9
- package/core/packages/voice/README.md +0 -42
- package/core/packages/voice/package.json +0 -67
- package/core/packages/voice/src/LiveKitRtcConnection.receive.test.ts +0 -24
- package/core/packages/voice/src/LiveKitRtcConnection.ts +0 -1767
- package/core/packages/voice/src/VoiceConnection.ts +0 -413
- package/core/packages/voice/src/VoiceManager.receive.test.ts +0 -61
- package/core/packages/voice/src/VoiceManager.test.ts +0 -44
- package/core/packages/voice/src/VoiceManager.ts +0 -503
- package/core/packages/voice/src/exports.test.ts +0 -38
- package/core/packages/voice/src/index.ts +0 -51
- package/core/packages/voice/src/livekit.test.ts +0 -48
- package/core/packages/voice/src/livekit.ts +0 -33
- package/core/packages/voice/src/mp4box.d.ts +0 -32
- package/core/packages/voice/src/opusUtils.test.ts +0 -29
- package/core/packages/voice/src/opusUtils.ts +0 -86
- package/core/packages/voice/src/streamPreviewPlaceholder.test.ts +0 -16
- package/core/packages/voice/src/streamPreviewPlaceholder.ts +0 -8
- package/core/packages/voice/src/ws.d.ts +0 -1
- package/core/packages/voice/tsconfig.json +0 -5
- package/core/packages/voice/tsup.config.ts +0 -10
- package/core/packages/voice/vitest.config.ts +0 -9
- package/core/packages/ws/package.json +0 -52
- package/core/packages/ws/src/WebSocketManager.ts +0 -130
- package/core/packages/ws/src/WebSocketShard.ts +0 -296
- package/core/packages/ws/src/index.ts +0 -12
- package/core/packages/ws/src/utils/constants.test.ts +0 -46
- package/core/packages/ws/src/utils/constants.ts +0 -22
- package/core/packages/ws/src/utils/getWebSocket.ts +0 -55
- package/core/packages/ws/src/ws.d.ts +0 -10
- package/core/packages/ws/tsconfig.json +0 -9
- package/core/packages/ws/tsup.config.ts +0 -9
- package/core/pnpm-lock.yaml +0 -7033
- package/core/pnpm-workspace.yaml +0 -4
- package/core/scripts/generate-ai-rag.ts +0 -240
- package/core/scripts/generate-docs.ts +0 -143
- package/core/scripts/generate-emoji-shortcodes.ts +0 -58
- package/core/scripts/generate-types.ts +0 -6
- package/core/scripts/publish-ordered.js +0 -63
- package/core/scripts/test-cjs-require.mjs +0 -43
- package/core/scripts/test-esm-imports.mjs +0 -42
- package/core/scripts/test-package-exports.mjs +0 -98
- package/core/scripts/test-smoke.mjs +0 -103
- package/core/tsconfig.json +0 -18
- package/core/turbo.json +0 -30
- package/core/vitest.config.ts +0 -17
- package/core/wrangler.jsonc +0 -9
|
@@ -1,558 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { REST } from '@erinjs/rest';
|
|
3
|
-
import { WebSocketManager } from '@erinjs/ws';
|
|
4
|
-
import {
|
|
5
|
-
APIApplicationCommandInteraction,
|
|
6
|
-
GatewayGuildRoleCreateDispatchData,
|
|
7
|
-
GatewayGuildRoleDeleteDispatchData,
|
|
8
|
-
GatewayGuildRoleUpdateDispatchData,
|
|
9
|
-
GatewayInviteDeleteDispatchData,
|
|
10
|
-
GatewayMessageDeleteBulkDispatchData,
|
|
11
|
-
GatewayTypingStartDispatchData,
|
|
12
|
-
GatewayUserUpdateDispatchData,
|
|
13
|
-
Routes,
|
|
14
|
-
} from '@erinjs/types';
|
|
15
|
-
import { ChannelManager } from './ChannelManager.js';
|
|
16
|
-
import { GuildManager } from './GuildManager.js';
|
|
17
|
-
import { ClientOptions } from '../util/Options.js';
|
|
18
|
-
import { ClientUser } from './ClientUser.js';
|
|
19
|
-
import { Guild } from '../structures/Guild.js';
|
|
20
|
-
import { Channel, GuildChannel } from '../structures/Channel.js';
|
|
21
|
-
import { FluxerError } from '../errors/FluxerError.js';
|
|
22
|
-
import { ErrorCodes } from '../errors/ErrorCodes.js';
|
|
23
|
-
import { Events } from '../util/Events.js';
|
|
24
|
-
import {
|
|
25
|
-
GatewayReceivePayload,
|
|
26
|
-
GatewaySendPayload,
|
|
27
|
-
GatewayVoiceStateUpdateDispatchData,
|
|
28
|
-
GatewayVoiceServerUpdateDispatchData,
|
|
29
|
-
GatewayMessageReactionRemoveEmojiDispatchData,
|
|
30
|
-
GatewayMessageReactionRemoveAllDispatchData,
|
|
31
|
-
GatewayReactionEmoji,
|
|
32
|
-
GatewayGuildEmojisUpdateDispatchData,
|
|
33
|
-
GatewayGuildStickersUpdateDispatchData,
|
|
34
|
-
GatewayGuildIntegrationsUpdateDispatchData,
|
|
35
|
-
GatewayGuildScheduledEventCreateDispatchData,
|
|
36
|
-
GatewayGuildScheduledEventUpdateDispatchData,
|
|
37
|
-
GatewayGuildScheduledEventDeleteDispatchData,
|
|
38
|
-
GatewayChannelPinsUpdateDispatchData,
|
|
39
|
-
GatewayPresenceUpdateDispatchData,
|
|
40
|
-
GatewayWebhooksUpdateDispatchData,
|
|
41
|
-
} from '@erinjs/types';
|
|
42
|
-
import {
|
|
43
|
-
APIChannel,
|
|
44
|
-
APIGuild,
|
|
45
|
-
APIGatewayBotResponse,
|
|
46
|
-
APIMessage,
|
|
47
|
-
APIUser,
|
|
48
|
-
APIUserPartial,
|
|
49
|
-
APIInstance,
|
|
50
|
-
} from '@erinjs/types';
|
|
51
|
-
import {
|
|
52
|
-
emitDeprecationWarning,
|
|
53
|
-
formatEmoji,
|
|
54
|
-
getUnicodeFromShortcode,
|
|
55
|
-
parseEmoji,
|
|
56
|
-
} from '@erinjs/util';
|
|
57
|
-
import { User } from '../structures/User.js';
|
|
58
|
-
import { UsersManager } from './UsersManager.js';
|
|
59
|
-
import { eventHandlers } from './EventHandlerRegistry.js';
|
|
60
|
-
import { normalizeGuildPayload } from '../util/guildUtils';
|
|
61
|
-
import { Message } from '../structures/Message';
|
|
62
|
-
import { PartialMessage } from '../structures/PartialMessage';
|
|
63
|
-
import type { MessageSendOptions } from '../util/messageUtils.js';
|
|
64
|
-
import { MessageReaction } from '../structures/MessageReaction';
|
|
65
|
-
import { GuildMember } from '../structures/GuildMember';
|
|
66
|
-
import { GuildBan } from '../structures/GuildBan';
|
|
67
|
-
import { Invite } from '../structures/Invite';
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Callback parameter types for client events. Use with client.on(Events.X, handler).
|
|
71
|
-
* @see Events
|
|
72
|
-
*/
|
|
73
|
-
export interface ClientEvents {
|
|
74
|
-
[Events.Ready]: [];
|
|
75
|
-
[Events.MessageCreate]: [message: Message];
|
|
76
|
-
[Events.MessageUpdate]: [oldMessage: Message | null, newMessage: Message];
|
|
77
|
-
[Events.MessageDelete]: [message: PartialMessage];
|
|
78
|
-
[Events.MessageReactionAdd]: [
|
|
79
|
-
reaction: MessageReaction,
|
|
80
|
-
user: User,
|
|
81
|
-
messageId: string,
|
|
82
|
-
channelId: string,
|
|
83
|
-
emoji: GatewayReactionEmoji,
|
|
84
|
-
userId: string,
|
|
85
|
-
];
|
|
86
|
-
[Events.MessageReactionRemove]: [
|
|
87
|
-
reaction: MessageReaction,
|
|
88
|
-
user: User,
|
|
89
|
-
messageId: string,
|
|
90
|
-
channelId: string,
|
|
91
|
-
emoji: GatewayReactionEmoji,
|
|
92
|
-
userId: string,
|
|
93
|
-
];
|
|
94
|
-
[Events.MessageReactionRemoveAll]: [data: GatewayMessageReactionRemoveAllDispatchData];
|
|
95
|
-
[Events.MessageReactionRemoveEmoji]: [data: GatewayMessageReactionRemoveEmojiDispatchData];
|
|
96
|
-
[Events.InteractionCreate]: [interaction: APIApplicationCommandInteraction];
|
|
97
|
-
[Events.GuildCreate]: [guild: Guild];
|
|
98
|
-
[Events.GuildUpdate]: [oldGuild: Guild, newGuild: Guild];
|
|
99
|
-
[Events.GuildDelete]: [guild: Guild];
|
|
100
|
-
[Events.ChannelCreate]: [channel: GuildChannel];
|
|
101
|
-
[Events.ChannelUpdate]: [oldChannel: Channel, newChannel: Channel];
|
|
102
|
-
[Events.ChannelDelete]: [channel: Channel];
|
|
103
|
-
[Events.GuildMemberAdd]: [member: GuildMember];
|
|
104
|
-
[Events.GuildMemberUpdate]: [oldMember: GuildMember, newMember: GuildMember];
|
|
105
|
-
[Events.GuildMemberRemove]: [member: GuildMember];
|
|
106
|
-
[Events.VoiceStateUpdate]: [data: GatewayVoiceStateUpdateDispatchData];
|
|
107
|
-
[Events.VoiceServerUpdate]: [data: GatewayVoiceServerUpdateDispatchData];
|
|
108
|
-
[Events.VoiceStatesSync]: [
|
|
109
|
-
data: { guildId: string; voiceStates: Array<{ user_id: string; channel_id: string | null }> },
|
|
110
|
-
];
|
|
111
|
-
[Events.MessageDeleteBulk]: [data: GatewayMessageDeleteBulkDispatchData];
|
|
112
|
-
[Events.GuildBanAdd]: [ban: GuildBan];
|
|
113
|
-
[Events.GuildBanRemove]: [ban: GuildBan];
|
|
114
|
-
[Events.GuildEmojisUpdate]: [data: GatewayGuildEmojisUpdateDispatchData];
|
|
115
|
-
[Events.GuildStickersUpdate]: [data: GatewayGuildStickersUpdateDispatchData];
|
|
116
|
-
[Events.GuildIntegrationsUpdate]: [data: GatewayGuildIntegrationsUpdateDispatchData];
|
|
117
|
-
[Events.GuildRoleCreate]: [data: GatewayGuildRoleCreateDispatchData];
|
|
118
|
-
[Events.GuildRoleUpdate]: [data: GatewayGuildRoleUpdateDispatchData];
|
|
119
|
-
[Events.GuildRoleDelete]: [data: GatewayGuildRoleDeleteDispatchData];
|
|
120
|
-
[Events.GuildScheduledEventCreate]: [data: GatewayGuildScheduledEventCreateDispatchData];
|
|
121
|
-
[Events.GuildScheduledEventUpdate]: [data: GatewayGuildScheduledEventUpdateDispatchData];
|
|
122
|
-
[Events.GuildScheduledEventDelete]: [data: GatewayGuildScheduledEventDeleteDispatchData];
|
|
123
|
-
[Events.ChannelPinsUpdate]: [data: GatewayChannelPinsUpdateDispatchData];
|
|
124
|
-
[Events.InviteCreate]: [invite: Invite];
|
|
125
|
-
[Events.InviteDelete]: [data: GatewayInviteDeleteDispatchData];
|
|
126
|
-
[Events.TypingStart]: [data: GatewayTypingStartDispatchData];
|
|
127
|
-
[Events.UserUpdate]: [data: GatewayUserUpdateDispatchData];
|
|
128
|
-
[Events.PresenceUpdate]: [data: GatewayPresenceUpdateDispatchData];
|
|
129
|
-
[Events.WebhooksUpdate]: [data: GatewayWebhooksUpdateDispatchData];
|
|
130
|
-
[Events.Resumed]: [];
|
|
131
|
-
[Events.Error]: [error: Error];
|
|
132
|
-
[Events.Debug]: [message: string];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Typed event handler methods. Use client.events.MessageReactionAdd((reaction, user, messageId, channelId, emoji, userId) => {...}) or client.on(Events.MessageReactionAdd, ...). */
|
|
136
|
-
export type ClientEventMethods = {
|
|
137
|
-
[K in keyof typeof Events]: (cb: (...args: ClientEvents[(typeof Events)[K]]) => void) => Client;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
function createEventMethods(client: Client): ClientEventMethods {
|
|
141
|
-
const result: Record<string, (cb: (...args: unknown[]) => void) => Client> = {};
|
|
142
|
-
for (const key of Object.keys(Events) as (keyof typeof Events)[]) {
|
|
143
|
-
const eventName = Events[key];
|
|
144
|
-
result[key] = (cb) => {
|
|
145
|
-
client.on(eventName, cb as (...args: unknown[]) => void);
|
|
146
|
-
return client;
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
return result as ClientEventMethods;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** Main Fluxer bot client. Connects to the gateway, emits events, and provides REST access. */
|
|
153
|
-
export class Client extends EventEmitter {
|
|
154
|
-
readonly rest: REST;
|
|
155
|
-
readonly guilds = new GuildManager(this);
|
|
156
|
-
readonly channels = new ChannelManager(this);
|
|
157
|
-
readonly users = new UsersManager(this);
|
|
158
|
-
/** Typed event handlers. Use client.events.MessageReactionAdd((reaction, user, messageId, channelId, emoji, userId) => {...}) or client.on(Events.MessageReactionAdd, ...). */
|
|
159
|
-
readonly events: ClientEventMethods;
|
|
160
|
-
/** The authenticated bot user. Null until READY is received. */
|
|
161
|
-
user: ClientUser | null = null;
|
|
162
|
-
/** Timestamp when the client became ready. Null until READY is received. */
|
|
163
|
-
readyAt: Date | null = null;
|
|
164
|
-
private _ws: WebSocketManager | null = null;
|
|
165
|
-
/** When waitForGuilds, set of guild IDs we're waiting for GUILD_CREATE on. Null when not waiting. */
|
|
166
|
-
_pendingGuildIds: Set<string> | null = null;
|
|
167
|
-
/** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
|
|
168
|
-
private _guildStreamSettleTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
169
|
-
/** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
|
|
170
|
-
private _messageCaches: Map<string, Map<string, APIMessage>> | null = null;
|
|
171
|
-
|
|
172
|
-
/** @param options - Token, REST config, WebSocket, presence, etc. */
|
|
173
|
-
constructor(public readonly options: ClientOptions = {}) {
|
|
174
|
-
super();
|
|
175
|
-
this.events = createEventMethods(this);
|
|
176
|
-
Object.defineProperty(this.channels, 'cache', {
|
|
177
|
-
get: () => this.channels,
|
|
178
|
-
configurable: true,
|
|
179
|
-
});
|
|
180
|
-
Object.defineProperty(this.guilds, 'cache', {
|
|
181
|
-
get: () => this.guilds,
|
|
182
|
-
configurable: true,
|
|
183
|
-
});
|
|
184
|
-
Object.defineProperty(this.users, 'cache', {
|
|
185
|
-
get: () => this.users,
|
|
186
|
-
configurable: true,
|
|
187
|
-
});
|
|
188
|
-
this.rest = new REST({
|
|
189
|
-
api: options.rest?.api ?? 'https://api.fluxer.app',
|
|
190
|
-
version: options.rest?.version ?? '1',
|
|
191
|
-
...options.rest,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Resolve an emoji argument to the API format (unicode or "name:id").
|
|
197
|
-
* Supports: <:name:id>, :name:, name:id, { name, id }, unicode.
|
|
198
|
-
* When id is missing (e.g. :name:), fetches guild emojis if guildId provided.
|
|
199
|
-
* When reacting in a guild channel, custom emojis must be from that guild.
|
|
200
|
-
* @param emoji - Emoji string or object
|
|
201
|
-
* @param guildId - Guild ID for resolving custom emoji by name (required when id is missing)
|
|
202
|
-
* @returns API-formatted string for reactions
|
|
203
|
-
*/
|
|
204
|
-
async resolveEmoji(
|
|
205
|
-
emoji: string | { name: string; id?: string; animated?: boolean },
|
|
206
|
-
guildId?: string | null,
|
|
207
|
-
): Promise<string> {
|
|
208
|
-
if (typeof emoji === 'object' && emoji.id) {
|
|
209
|
-
if (guildId) {
|
|
210
|
-
await this.assertEmojiInGuild(emoji.id, guildId);
|
|
211
|
-
}
|
|
212
|
-
return formatEmoji({ name: emoji.name, id: emoji.id as string, animated: emoji.animated });
|
|
213
|
-
}
|
|
214
|
-
const parsed = parseEmoji(
|
|
215
|
-
typeof emoji === 'string' ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name,
|
|
216
|
-
);
|
|
217
|
-
if (!parsed) throw new Error('Invalid emoji');
|
|
218
|
-
if (parsed.id) {
|
|
219
|
-
if (guildId) {
|
|
220
|
-
await this.assertEmojiInGuild(parsed.id, guildId);
|
|
221
|
-
}
|
|
222
|
-
return formatEmoji(parsed);
|
|
223
|
-
}
|
|
224
|
-
// Unicode emoji: name has non-ASCII or isn't a custom shortcode — return raw, route will encode
|
|
225
|
-
if (!/^\w+$/.test(parsed.name)) return parsed.name;
|
|
226
|
-
// Known Unicode shortcode (e.g. :red_square:, :light_blue_heart:) — resolve and return raw unicode
|
|
227
|
-
const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
|
|
228
|
-
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
229
|
-
if (guildId) {
|
|
230
|
-
const emojis = await this.rest.get(Routes.guildEmojis(guildId));
|
|
231
|
-
const list = (Array.isArray(emojis) ? emojis : Object.values(emojis ?? {})) as Array<{
|
|
232
|
-
id: string;
|
|
233
|
-
name?: string;
|
|
234
|
-
animated?: boolean;
|
|
235
|
-
}>;
|
|
236
|
-
const found = list.find((e) => e.name && e.name.toLowerCase() === parsed!.name.toLowerCase());
|
|
237
|
-
if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
|
|
238
|
-
throw new Error(
|
|
239
|
-
`Custom emoji ":${parsed.name}:" not found in guild. Use name:id or <:name:id> format.`,
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
if (/^\w+$/.test(parsed.name)) {
|
|
243
|
-
throw new Error(
|
|
244
|
-
`Custom emoji ":${parsed.name}:" requires guild context. Use message.react() in a guild channel, or pass guildId to client.resolveEmoji().`,
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
return parsed.name;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Asserts that a custom emoji (by id) belongs to the given guild.
|
|
252
|
-
* Used when reacting in guild channels to reject emojis from other servers.
|
|
253
|
-
* @throws FluxerError with EMOJI_NOT_IN_GUILD if the emoji is not in the guild
|
|
254
|
-
*/
|
|
255
|
-
private async assertEmojiInGuild(emojiId: string, guildId: string): Promise<void> {
|
|
256
|
-
const emojis = await this.rest.get(Routes.guildEmojis(guildId));
|
|
257
|
-
const list = (Array.isArray(emojis) ? emojis : Object.values(emojis ?? {})) as Array<{
|
|
258
|
-
id: string;
|
|
259
|
-
}>;
|
|
260
|
-
const found = list.some((e) => e.id === emojiId);
|
|
261
|
-
if (!found) {
|
|
262
|
-
throw new FluxerError('Custom emoji is from another server. Use an emoji from this server.', {
|
|
263
|
-
code: ErrorCodes.EmojiNotInGuild,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Fetch instance discovery info (API URL, gateway URL, features).
|
|
270
|
-
* Uses canonical GET /.well-known/fluxer.
|
|
271
|
-
* Does not require authentication.
|
|
272
|
-
*/
|
|
273
|
-
async fetchInstance(): Promise<APIInstance> {
|
|
274
|
-
return this.rest.get<APIInstance>(Routes.instanceDiscovery(), { auth: false });
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Fetch gateway connection metadata (WebSocket URL, recommended shards, session limits).
|
|
279
|
-
* Uses authenticated GET /gateway/bot.
|
|
280
|
-
*/
|
|
281
|
-
async fetchGatewayInfo(): Promise<APIGatewayBotResponse> {
|
|
282
|
-
return this.rest.get<APIGatewayBotResponse>(Routes.gatewayBot());
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Fetch a message by channel and message ID. Use when you have IDs (e.g. from a DB).
|
|
287
|
-
* @param channelId - Snowflake of the channel
|
|
288
|
-
* @param messageId - Snowflake of the message
|
|
289
|
-
* @returns The message
|
|
290
|
-
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
291
|
-
* @deprecated Use channel.messages.fetch(messageId). For IDs-only: (await client.channels.resolve(channelId))?.messages?.fetch(messageId)
|
|
292
|
-
* @example
|
|
293
|
-
* const channel = await client.channels.resolve(channelId);
|
|
294
|
-
* const message = await channel?.messages?.fetch(messageId);
|
|
295
|
-
*/
|
|
296
|
-
async fetchMessage(channelId: string, messageId: string): Promise<Message> {
|
|
297
|
-
emitDeprecationWarning(
|
|
298
|
-
'Client.fetchMessage()',
|
|
299
|
-
'Use channel.messages.fetch(messageId). For IDs-only: (await client.channels.resolve(channelId))?.messages?.fetch(messageId)',
|
|
300
|
-
);
|
|
301
|
-
return this.channels.fetchMessage(channelId, messageId);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Send a message to any channel by ID. Shorthand for client.channels.send().
|
|
306
|
-
* Works even when the channel is not cached.
|
|
307
|
-
* @deprecated Use client.channels.send(channelId, payload).
|
|
308
|
-
*/
|
|
309
|
-
async sendToChannel(channelId: string, payload: string | MessageSendOptions): Promise<Message> {
|
|
310
|
-
emitDeprecationWarning(
|
|
311
|
-
'Client.sendToChannel()',
|
|
312
|
-
'Use client.channels.send(channelId, payload).',
|
|
313
|
-
);
|
|
314
|
-
return this.channels.send(channelId, payload);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Get the message cache for a channel. Returns null if message caching is disabled.
|
|
319
|
-
* Used by MessageManager.get() and event handlers.
|
|
320
|
-
* @internal
|
|
321
|
-
*/
|
|
322
|
-
_getMessageCache(channelId: string): Map<string, APIMessage> | null {
|
|
323
|
-
const limit = this.options.cache?.messages ?? 0;
|
|
324
|
-
if (limit <= 0) return null;
|
|
325
|
-
if (!this._messageCaches) this._messageCaches = new Map();
|
|
326
|
-
let cache = this._messageCaches.get(channelId);
|
|
327
|
-
if (!cache) {
|
|
328
|
-
cache = new Map();
|
|
329
|
-
this._messageCaches.set(channelId, cache);
|
|
330
|
-
}
|
|
331
|
-
return cache;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Add a message to the channel cache. Evicts oldest (FIFO) when over limit.
|
|
336
|
-
* @internal
|
|
337
|
-
*/
|
|
338
|
-
_addMessageToCache(channelId: string, data: APIMessage): void {
|
|
339
|
-
const cache = this._getMessageCache(channelId);
|
|
340
|
-
if (!cache) return;
|
|
341
|
-
const limit = this.options.cache?.messages ?? 0;
|
|
342
|
-
if (limit > 0 && cache.size >= limit && !cache.has(data.id)) {
|
|
343
|
-
const firstKey = cache.keys().next().value;
|
|
344
|
-
if (firstKey !== undefined) cache.delete(firstKey);
|
|
345
|
-
}
|
|
346
|
-
cache.set(data.id, { ...data });
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Remove a message from the channel cache.
|
|
351
|
-
* @internal
|
|
352
|
-
*/
|
|
353
|
-
_removeMessageFromCache(channelId: string, messageId: string): void {
|
|
354
|
-
this._messageCaches?.get(channelId)?.delete(messageId);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Get or create a User from API data. Caches in client.users.
|
|
359
|
-
* Updates existing user's username, avatar, etc. when fresh data is provided.
|
|
360
|
-
*/
|
|
361
|
-
getOrCreateUser(data: APIUserPartial): User {
|
|
362
|
-
const existing = this.users.get(data.id);
|
|
363
|
-
if (existing) {
|
|
364
|
-
existing._patch(data);
|
|
365
|
-
return existing;
|
|
366
|
-
}
|
|
367
|
-
const user = new User(this, data);
|
|
368
|
-
this.users.set(user.id, user);
|
|
369
|
-
return user;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/** WebSocket manager. Throws if not logged in. */
|
|
373
|
-
get ws(): WebSocketManager {
|
|
374
|
-
if (!this._ws) throw new Error('Client is not logged in');
|
|
375
|
-
return this._ws;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Send a payload to the gateway (e.g. Voice State Update).
|
|
380
|
-
* @param shardId - Shard ID (use 0 for single-shard)
|
|
381
|
-
* @param payload - Gateway payload to send
|
|
382
|
-
*/
|
|
383
|
-
sendToGateway(shardId: number, payload: GatewaySendPayload): void {
|
|
384
|
-
this.ws.send(shardId, payload);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
private async handleDispatch(payload: GatewayReceivePayload): Promise<void> {
|
|
388
|
-
if (payload.op !== 0 || !payload.t) return;
|
|
389
|
-
const { t: event, d } = payload;
|
|
390
|
-
try {
|
|
391
|
-
const handler = eventHandlers.get(event);
|
|
392
|
-
if (handler) await handler(this, d);
|
|
393
|
-
} catch (err) {
|
|
394
|
-
this.emit(Events.Error, err instanceof Error ? err : new Error(String(err)));
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Connect to the Fluxer gateway and authenticate.
|
|
400
|
-
* @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
|
|
401
|
-
*/
|
|
402
|
-
async login(token: string): Promise<string> {
|
|
403
|
-
if (this._ws) {
|
|
404
|
-
throw new FluxerError('Client is already logged in. Call destroy() first.', {
|
|
405
|
-
code: ErrorCodes.AlreadyLoggedIn,
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
this.rest.setToken(token);
|
|
409
|
-
let intents = this.options.intents ?? 0;
|
|
410
|
-
if (intents !== 0) {
|
|
411
|
-
if (!this.options.suppressIntentWarning) {
|
|
412
|
-
if (typeof process !== 'undefined' && process.emitWarning) {
|
|
413
|
-
process.emitWarning('Fluxer does not support intents yet. Value has been set to 0.', {
|
|
414
|
-
type: 'FluxerIntents',
|
|
415
|
-
});
|
|
416
|
-
} else {
|
|
417
|
-
console.warn('Fluxer does not support intents yet. Value has been set to 0.');
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
intents = 0;
|
|
421
|
-
}
|
|
422
|
-
this._ws = new WebSocketManager({
|
|
423
|
-
token,
|
|
424
|
-
intents,
|
|
425
|
-
presence: this.options.presence,
|
|
426
|
-
rest: { get: (route: string) => this.rest.get(route) },
|
|
427
|
-
version: this.options.rest?.version ?? '1',
|
|
428
|
-
WebSocket: this.options.WebSocket,
|
|
429
|
-
});
|
|
430
|
-
this._ws.on('dispatch', ({ payload }: { payload: GatewayReceivePayload }) => {
|
|
431
|
-
this.handleDispatch(payload).catch((err: unknown) =>
|
|
432
|
-
this.emit(Events.Error, err instanceof Error ? err : new Error(String(err))),
|
|
433
|
-
);
|
|
434
|
-
});
|
|
435
|
-
this._ws.on(
|
|
436
|
-
'ready',
|
|
437
|
-
async ({
|
|
438
|
-
data,
|
|
439
|
-
}: {
|
|
440
|
-
data: { user: APIUser; guilds: Array<APIGuild & { unavailable?: boolean }> };
|
|
441
|
-
}) => {
|
|
442
|
-
this.user = new ClientUser(this, data.user);
|
|
443
|
-
const waitForGuilds = this.options.waitForGuilds === true;
|
|
444
|
-
const pending = waitForGuilds ? new Set<string>() : null;
|
|
445
|
-
for (const g of data.guilds ?? []) {
|
|
446
|
-
if (g.unavailable === true) {
|
|
447
|
-
if (pending !== null && g.id) pending.add(g.id);
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
const guildData = normalizeGuildPayload(g as unknown);
|
|
451
|
-
if (!guildData) continue;
|
|
452
|
-
const guild = new Guild(this, guildData);
|
|
453
|
-
this.guilds.set(guild.id, guild);
|
|
454
|
-
const withCh = g as APIGuild & {
|
|
455
|
-
channels?: APIChannel[];
|
|
456
|
-
voice_states?: Array<{ user_id: string; channel_id: string | null }>;
|
|
457
|
-
};
|
|
458
|
-
for (const ch of withCh.channels ?? []) {
|
|
459
|
-
const channel = Channel.from(this, ch);
|
|
460
|
-
if (channel) {
|
|
461
|
-
this.channels.set(channel.id, channel);
|
|
462
|
-
guild.channels.set(channel.id, channel as GuildChannel);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (withCh.voice_states?.length) {
|
|
466
|
-
this.emit(Events.VoiceStatesSync, {
|
|
467
|
-
guildId: guild.id,
|
|
468
|
-
voiceStates: withCh.voice_states,
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
if (pending !== null && pending.size > 0) {
|
|
473
|
-
this._pendingGuildIds = pending;
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
if (waitForGuilds && (data.guilds ?? []).length === 0) {
|
|
477
|
-
// Gateway sent READY with no guilds; guilds will arrive via GUILD_CREATE.
|
|
478
|
-
// Defer Ready until guild stream settles (avoids Ready firing with empty client.guilds).
|
|
479
|
-
const GUILD_STREAM_SETTLE_MS = 500;
|
|
480
|
-
this._guildStreamSettleTimeout = setTimeout(() => {
|
|
481
|
-
this._guildStreamSettleTimeout = null;
|
|
482
|
-
this._finalizeReady();
|
|
483
|
-
}, GUILD_STREAM_SETTLE_MS);
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
this._finalizeReady();
|
|
487
|
-
},
|
|
488
|
-
);
|
|
489
|
-
this._ws.on('error', ({ error }: { error: Error }) => this.emit(Events.Error, error));
|
|
490
|
-
this._ws.on('debug', (msg: string) => this.emit(Events.Debug, msg));
|
|
491
|
-
await this._ws.connect();
|
|
492
|
-
return token;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Called when all guilds have been received (or immediately if not waiting).
|
|
497
|
-
* Sets readyAt, emits Ready, clears pending state.
|
|
498
|
-
*/
|
|
499
|
-
_finalizeReady(): void {
|
|
500
|
-
this._pendingGuildIds = null;
|
|
501
|
-
this.readyAt = new Date();
|
|
502
|
-
this.emit(Events.Ready);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Called by GUILD_CREATE handler when waitForGuilds is enabled.
|
|
507
|
-
* Removes guild from pending set; when empty, finalizes ready.
|
|
508
|
-
*/
|
|
509
|
-
_onGuildReceived(guildId: string): void {
|
|
510
|
-
const pending = this._pendingGuildIds;
|
|
511
|
-
if (pending === null) return;
|
|
512
|
-
pending.delete(guildId);
|
|
513
|
-
if (pending.size === 0) this._finalizeReady();
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
/** Disconnect from the gateway and clear cached data. */
|
|
517
|
-
async destroy(): Promise<void> {
|
|
518
|
-
if (this._guildStreamSettleTimeout !== null) {
|
|
519
|
-
clearTimeout(this._guildStreamSettleTimeout);
|
|
520
|
-
this._guildStreamSettleTimeout = null;
|
|
521
|
-
}
|
|
522
|
-
if (this._ws) {
|
|
523
|
-
this._ws.destroy();
|
|
524
|
-
this._ws = null;
|
|
525
|
-
}
|
|
526
|
-
this.rest.setToken(null);
|
|
527
|
-
this.user = null;
|
|
528
|
-
this.readyAt = null;
|
|
529
|
-
this._pendingGuildIds = null;
|
|
530
|
-
this.guilds.clear();
|
|
531
|
-
this.channels.clear();
|
|
532
|
-
this.users.clear();
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
/** Returns true if the client has received Ready and `user` is set. */
|
|
536
|
-
isReady(): this is Client & { user: NonNullable<Client['user']> } {
|
|
537
|
-
return this.readyAt !== null && this.user !== null;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Throws if the client is not ready. Use before accessing client.user or other post-ready state.
|
|
542
|
-
* @throws FluxerError with CLIENT_NOT_READY if client has not received Ready yet
|
|
543
|
-
*/
|
|
544
|
-
assertReady(): asserts this is Client & { user: NonNullable<Client['user']> } {
|
|
545
|
-
if (!this.isReady()) {
|
|
546
|
-
throw new FluxerError(
|
|
547
|
-
'Client is not ready yet. Wait for the Ready event before accessing client.user.',
|
|
548
|
-
{
|
|
549
|
-
code: ErrorCodes.ClientNotReady,
|
|
550
|
-
},
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
static get Routes(): typeof Routes {
|
|
556
|
-
return Routes;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Client } from './Client.js';
|
|
2
|
-
import { User } from '../structures/User.js';
|
|
3
|
-
import { APIGuild, APIUserPartial } from '@erinjs/types';
|
|
4
|
-
import { Routes } from '@erinjs/types';
|
|
5
|
-
import { Guild } from '../structures/Guild.js';
|
|
6
|
-
|
|
7
|
-
export class ClientUser extends User {
|
|
8
|
-
declare readonly client: Client;
|
|
9
|
-
|
|
10
|
-
constructor(client: Client, data: APIUserPartial) {
|
|
11
|
-
super(client, { ...data });
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Fetch guilds the bot is a member of.
|
|
16
|
-
* @returns Array of Guild objects (cached in client.guilds)
|
|
17
|
-
*/
|
|
18
|
-
async fetchGuilds(): Promise<Guild[]> {
|
|
19
|
-
const data = await this.client.rest.get<APIGuild[] | { guilds?: APIGuild[] }>(
|
|
20
|
-
Routes.currentUserGuilds(),
|
|
21
|
-
);
|
|
22
|
-
const list = Array.isArray(data) ? data : (data?.guilds ?? []);
|
|
23
|
-
const guilds: Guild[] = [];
|
|
24
|
-
for (const g of list) {
|
|
25
|
-
const guild = new Guild(this.client, g);
|
|
26
|
-
this.client.guilds.set(guild.id, guild);
|
|
27
|
-
guilds.push(guild);
|
|
28
|
-
}
|
|
29
|
-
return guilds;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Leave a guild. Requires the bot to be a member.
|
|
34
|
-
* @param guildId - The guild ID to leave
|
|
35
|
-
*/
|
|
36
|
-
async leaveGuild(guildId: string): Promise<void> {
|
|
37
|
-
await this.client.rest.delete(Routes.leaveGuild(guildId), { auth: true });
|
|
38
|
-
this.client.guilds.delete(guildId);
|
|
39
|
-
}
|
|
40
|
-
}
|