├── .eslintignore ├── .eslintrc.json ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug.md │ └── feature.md └── workflows │ ├── Docs.yml │ └── ESLint.yml ├── .gitignore ├── .husky └── pre-commit ├── .npmignore ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── docs ├── assets │ ├── css │ │ └── main.css │ ├── images │ │ ├── icons.png │ │ ├── icons@2x.png │ │ ├── widgets.png │ │ └── widgets@2x.png │ └── js │ │ ├── main.js │ │ └── search.js ├── classes │ ├── errors_discordapierror.default.html │ ├── errors_discordresterror.default.html │ ├── errors_discordrestvalidationerror.default.html │ ├── errors_requestabortederror.default.html │ ├── events_channel_channelcreateevent.default.html │ ├── events_channel_channeldeleteevent.default.html │ ├── events_channel_channelpinsupdateevent.default.html │ ├── events_channel_channelupdateevent.default.html │ ├── events_event.default.html │ ├── events_guild_bans_guildbanaddevent.default.html │ ├── events_guild_bans_guildbanremoveevent.default.html │ ├── events_guild_guildcreateevent.default.html │ ├── events_guild_guilddeleteevent.default.html │ ├── events_guild_guildemojisupdateevent.default.html │ ├── events_guild_guildintegrationsupdateevent.default.html │ ├── events_guild_guildupdateevent.default.html │ ├── events_guild_member_guildmemberaddevent.default.html │ ├── events_guild_member_guildmemberchunkevent.default.html │ ├── events_guild_member_guildmemberremoveevent.default.html │ ├── events_guild_member_guildmemberupdateevent.default.html │ ├── events_guild_roles_guildrolecreateevent.default.html │ ├── events_guild_roles_guildroledeleteevent.default.html │ ├── events_guild_roles_guildroleupdateevent.default.html │ ├── events_interaction_interactioncreateevent.default.html │ ├── events_invites_invitecreateevent.default.html │ ├── events_invites_invitedeleteevent.default.html │ ├── events_message_messagecreateevent.default.html │ ├── events_message_messagedeletebulkevent.default.html │ ├── events_message_messagedeleteevent.default.html │ ├── events_message_messageupdateevent.default.html │ ├── events_message_reaction_messagereactionaddevent.default.html │ ├── events_message_reaction_messagereactionremoveallevent.default.html │ ├── events_message_reaction_messagereactionremoveemojievent.default.html │ ├── events_message_reaction_messagereactionremoveevent.default.html │ ├── events_presence_presenceupdateevent.default.html │ ├── events_typingstartevent.typingstartevent.html │ ├── events_userupdateevent.userupdateevent.html │ ├── events_voice_voiceserverupdateevent.default.html │ ├── events_voice_voicestateupdateevent.default.html │ ├── events_webhooksupdateevent.webhooksupdateevent.html │ ├── gateway_shardingmanager.default.html │ ├── gateway_websocketclient.default.html │ ├── gateway_websocketshard.default.html │ ├── interactions_command.default.html │ ├── interactions_helper.default.html │ ├── interactions_interactionclient.default.html │ ├── managers_basemanager.default.html │ ├── managers_channelmanager.default.html │ ├── managers_channelmessagesmanager.default.html │ ├── managers_guildemojimanager.default.html │ ├── managers_guildmanager.default.html │ ├── managers_guildmembermanager.default.html │ ├── managers_guildpresencesmanager.default.html │ ├── managers_guildrolemanager.default.html │ ├── managers_guildvoicestatemanager.default.html │ ├── managers_usermanager.default.html │ ├── models_application.application.html │ ├── models_attachment.attachment.html │ ├── models_audits_auditlogentry.default.html │ ├── models_audits_auditlogs.default.html │ ├── models_base.default.html │ ├── models_channel.channel.html │ ├── models_channel_categorychannel.categorychannel.html │ ├── models_channel_dmchannel.dmchannel.html │ ├── models_channel_groupchannel.groupchannel.html │ ├── models_channel_guildchannel.default.html │ ├── models_channel_guildtextablechannel.default.html │ ├── models_channel_newschannel.newschannel.html │ ├── models_channel_storechannel.storechannel.html │ ├── models_channel_textchannel.textchannel.html │ ├── models_channel_voicechannel.voicechannel.html │ ├── models_guild.guild.html │ ├── models_guild_guildban.default.html │ ├── models_guild_guildemoji.default.html │ ├── models_guild_guildintegration.default.html │ ├── models_guild_guildinvite.default.html │ ├── models_guild_guildmember.default.html │ ├── models_guild_guildpreview.default.html │ ├── models_guild_guildrole.default.html │ ├── models_guild_unavailableguild.default.html │ ├── models_inherit_textablechannel.default.html │ ├── models_interactionmessage.interactionmessage.html │ ├── models_message.message.html │ ├── models_permissionoverwrite.permissionoverwrite.html │ ├── models_presence_activity.default.html │ ├── models_presence_presence.default.html │ ├── models_selfuser.selfuser.html │ ├── models_teams_team.default.html │ ├── models_teams_teammember.default.html │ ├── models_template.template.html │ ├── models_user.user.html │ ├── models_util_embedbuilder.default.html │ ├── models_util_messagecollector.default.html │ ├── models_util_reactioncollector.default.html │ ├── models_voicestate.voicestate.html │ ├── models_webhook.webhook.html │ ├── rest_ratelimitbucket.default.html │ ├── rest_restclient.default.html │ ├── util.default.html │ └── util_permissions.default.html ├── enums │ ├── constants.activityflags.html │ ├── constants.activitystatus.html │ ├── constants.auditlogaction.html │ ├── constants.channeltypes.html │ ├── constants.gatewayevents.html │ ├── constants.gatewayintents.html │ ├── constants.messageflags.html │ ├── constants.messagetypes.html │ ├── constants.opcodes.html │ ├── constants.permissions.html │ ├── constants.shardstatus.html │ ├── constants.stickertype.html │ ├── constants.userflags.html │ ├── interactions_types.applicationcommandoptiontype.html │ ├── interactions_types.interactionresponsetype.html │ └── interactions_types.interactiontype.html ├── index.html ├── interfaces │ ├── gateway_websocketclient.websocketclientevents.html │ ├── interactions_interactionclient.interactionclientevents.html │ ├── interactions_types.applicationcommand.html │ ├── interactions_types.applicationcommandinteractiondata.html │ ├── interactions_types.applicationcommandinteractiondataoption.html │ ├── interactions_types.applicationcommandoption.html │ ├── interactions_types.applicationcommandoptionchoice.html │ ├── interactions_types.iapplicationcommand.html │ ├── interactions_types.interaction.html │ ├── interactions_types.interactionapplicationcommandcallbackdata.html │ ├── interactions_types.interactionresponse.html │ ├── models_guild.guildbanoptions.html │ ├── models_guild.modifyguildmemberoptions.html │ ├── rest_ratelimitbucket.ratelimitinfo.html │ ├── types.allowedmentions.html │ ├── types.clientoptions.html │ ├── types.messagecontentoptions.html │ ├── types.messagefile.html │ ├── types.restcallproperties.html │ ├── types.sendactivityoptions.html │ ├── types.shardinfo.html │ ├── types.voiceoptions.html │ └── types.websocketoptions.html ├── modules.html └── modules │ ├── constants.html │ ├── errors_discordapierror.html │ ├── errors_discordresterror.html │ ├── errors_discordrestvalidationerror.html │ ├── errors_requestabortederror.html │ ├── events.html │ ├── events_channel_channelcreateevent.html │ ├── events_channel_channeldeleteevent.html │ ├── events_channel_channelpinsupdateevent.html │ ├── events_channel_channelupdateevent.html │ ├── events_event.html │ ├── events_guild.html │ ├── events_guild_bans_guildbanaddevent.html │ ├── events_guild_bans_guildbanremoveevent.html │ ├── events_guild_guildcreateevent.html │ ├── events_guild_guilddeleteevent.html │ ├── events_guild_guildemojisupdateevent.html │ ├── events_guild_guildintegrationsupdateevent.html │ ├── events_guild_guildupdateevent.html │ ├── events_guild_member_guildmemberaddevent.html │ ├── events_guild_member_guildmemberchunkevent.html │ ├── events_guild_member_guildmemberremoveevent.html │ ├── events_guild_member_guildmemberupdateevent.html │ ├── events_guild_roles_guildrolecreateevent.html │ ├── events_guild_roles_guildroledeleteevent.html │ ├── events_guild_roles_guildroleupdateevent.html │ ├── events_interaction.html │ ├── events_interaction_interactioncreateevent.html │ ├── events_invites_invitecreateevent.html │ ├── events_invites_invitedeleteevent.html │ ├── events_message.html │ ├── events_message_messagecreateevent.html │ ├── events_message_messagedeletebulkevent.html │ ├── events_message_messagedeleteevent.html │ ├── events_message_messageupdateevent.html │ ├── events_message_reaction_messagereactionaddevent.html │ ├── events_message_reaction_messagereactionremoveallevent.html │ ├── events_message_reaction_messagereactionremoveemojievent.html │ ├── events_message_reaction_messagereactionremoveevent.html │ ├── events_presence.html │ ├── events_presence_presenceupdateevent.html │ ├── events_typingstartevent.html │ ├── events_userupdateevent.html │ ├── events_voice.html │ ├── events_voice_voiceserverupdateevent.html │ ├── events_voice_voicestateupdateevent.html │ ├── events_webhooksupdateevent.html │ ├── gateway_shardingmanager.html │ ├── gateway_websocketclient.html │ ├── gateway_websocketshard.html │ ├── index.html │ ├── interactions_command.html │ ├── interactions_helper.html │ ├── interactions_interactionclient.html │ ├── interactions_types.html │ ├── managers_basemanager.html │ ├── managers_channelmanager.html │ ├── managers_channelmessagesmanager.html │ ├── managers_guildemojimanager.html │ ├── managers_guildmanager.html │ ├── managers_guildmembermanager.html │ ├── managers_guildpresencesmanager.html │ ├── managers_guildrolemanager.html │ ├── managers_guildvoicestatemanager.html │ ├── managers_usermanager.html │ ├── models.html │ ├── models_application.html │ ├── models_attachment.html │ ├── models_audits_auditlogentry.html │ ├── models_audits_auditlogs.html │ ├── models_base.html │ ├── models_channel.html │ ├── models_channel_categorychannel.html │ ├── models_channel_dmchannel.html │ ├── models_channel_groupchannel.html │ ├── models_channel_guildchannel.html │ ├── models_channel_guildtextablechannel.html │ ├── models_channel_newschannel.html │ ├── models_channel_storechannel.html │ ├── models_channel_textchannel.html │ ├── models_channel_voicechannel.html │ ├── models_guild.html │ ├── models_guild_guildban.html │ ├── models_guild_guildemoji.html │ ├── models_guild_guildintegration.html │ ├── models_guild_guildinvite.html │ ├── models_guild_guildmember.html │ ├── models_guild_guildpreview.html │ ├── models_guild_guildrole.html │ ├── models_guild_unavailableguild.html │ ├── models_inherit_textablechannel.html │ ├── models_interactionmessage.html │ ├── models_message.html │ ├── models_permissionoverwrite.html │ ├── models_presence.html │ ├── models_presence_activity.html │ ├── models_presence_presence.html │ ├── models_selfuser.html │ ├── models_teams_team.html │ ├── models_teams_teammember.html │ ├── models_template.html │ ├── models_user.html │ ├── models_util.html │ ├── models_util_embedbuilder.html │ ├── models_util_messagecollector.html │ ├── models_util_reactioncollector.html │ ├── models_voicestate.html │ ├── models_webhook.html │ ├── rest_ratelimitbucket.html │ ├── rest_restclient.html │ ├── types.html │ ├── util.html │ └── util_permissions.html ├── examples ├── basic │ └── index.js └── interactions │ └── index.js ├── package-lock.json ├── package.json ├── renovate.json ├── scripts ├── build.js ├── docs.js ├── lint.js ├── release.js └── test.js ├── src ├── Constants.ts ├── errors │ ├── DiscordAPIError.ts │ ├── DiscordRestError.ts │ ├── DiscordRestValidationError.ts │ └── RequestAbortedError.ts ├── events │ ├── Event.ts │ ├── TypingStartEvent.ts │ ├── UserUpdateEvent.ts │ ├── WebhooksUpdateEvent.ts │ ├── channel │ │ ├── ChannelCreateEvent.ts │ │ ├── ChannelDeleteEvent.ts │ │ ├── ChannelPinsUpdateEvent.ts │ │ └── ChannelUpdateEvent.ts │ ├── guild │ │ ├── GuildCreateEvent.ts │ │ ├── GuildDeleteEvent.ts │ │ ├── GuildEmojisUpdateEvent.ts │ │ ├── GuildIntegrationsUpdateEvent.ts │ │ ├── GuildUpdateEvent.ts │ │ ├── bans │ │ │ ├── GuildBanAddEvent.ts │ │ │ └── GuildBanRemoveEvent.ts │ │ ├── index.ts │ │ ├── member │ │ │ ├── GuildMemberAddEvent.ts │ │ │ ├── GuildMemberChunkEvent.ts │ │ │ ├── GuildMemberRemoveEvent.ts │ │ │ └── GuildMemberUpdateEvent.ts │ │ └── roles │ │ │ ├── GuildRoleCreateEvent.ts │ │ │ ├── GuildRoleDeleteEvent.ts │ │ │ └── GuildRoleUpdateEvent.ts │ ├── index.ts │ ├── interaction │ │ ├── InteractionCreateEvent.ts │ │ └── index.ts │ ├── invites │ │ ├── InviteCreateEvent.ts │ │ └── InviteDeleteEvent.ts │ ├── message │ │ ├── MessageCreateEvent.ts │ │ ├── MessageDeleteBulkEvent.ts │ │ ├── MessageDeleteEvent.ts │ │ ├── MessageUpdateEvent.ts │ │ ├── index.ts │ │ └── reaction │ │ │ ├── MessageReactionAddEvent.ts │ │ │ ├── MessageReactionRemoveAllEvent.ts │ │ │ ├── MessageReactionRemoveEmojiEvent.ts │ │ │ └── MessageReactionRemoveEvent.ts │ ├── presence │ │ ├── PresenceUpdateEvent.ts │ │ └── index.ts │ └── voice │ │ ├── VoiceServerUpdateEvent.ts │ │ ├── VoiceStateUpdateEvent.ts │ │ └── index.ts ├── gateway │ ├── ShardingManager.ts │ ├── WebSocketClient.ts │ └── WebSocketShard.ts ├── index.ts ├── interactions │ ├── Command.ts │ ├── Helper.ts │ ├── InteractionClient.ts │ └── types.ts ├── managers │ ├── BaseManager.ts │ ├── ChannelManager.ts │ ├── ChannelMessagesManager.ts │ ├── GuildEmojiManager.ts │ ├── GuildManager.ts │ ├── GuildMemberManager.ts │ ├── GuildPresencesManager.ts │ ├── GuildRoleManager.ts │ ├── GuildVoiceStateManager.ts │ └── UserManager.ts ├── models │ ├── Application.ts │ ├── Attachment.ts │ ├── Base.ts │ ├── Channel.ts │ ├── Guild.ts │ ├── InteractionMessage.ts │ ├── Message.ts │ ├── PermissionOverwrite.ts │ ├── SelfUser.ts │ ├── Template.ts │ ├── User.ts │ ├── VoiceState.ts │ ├── Webhook.ts │ ├── audits │ │ ├── AuditLogEntry.ts │ │ └── AuditLogs.ts │ ├── channel │ │ ├── CategoryChannel.ts │ │ ├── DMChannel.ts │ │ ├── GroupChannel.ts │ │ ├── GuildChannel.ts │ │ ├── GuildTextableChannel.ts │ │ ├── NewsChannel.ts │ │ ├── StageChannel.ts │ │ ├── StoreChannel.ts │ │ ├── TextChannel.ts │ │ └── VoiceChannel.ts │ ├── guild │ │ ├── GuildBan.ts │ │ ├── GuildEmoji.ts │ │ ├── GuildIntegration.ts │ │ ├── GuildInvite.ts │ │ ├── GuildMember.ts │ │ ├── GuildPreview.ts │ │ ├── GuildRole.ts │ │ └── UnavailableGuild.ts │ ├── index.ts │ ├── inherit │ │ └── TextableChannel.ts │ ├── presence │ │ ├── Activity.ts │ │ ├── Presence.ts │ │ └── index.ts │ ├── teams │ │ ├── Team.ts │ │ └── TeamMember.ts │ └── util │ │ ├── EmbedBuilder.ts │ │ ├── MessageCollector.ts │ │ ├── ReactionCollector.ts │ │ └── index.ts ├── rest │ ├── RatelimitBucket.ts │ └── RestClient.ts ├── types.ts └── util │ ├── Permissions.ts │ └── index.ts ├── tsconfig.json └── typedoc.json /.eslintignore: -------------------------------------------------------------------------------- 1 | .github/ 2 | docs/ 3 | examples/ 4 | node_modules/ 5 | build/ 6 | 7 | .npmignore 8 | *.md 9 | LICENSE 10 | *.json 11 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@augu/eslint-config/ts.js" 3 | } 4 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Wumpcord 2 | You finally decided to contribute to Wumpcord, splendid! We use tools like **ESLint** to keep a conistent code style and **Jest** to test any features that aren't related to Discord's API. 3 | 4 | ## Getting Started 5 | Before you wanna contribute, you will need Node.js v10 or higher. 6 | 7 | ## Setup 8 | - [Fork](https://github.com/auguwu/Wumpcord/fork) the repository 9 | - Clone the repository (``git clone https://github.com/$USERNAME/Wumpcord``), omit `$USERNAME` with your GitHub username where you cloned the repository. 10 | - Run `npm ci` to get the dependencies 11 | - Code your heart out! :heart: 12 | - Once you are finished, push to a different branch to the **indev** branch. 13 | - [Submit](https://github.com/auguwu/Wumpcord/compare) your contribution. 14 | - If you are in the [Discord](https://discord.gg/JjHGR6vhcG) server and have your PR merged, contact **August#5820** for the **Contributor** role. 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report any bugs related to Wumpcord 4 | assignees: auguwu 5 | labels: bug 6 | --- 7 | 8 | # Issue in-hand 9 | **Describe your bug report here** 10 | 11 | ```js 12 | // If there is any code to reproduce, add it here 13 | ``` 14 | 15 | # Options 16 | - Node.js Version: 17 | - Wumpcord Version/Branch: 18 | - Operating System: 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Add any featue requests here 4 | assignees: auguwu 5 | labels: feature, wontfix 6 | --- 7 | 8 | # Feature Request 9 | **Detail on what you want added to Wumpcord** 10 | -------------------------------------------------------------------------------- /.github/workflows/Docs.yml: -------------------------------------------------------------------------------- 1 | name: Deploy docs 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: 6 | - 'master' 7 | paths-ignore: 8 | - '.github/**' 9 | - '.vscode/**' 10 | - 'examples/' 11 | - '.eslintignore' 12 | - '.gitignore' 13 | - '.npmignore' 14 | - '**.md' 15 | - 'jest.config.js' 16 | - 'LICENSE' 17 | - 'package.json' 18 | - 'renovate.json' 19 | - 'tsconfig.json' 20 | - 'tsconfig.test.json' 21 | jobs: 22 | deploy: 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Update documentation 26 | run: | 27 | mkdir ~/.kube 28 | echo "${{ secrets.KUBE_CONFIG }}" > ~/.kube/config 29 | kubectl rollout restart deployment/wumpdocs 30 | -------------------------------------------------------------------------------- /.github/workflows/ESLint.yml: -------------------------------------------------------------------------------- 1 | name: ESLint 2 | on: 3 | push: 4 | branches: 5 | - 'issue/**' 6 | - 'feat/**' 7 | - 'master' 8 | - 'indev' 9 | paths-ignore: 10 | - '.github/**' 11 | - '.vscode/**' 12 | - 'examples/' 13 | - 'docs/' 14 | - '.eslintignore' 15 | - '.gitignore' 16 | - '.npmignore' 17 | - '**.md' 18 | - 'jest.config.js' 19 | - 'LICENSE' 20 | - 'package.json' 21 | - 'renovate.json' 22 | - 'tsconfig.json' 23 | - 'tsconfig.test.json' 24 | 25 | pull_request: 26 | branches: 27 | - 'master' 28 | - 'indev' 29 | paths-ignore: 30 | - '.github/**' 31 | - '.vscode/**' 32 | - 'examples/' 33 | - 'docs/' 34 | - '.eslintignore' 35 | - '.gitignore' 36 | - '.npmignore' 37 | - '**.md' 38 | - 'jest.config.js' 39 | - 'LICENSE' 40 | - 'package.json' 41 | - 'renovate.json' 42 | - 'tsconfig.json' 43 | - 'tsconfig.test.json' 44 | 45 | jobs: 46 | lint: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | node-version: [14.x, 15.x] 51 | steps: 52 | - name: Checkout the repository 53 | uses: actions/checkout@v2 54 | 55 | - name: Uses Node.js v${{ matrix.node-version }} 56 | uses: actions/setup-node@v2 57 | with: 58 | node-version: ${{ matrix.node-version }} 59 | 60 | - name: Installs ESLint globally 61 | run: npm i -g eslint 62 | 63 | - name: Installs all local dependencies 64 | run: npm i 65 | 66 | - name: Lints the repository for any code-checking errors 67 | run: npm run lint 68 | 69 | - name: Build the project for any errors 70 | run: tsc --noEmit 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .husky/_/ 3 | build/ 4 | test/ 5 | 6 | *.lock 7 | *.log 8 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | echo '❓ lint ~ ❓ project - checking eslint for errors' 5 | eslint src --ext .ts # `--fix` would normally be here but it should only print and not fix 6 | 7 | echo '✔ lint ~ ❓ project - compiling project for errors' 8 | tsc --noEmit 9 | 10 | echo '✔ lint ~ ✔ project - we are done here' 11 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | examples 3 | typings 4 | docs 5 | test 6 | src 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules\\typescript\\lib" 3 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at august@augu.dev. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020-2021 August 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WARNING 2 | **wumpcord** has been deprecated due to Discord's API changes being too fast paced for the limited time I have. 3 | 4 | # Wumpcord 5 | > 🚣 **Flexible, type-safe, and lightweight Discord API library made in TypeScript** 6 | 7 | ## Installation 8 | You can install **Wumpcord** under NPM, as follows: 9 | 10 | ```sh 11 | $ npm i --no-optional wumpcord 12 | ``` 13 | 14 | If you wish to install indev builds (that are most likely buggy), you can install them using: 15 | 16 | ```sh 17 | $ npm i --no-optional wumpcord@indev 18 | ``` 19 | 20 | ### Features 21 | Specific features require extra dependencies, this is a list that requires them 22 | 23 | #### Optional Dependencies 24 | - `erlpack` 25 | - Required: No 26 | - Native: Yes 27 | - Alternative: **JSON** (built-in) 28 | 29 | ## Need Support? 30 | You can join the server below and join in #support under the **Wumpcord** category 31 | 32 | [![discord embed owo](https://discord.com/api/v8/guilds/824066105102303232/widget.png?style=banner3)](https://discord.gg/ATmjFH9kMH) 33 | 34 | ## Example Bot 35 | ```js 36 | const { Client } = require('wumpcord'); 37 | const client = new Client({ 38 | intents: ['guilds', 'guildMessages'], 39 | token: '' 40 | }); 41 | 42 | client.on('message', event => { 43 | if (event.message.content === '!ping') return event.message.channel.send('henlo world'); 44 | }); 45 | 46 | client.on('ready', async () => { 47 | console.log(`Connected as ${client.user.tag}!`); 48 | client.setStatus('online', { // Sets it to "Competing in uwu" 49 | type: 5, 50 | name: 'uwu' 51 | }); 52 | }); 53 | 54 | client.connect(); 55 | ``` 56 | 57 | ## Maintainers 58 | - [August](https://floofy.dev) 59 | 60 | ## Testers 61 | None at the moment. 62 | 63 | ## License 64 | **Wumpcord** is released under the [MIT](/LICENSE) License. :sparkling_heart: 65 | -------------------------------------------------------------------------------- /docs/assets/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auguwu/Wumpcord/aff6341ee60e75086f216e7c3103912f5037ca4c/docs/assets/images/icons.png -------------------------------------------------------------------------------- /docs/assets/images/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auguwu/Wumpcord/aff6341ee60e75086f216e7c3103912f5037ca4c/docs/assets/images/icons@2x.png -------------------------------------------------------------------------------- /docs/assets/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auguwu/Wumpcord/aff6341ee60e75086f216e7c3103912f5037ca4c/docs/assets/images/widgets.png -------------------------------------------------------------------------------- /docs/assets/images/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auguwu/Wumpcord/aff6341ee60e75086f216e7c3103912f5037ca4c/docs/assets/images/widgets@2x.png -------------------------------------------------------------------------------- /examples/basic/index.js: -------------------------------------------------------------------------------- 1 | // Simple ping bot made in Wumpcord! 2 | 3 | const { Client } = require('wumpcord'); 4 | const client = new Client({ 5 | ws: { intents: ['guilds', 'guildMessages'] }, 6 | token: 'set your token here' 7 | }); 8 | 9 | client.on('ready', () => console.info(`Bot is ready as ${client.user.tag}!`)); 10 | client.on('message', event => { 11 | if (event.message.content === '!ping') 12 | return event.channel.send('Pong!'); 13 | }); 14 | 15 | client.connect(); 16 | -------------------------------------------------------------------------------- /examples/interactions/index.js: -------------------------------------------------------------------------------- 1 | // Example on how to use the Interaction Helper 2 | const { InteractionClient } = require('wumpcord'); 3 | 4 | const client = new InteractionClient({ 5 | token: 'set your token here', 6 | ws: { intents: ['guildMessages', 'guilds'] } 7 | }); 8 | 9 | client.on('ready', async () => { 10 | console.log(`Bot is ready as ${client.user.tag}!`); 11 | await client.interactions.createGuildCommand('guild id', { 12 | name: 'beep', 13 | description: 'It does beep!' 14 | }); 15 | }); 16 | 17 | client.on('interactionReceive', event => { 18 | console.log(`Received command /${event.command.name}`); 19 | return event.message.send('Beep!'); 20 | }); 21 | 22 | client.connect(); 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wumpcord", 3 | "description": "🚣 Flexible, type-safe, and lightweight Discord API library", 4 | "version": "1.2.0", 5 | "main": "build/index.js", 6 | "license": "MIT", 7 | "author": "Chris \"August\" Hernandez ", 8 | "repository": "https://github.com/auguwu/Wumpcord", 9 | "homepage": "https://wump.floofy.dev", 10 | "types": "./build/index.d.ts", 11 | "funding": { 12 | "url": "https://github.com/auguwu/Wumpcord?sponsor=1" 13 | }, 14 | "files": [ 15 | "build/" 16 | ], 17 | "maintainers": [ 18 | "Chris \"August\" Hernandez " 19 | ], 20 | "engines": { 21 | "node": ">=14" 22 | }, 23 | "scripts": { 24 | "clean:node_modules": "rm -rf node_modules/@types/**/node_modules && rm -rf node_modules/@augu/**/node_modules", 25 | "clean:win:tar": "cp node_modules/@augu/collections/build/index.js.* node_modules/@augu/collections/build/index.js && rm node_modules/@augu/collections/build/index.js.*", 26 | "prepare": "npm run build", 27 | "docgen": "typedoc src --out docs --theme node_modules/eledoc/bin/default/", 28 | "build": "npm run lint && rm -rf build && tsc", 29 | "lint": "node scripts/lint.js" 30 | }, 31 | "dependencies": { 32 | "@augu/collections": "1.0.5", 33 | "@augu/utils": "1.4.2", 34 | "discord-api-types": "0.11.2", 35 | "form-data": "4.0.0", 36 | "ws": "7.4.6" 37 | }, 38 | "devDependencies": { 39 | "@augu/eslint-config": "1.10.0", 40 | "@augu/tsconfig": "1.0.1", 41 | "@types/node": "14.14.37", 42 | "@types/ws": "7.4.1", 43 | "@typescript-eslint/eslint-plugin": "4.20.0", 44 | "@typescript-eslint/parser": "4.20.0", 45 | "eledoc": "0.2.1", 46 | "eslint": "7.23.0", 47 | "husky": "6.0.0", 48 | "typedoc": "0.20.34", 49 | "typescript": "4.2.3" 50 | }, 51 | "peerDependencies": { 52 | "erlpack": "0.1.3" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseBranches": ["indev"], 3 | "automerge": true, 4 | "extends": ["config:base"] 5 | } 6 | -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | const { exec } = require('child_process'); 24 | const { join } = require('path'); 25 | 26 | const log = (message) => process.stdout.write(`[build] ${message}\n`); 27 | 28 | async function main(ci) { 29 | log('starting build...'); 30 | log(`ci: ${ci ? 'yes' : 'no'}`); 31 | 32 | const args = ci ? ['--noEmit'] : []; 33 | const child = exec(`tsc ${args.join(' ')}`, { cwd: join(__dirname, '..') }); 34 | log(`started child process as ${child.pid}`); 35 | 36 | let success = true; 37 | child.stdout.on('data', chunk => log(chunk)); 38 | child.stderr.on('data', chunk => log(chunk)); 39 | child.on('error', error => { 40 | log('unable to build source'); 41 | log(error.stack); 42 | 43 | success = false; 44 | }); 45 | 46 | child.once('exit', (code, signal) => { 47 | success = code === 0; 48 | 49 | log(`\`tsc\` has closed with code ${code}${signal ? ` with signale "${signal}"` : ''}, success: ${success ? 'yes' : 'no'}`); 50 | process.exit(success ? 0 : 1); 51 | }); 52 | } 53 | 54 | const args = process.argv.slice(2); 55 | const isCi = args[0] === '--ci' || args[0] === '-c'; 56 | 57 | main(isCi); 58 | -------------------------------------------------------------------------------- /scripts/lint.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | const { ESLint } = require('eslint'); 24 | const { join } = require('path'); 25 | 26 | const log = (message) => process.stdout.write(`[lint] ${message}\n`); 27 | 28 | async function main() { 29 | const linter = new ESLint({ 30 | overrideConfigFile: join(__dirname, '..', '.eslintrc.json'), 31 | extensions: ['js', 'ts'], 32 | ignorePath: join(__dirname, '..', '.eslintignore'), 33 | fix: true 34 | }); 35 | 36 | log('linting files from `src`...'); 37 | const results = await linter.lintFiles('src'); 38 | const errors = results.reduce((acc, curr) => acc + curr.errorCount, 0); 39 | const warnings = results.reduce((acc, curr) => acc + curr.warningCount, 0); 40 | 41 | log(`Received ${errors} errors and ${warnings} warnings`); 42 | } 43 | 44 | main(); 45 | -------------------------------------------------------------------------------- /scripts/release.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | const { promises: fs } = require('fs'); 24 | const { exec } = require('child_process'); 25 | const { join } = require('path'); 26 | 27 | const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); 28 | const log = (message) => process.stdout.write(`[release] ${message}\n`); 29 | 30 | async function main() { 31 | console.log('[release] Preparing for release...'); 32 | await sleep(3000); 33 | 34 | log('linting files...'); 35 | try { 36 | await require('./lint'); 37 | await sleep(1500); 38 | } catch(ex) { 39 | log(ex.message); 40 | process.exit(1); 41 | } 42 | 43 | log('running tests...'); 44 | try { 45 | await require('./test'); 46 | await sleep(1500); 47 | } catch(ex) { 48 | log(ex.message); 49 | process.exit(1); 50 | } 51 | 52 | log('re-building typings for documentation...'); 53 | try { 54 | await require('./docs'); 55 | await sleep(1500); 56 | } catch(ex) { 57 | log(ex.message); 58 | process.exit(1); 59 | } 60 | 61 | log('prepared everything for release.'); 62 | } 63 | 64 | main(); 65 | -------------------------------------------------------------------------------- /scripts/test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | const { runCLI } = require('@jest/core'); 24 | const { join } = require('path'); 25 | 26 | /** 27 | * Runs the `test` script 28 | * @param {boolean} ci If we are in CI mode 29 | */ 30 | async function main(ci) { 31 | try { 32 | await runCLI({ 33 | ci, 34 | config: join(__dirname, '..', 'jest.config.js'), 35 | projects: [process.cwd()], 36 | silent: true 37 | }, [process.cwd()]); // HOW THE FUCK DO YOU GET PRINTED WHAT???? 38 | } catch(ex) { 39 | console.error(ex); 40 | } 41 | } 42 | 43 | const args = process.argv.slice(2); 44 | const isCI = args[0] && args[0] === '--ci'; 45 | 46 | main(isCI); 47 | -------------------------------------------------------------------------------- /src/errors/DiscordAPIError.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /** 24 | * Represents a error related to Discord's API 25 | */ 26 | export class DiscordAPIError extends Error { 27 | /** 28 | * Creates a new [DiscordAPIError] instance 29 | * @param code The code Discord gave us 30 | * @param message The actual message 31 | */ 32 | constructor(code: number, message: string) { 33 | super(message); 34 | 35 | this.name = `DiscordAPIError [${code}]`; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/errors/DiscordRestError.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /** 24 | * Represents a error related to the rest client 25 | */ 26 | export class DiscordRestError extends Error { 27 | /** 28 | * Creates a new [DiscordAPIError] instance 29 | * @param code The code Discord gave us 30 | * @param message The actual message 31 | */ 32 | constructor(code: number, message: string) { 33 | super(message); 34 | 35 | this.name = `DiscordRestError [${code}]`; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/errors/DiscordRestValidationError.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /** Represents the validation errors Discord provides */ 24 | interface ErrorType { 25 | message: string; 26 | code: string; 27 | key: string; 28 | } 29 | 30 | /** 31 | * Represents a error that a validation error has occured 32 | */ 33 | export class DiscordRestValidationError extends Error { 34 | constructor(endpoint: string, method: string, code: number, message: string, errors: ErrorType[]) { 35 | super(`${method.toUpperCase()} ${endpoint}: ${message}\n${errors.map((error) => `- '${error.key}' [${error.code}]: ${error.message}`).join('\n')}`); 36 | 37 | this.name = `DiscordRestValidationError [${code}]`; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/errors/RequestAbortedError.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /** 24 | * Class to define a request aborted error 25 | */ 26 | export class RequestAbortedError extends Error { 27 | constructor(endpoint: string, method: string) { 28 | super(`Request was aborted by server on "${method.toUpperCase()} ${endpoint}"`); 29 | 30 | this.name = 'RequestAbortedError'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/events/Event.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import type WebSocketShard from '../gateway/WebSocketShard'; 25 | import type * as types from '../types'; 26 | 27 | /** 28 | * Represents a event from Discord and handles everything 29 | * @template D The data object structure 30 | * @template Refs The references available in this event's context 31 | */ 32 | export default class Event { 33 | /** The WebSocket client attached */ 34 | public client: WebSocketClient; 35 | 36 | /** The WebSocket shard that is handling this event */ 37 | public shard: WebSocketShard; 38 | 39 | /** The references attached to this [Event] */ 40 | public $refs: Refs; 41 | 42 | /** The data payload from Discord */ 43 | public data: D; 44 | 45 | /** 46 | * Represents a event from Discord and handles everything 47 | * @param shard The shard that is handling this event 48 | * @param data The data payload from Discord 49 | */ 50 | constructor(shard: WebSocketShard, data: D) { 51 | // @ts-ignore Yes it is private, but I want to access it. 52 | this.client = shard.client; 53 | this.shard = shard; 54 | this.$refs = {} as Refs; 55 | this.data = data; 56 | } 57 | 58 | process(): types.MaybePromise { 59 | throw new TypeError('Overridable function [Event.process] is not implemented.'); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/events/TypingStartEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { PartialEntity, TextableChannel } from '../types'; 24 | import type { GatewayTypingStartDispatchData } from 'discord-api-types'; 25 | import { User } from '../models'; 26 | import Event from './Event'; 27 | 28 | interface TypingStartReferences { 29 | channel: PartialEntity; 30 | user: PartialEntity; 31 | } 32 | 33 | export class TypingStartEvent extends Event { 34 | get user() { 35 | return this.client.users.get(this.$refs.user.id); 36 | } 37 | 38 | get channel() { 39 | return this.client.channels.get(this.$refs.channel.id); 40 | } 41 | 42 | async process() { 43 | const { data, client } = this; 44 | 45 | const channel = client.channels.get(data.channel_id) || { id: data.channel_id }; 46 | const user = client.users.get(data.user_id) || { id: data.user_id }; 47 | 48 | this.$refs = { user, channel }; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/events/UserUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayUserUpdateDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../types'; 25 | import { User } from '../models'; 26 | import Event from './Event'; 27 | 28 | interface UserUpdateReferences { 29 | user: PartialEntity; 30 | old?: PartialEntity; 31 | } 32 | 33 | export class UserUpdateEvent extends Event { 34 | get old() { 35 | return this.$refs.old; 36 | } 37 | 38 | get user() { 39 | return this.$refs.user; 40 | } 41 | 42 | process() { 43 | const user = this.client.users.get(this.data.id); 44 | if (!user) { 45 | this.shard.debug('Unable to emit \'userUpdate\': Missing cached user, emitting anyway'); 46 | this.$refs = { old: undefined, user: new User(this.client, this.data) }; 47 | 48 | return; 49 | } 50 | 51 | const updated = this.client.users.add(new User(this.client, this.data)); 52 | this.$refs = { 53 | old: user, 54 | user: updated 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/events/WebhooksUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayWebhooksUpdateDispatchData } from 'discord-api-types'; 24 | import type { AnyChannel, PartialEntity } from '../types'; 25 | import { Guild } from '../models'; 26 | import Event from './Event'; 27 | 28 | interface WebhooksUpdateReferences { 29 | channel: PartialEntity; 30 | guild: PartialEntity; 31 | } 32 | 33 | export class WebhooksUpdateEvent extends Event { 34 | get guild() { 35 | return this.$refs.guild; 36 | } 37 | 38 | get channel() { 39 | return this.$refs.channel; 40 | } 41 | 42 | process() { 43 | this.$refs = { 44 | channel: this.client.channels.get(this.data.channel_id) || { id: this.data.channel_id }, 45 | guild: this.client.guilds.get(this.data.guild_id) || { id: this.data.guild_id } 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/events/channel/ChannelCreateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayChannelCreateDispatchData } from 'discord-api-types'; 24 | import type { AnyChannel, PartialEntity } from '../../types'; 25 | import { Channel, Guild } from '../../models'; 26 | import Event from '../Event'; 27 | 28 | interface ChannelCreateRefs { 29 | channel: AnyChannel; 30 | guild?: PartialEntity; 31 | } 32 | 33 | export default class ChannelCreateEvent extends Event { 34 | get channel() { 35 | return this.$refs.channel; 36 | } 37 | 38 | get guild() { 39 | return this.$refs.guild; 40 | } 41 | 42 | process() { 43 | const channel = Channel.from(this.client, this.data); 44 | const guild = this.data.guild_id !== undefined ? this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id } : undefined; 45 | 46 | this.client.channels.add(channel); 47 | (guild as Guild | undefined)?.channels?.add(channel); 48 | 49 | this.$refs = { channel: channel!, guild }; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/events/channel/ChannelDeleteEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayChannelDeleteDispatchData } from 'discord-api-types'; 24 | import { Channel } from '../../models'; 25 | import type { PartialEntity, AnyChannel } from '../../types'; 26 | import Event from '../Event'; 27 | 28 | interface ChannelDeleteRefs { 29 | channel: PartialEntity; 30 | } 31 | 32 | export default class ChannelDeleteEvent extends Event { 33 | get channel() { 34 | return this.$refs.channel; 35 | } 36 | 37 | process() { 38 | if (this.data.guild_id !== undefined) { 39 | const guild = this.client.guilds.get(this.data.guild_id); 40 | if (guild !== null) guild.channels.remove(this.data.id); 41 | } 42 | 43 | this.client.channels.remove(this.data.id); 44 | this.$refs = { 45 | channel: this.client.channels.get(this.data.id) ?? Channel.from(this.client, this.data)! 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/events/channel/ChannelPinsUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import { GatewayChannelPinsUpdateDispatchData } from 'discord-api-types'; 24 | import type { AnyChannel, PartialEntity } from '../../types'; 25 | import Event from '../Event'; 26 | 27 | interface ChannelPinsUpdateRefs { 28 | lastPinnedAt: Date | null; 29 | channel: PartialEntity; 30 | } 31 | 32 | export default class ChannelPinsUpdateEvent extends Event { 33 | get lastPinnedAt() { 34 | return this.$refs.lastPinnedAt; 35 | } 36 | 37 | get channel() { 38 | return this.$refs.channel; 39 | } 40 | 41 | process() { 42 | this.$refs = { 43 | lastPinnedAt: this.data.last_pin_timestamp !== undefined && this.data.last_pin_timestamp !== null 44 | ? new Date(this.data.last_pin_timestamp) 45 | : null, 46 | 47 | channel: this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id } 48 | }; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/events/channel/ChannelUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayChannelUpdateDispatchData } from 'discord-api-types'; 24 | import type { AnyChannel, PartialEntity } from '../../types'; 25 | import { Channel, Guild } from '../../models'; 26 | import Event from '../Event'; 27 | 28 | interface ChannelUpdateRefs { 29 | old: PartialEntity | null; 30 | new: AnyChannel; 31 | } 32 | 33 | export default class ChannelUpdateEvent extends Event { 34 | get old() { 35 | return this.$refs.old; 36 | } 37 | 38 | get channel() { 39 | return this.$refs.new; 40 | } 41 | 42 | process() { 43 | const guild = this.data.guild_id !== undefined ? this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id } : undefined; 44 | if (!guild || !guild.hasOwnProperty('channels')) { 45 | this.$refs = { 46 | old: null, 47 | new: Channel.from(this.client, this.data)! 48 | }; 49 | 50 | return; 51 | } 52 | 53 | const updated = Channel.from(this.client, this.data)!; 54 | const old = (guild as Guild).channels.get(this.data.id); 55 | if (old === null) { 56 | this.$refs = { 57 | old: null, 58 | new: updated 59 | }; 60 | 61 | return; 62 | } 63 | 64 | (guild as Guild).channels.remove(old); 65 | (guild as Guild).channels.add(updated); 66 | this.$refs = { 67 | old, 68 | new: updated 69 | }; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/events/guild/GuildCreateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildCreateDispatchData } from 'discord-api-types'; 24 | import { Guild } from '../../models/Guild'; 25 | import Event from '../Event'; 26 | 27 | interface GuildCreateRefs { 28 | guild: Guild; 29 | } 30 | 31 | export default class GuildCreateEvent extends Event { 32 | get guild() { 33 | return this.$refs.guild; 34 | } 35 | 36 | process() { 37 | if (this.client.guilds.has(this.data.id)) { 38 | const guild = this.client.guilds.get(this.data.id); 39 | if (guild !== null) { 40 | if (!guild.unavailable && !this.data.unavailable) { 41 | guild.patch({ ...this.data }); // eslint-disable-line camelcase 42 | this.client.guilds.cache.set(this.data.id, guild); 43 | this.$refs = { guild }; 44 | 45 | return true; 46 | } 47 | } 48 | } 49 | 50 | const guild = new Guild(this.client, { shard_id: this.shard.id, ...this.data }); // eslint-disable-line camelcase 51 | 52 | this.client.guilds.add(guild); 53 | this.$refs = { guild }; 54 | return false; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/events/guild/GuildDeleteEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildDeleteDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../types'; 25 | import { Guild } from '../../models/Guild'; 26 | import Event from '../Event'; 27 | 28 | interface GuildDeleteRefs { 29 | guild: PartialEntity; 30 | } 31 | 32 | export default class GuildDeleteEvent extends Event { 33 | get guild() { 34 | return this.$refs.guild; 35 | } 36 | 37 | process() { 38 | const guild = this.client.guilds.get(this.data.id) ?? { id: this.data.id }; 39 | if (this.data.unavailable) { 40 | this.$refs = { 41 | guild 42 | }; 43 | 44 | // @ts-ignore 45 | (guild as Guild)?.patch({ unavailable: true }); 46 | if (guild instanceof Guild) this.client.guilds.add(guild); 47 | 48 | return true; 49 | } 50 | 51 | this.$refs = { 52 | guild 53 | }; 54 | 55 | this.client.guilds.remove(this.data.id); 56 | return false; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/events/guild/GuildEmojisUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildEmojisUpdateDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../types'; 25 | import type { Guild } from '../../models/Guild'; 26 | import { GuildEmoji } from '../../models'; 27 | import Event from '../Event'; 28 | 29 | interface GuildEmojisUpdateRefs { 30 | emojis: EmojisUpdateRef; 31 | guild: PartialEntity; 32 | } 33 | 34 | interface EmojisUpdateRef { 35 | updated: GuildEmoji[]; 36 | old: GuildEmoji[]; 37 | } 38 | 39 | export default class GuildEmojisUpdateEvent extends Event< 40 | GatewayGuildEmojisUpdateDispatchData, 41 | GuildEmojisUpdateRefs 42 | > { 43 | get guild() { 44 | return this.$refs.guild; 45 | } 46 | 47 | process() { 48 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 49 | if (!guild.hasOwnProperty('emojis')) { 50 | this.$refs = { 51 | emojis: { updated: this.data.emojis.map(r => new GuildEmoji(this.client, r)), old: [] }, 52 | guild 53 | }; 54 | 55 | return; 56 | } 57 | 58 | const updated = this.data.emojis.map(r => new GuildEmoji(this.client, r)); 59 | const old = (guild as Guild).emojis.cache.toArray(); 60 | 61 | (guild as Guild).emojis.cache.clear(); 62 | 63 | for (let i = 0; i < updated.length; i++) (guild as Guild).emojis.add(updated[i]); 64 | 65 | this.$refs = { 66 | emojis: { updated, old }, 67 | guild 68 | }; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/events/guild/GuildIntegrationsUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildIntegrationsUpdateDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../types'; 25 | import type { Guild } from '../../models/Guild'; 26 | import Event from '../Event'; 27 | 28 | interface GuildIntegrationsUpdateRefs { 29 | guild: PartialEntity; 30 | } 31 | 32 | export default class GuildIntegrationsUpdateEvent extends Event< 33 | GatewayGuildIntegrationsUpdateDispatchData, 34 | GuildIntegrationsUpdateRefs 35 | > { 36 | get guild() { 37 | return this.$refs.guild; 38 | } 39 | 40 | process() { 41 | this.$refs = { 42 | guild: this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id } 43 | }; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/events/guild/GuildUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildUpdateDispatchData } from 'discord-api-types'; 24 | import { Guild } from '../../models/Guild'; 25 | import Event from '../Event'; 26 | 27 | interface GuildUpdateRefs { 28 | updated: Guild; 29 | old: Guild | null; 30 | } 31 | 32 | export default class GuildUpdateEvent extends Event { 33 | get old() { 34 | return this.$refs.old; 35 | } 36 | 37 | get guild() { 38 | return this.$refs.updated; 39 | } 40 | 41 | process() { 42 | const guild = this.client.guilds.get(this.data.id); 43 | if (guild === null) { 44 | const updated = new Guild(this.client, { shard_id: this.shard.id, ...this.data }); // eslint-disable-line camelcase 45 | this.$refs = { 46 | updated, 47 | old: null 48 | }; 49 | 50 | this.client.guilds.add(updated); 51 | return; 52 | } 53 | 54 | const old = guild; // keep a reference 55 | guild.patch({ shard_id: this.shard.id, ...this.data }); // eslint-disable-line camelcase 56 | this.client.guilds.add(guild); 57 | 58 | this.$refs = { 59 | updated: guild, 60 | old 61 | }; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/events/guild/bans/GuildBanAddEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildBanAddDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../../types'; 25 | import { Guild, User } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface GuildBanAddRefs { 29 | guild: PartialEntity; 30 | user: User; 31 | } 32 | 33 | export default class GuildBanAddEvent extends Event { 34 | get guild() { 35 | return this.$refs.guild; 36 | } 37 | 38 | get user() { 39 | return this.$refs.user; 40 | } 41 | 42 | process() { 43 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 44 | const user = new User(this.client, this.data.user); 45 | 46 | this.$refs = { guild, user }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/events/guild/bans/GuildBanRemoveEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildBanRemoveDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../../types'; 25 | import { Guild, User } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface GuildBanRemoveRefs { 29 | guild: PartialEntity; 30 | user: User; 31 | } 32 | 33 | export default class GuildBanAddEvent extends Event { 34 | get guild() { 35 | return this.$refs.guild; 36 | } 37 | 38 | get user() { 39 | return this.$refs.user; 40 | } 41 | 42 | process() { 43 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 44 | const user = new User(this.client, this.data.user); 45 | 46 | this.$refs = { guild, user }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/events/guild/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | // Guild Bans 24 | export { default as GuildBanRemoveEvent } from './bans/GuildBanRemoveEvent'; 25 | export { default as GuildBanAddEvent } from './bans/GuildBanAddEvent'; 26 | 27 | // Guild Member 28 | export { default as GuildMemberRemoveEvent } from './member/GuildMemberRemoveEvent'; 29 | export { default as GuildMemberUpdateEvent } from './member/GuildMemberUpdateEvent'; 30 | export { default as GuildMemberChunkEvent } from './member/GuildMemberChunkEvent'; 31 | export { default as GuildMemberAddEvent } from './member/GuildMemberAddEvent'; 32 | 33 | // Guild Roles 34 | export { default as GuildRoleDeleteEvent } from './roles/GuildRoleDeleteEvent'; 35 | export { default as GuildRoleUpdateEvent } from './roles/GuildRoleUpdateEvent'; 36 | export { default as GuildRoleCreateEvent } from './roles/GuildRoleCreateEvent'; 37 | 38 | // Guild 39 | export { default as GuildIntegrationsUpdateEvent } from './GuildIntegrationsUpdateEvent'; 40 | export { default as GuildEmojisUpdateEvent } from './GuildEmojisUpdateEvent'; 41 | export { default as GuildUpdateEvent } from './GuildUpdateEvent'; 42 | export { default as GuildCreateEvent } from './GuildCreateEvent'; 43 | export { default as GuildDeleteEvent } from './GuildDeleteEvent'; 44 | -------------------------------------------------------------------------------- /src/events/guild/member/GuildMemberAddEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildMemberAddDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../../types'; 25 | import { Guild, GuildMember } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface GuildMemberAddRefs { 29 | member: GuildMember; 30 | guild: PartialEntity; 31 | } 32 | 33 | export default class GuildMemberAddEvent extends Event { 34 | /** 35 | * Getter if the member hasn't passed the **Member Screening** panel. Use 36 | * a timeout (`setTimeout`) to check if `pending` is now the value you want. 37 | * 38 | * Useful for Autoroles and such. 39 | */ 40 | get pending() { 41 | return this.$refs.member.pending; 42 | } 43 | 44 | /** 45 | * Returns the reference for the member that joined the guild. 46 | */ 47 | get member() { 48 | return this.$refs.member; 49 | } 50 | 51 | /** 52 | * Returns a partial or a full guild, a partial guild only contains a object as 53 | * `{ id: String }` while a full guild has all metadata, this is purely based 54 | * on cache. 55 | */ 56 | get guild() { 57 | return this.$refs.guild; 58 | } 59 | 60 | process() { 61 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 62 | const member = new GuildMember(this.client, this.data); 63 | if (guild instanceof Guild) guild.members.add(member); 64 | 65 | this.$refs = { guild, member }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/events/guild/member/GuildMemberChunkEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildMembersChunkDispatchData } from 'discord-api-types'; 24 | import { Guild, GuildMember, Presence } from '../../../models'; 25 | import type { PartialEntity } from '../../../types'; 26 | import { Collection } from '@augu/collections'; 27 | import Event from '../../Event'; 28 | 29 | interface GuildMemberChunkRefs { 30 | chunkCount: number; 31 | chunkIndex: number; 32 | members: Collection; 33 | nonce?: string; 34 | guild: PartialEntity; 35 | } 36 | 37 | export default class GuildMemberChunkEvent extends Event { 38 | get chunkIndex() { 39 | return this.$refs.chunkIndex; 40 | } 41 | 42 | get chunkCount() { 43 | return this.$refs.chunkCount; 44 | } 45 | 46 | get members() { 47 | return this.$refs.members; 48 | } 49 | 50 | get nonce() { 51 | return this.$refs.nonce; 52 | } 53 | 54 | get guild() { 55 | return this.$refs.guild; 56 | } 57 | 58 | process() { 59 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 60 | const members = new Collection(); 61 | 62 | for (let i = 0; i < this.data.members.length; i++) { 63 | const member = this.data.members[i]; 64 | members.set(member.user!.id, new GuildMember(this.client, member)); 65 | } 66 | 67 | if (this.data.presences !== undefined) { 68 | for (let i = 0; i < this.data.presences.length; i++) { 69 | if (guild instanceof Guild) guild.presences.add(new Presence(this.client, this.data.presences[i])); 70 | } 71 | } 72 | 73 | this.$refs = { 74 | members, 75 | guild, 76 | chunkCount: this.data.chunk_count ?? 0, 77 | chunkIndex: this.data.chunk_index ?? 0, 78 | nonce: this.data.nonce 79 | }; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/events/guild/member/GuildMemberRemoveEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildMemberRemoveDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../../types'; 25 | import { Guild, GuildMember } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface GuildMemberRemoveRefs { 29 | member: GuildMember | null; 30 | guild: PartialEntity; 31 | } 32 | 33 | export default class GuildMemberRemoveEvent extends Event { 34 | get member() { 35 | return this.$refs.member; 36 | } 37 | 38 | get guild() { 39 | return this.$refs.guild; 40 | } 41 | 42 | process() { 43 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 44 | let member!: GuildMember | null; 45 | 46 | if (guild instanceof Guild) { 47 | const mlem = guild.members.get(this.data.user.id); 48 | if (mlem !== null) { 49 | member = mlem; 50 | guild.members.remove(member); 51 | } 52 | } 53 | 54 | this.$refs = { guild, member }; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/events/guild/member/GuildMemberUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildMemberUpdateDispatchData } from 'discord-api-types'; 24 | import { Guild, GuildMember } from '../../../models'; 25 | import { PartialEntity } from '../../../types'; 26 | import Event from '../../Event'; 27 | 28 | interface GuildMemberUpdateRefs { 29 | updated: GuildMember; 30 | old: PartialEntity | null; 31 | } 32 | 33 | export default class GuildMemberUpdateEvent extends Event { 34 | get member() { 35 | return this.$refs.updated; 36 | } 37 | 38 | get old() { 39 | return this.$refs.old; 40 | } 41 | 42 | process() { 43 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 44 | if (guild instanceof Guild) { 45 | if (this.data.user === undefined) { 46 | this.$refs = { old: null, updated: new GuildMember(this.client, this.data) }; 47 | return; 48 | } 49 | 50 | const member = guild.members.get(this.data.user.id) ?? { id: this.data.user.id }; 51 | let old = member; 52 | 53 | if (member instanceof GuildMember) { 54 | member.patch(this.data); 55 | guild.members.cache.set(member.user.id, member); 56 | 57 | this.$refs = { old, updated: member }; 58 | return; 59 | } 60 | } 61 | 62 | this.$refs = { 63 | updated: new GuildMember(this.client, this.data), 64 | old: this.data.user !== undefined ? { id: this.data.user.id } : null 65 | }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/events/guild/roles/GuildRoleCreateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildRoleCreateDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../../types'; 25 | import { Guild, GuildRole } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface GuildRoleCreateRefs { 29 | guild: PartialEntity; 30 | role: GuildRole; 31 | } 32 | 33 | export default class GuildRoleCreateEvent extends Event { 34 | get guild() { 35 | return this.$refs.guild; 36 | } 37 | 38 | get role() { 39 | return this.$refs.role; 40 | } 41 | 42 | process() { 43 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 44 | if (guild instanceof Guild) { 45 | const role = new GuildRole(this.client, { guild_id: guild.id, ...this.data.role }); // eslint-disable-line camelcase 46 | 47 | guild.roles.add(role); 48 | this.$refs = { role, guild }; 49 | 50 | return; 51 | } 52 | 53 | this.$refs = { 54 | role: new GuildRole(this.client, this.data.role as any), 55 | guild 56 | }; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/events/guild/roles/GuildRoleDeleteEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildRoleDeleteDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../../types'; 25 | import { Guild, GuildRole } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface GuildRoleDeleteRefs { 29 | guild: PartialEntity; 30 | role: PartialEntity; 31 | } 32 | 33 | export default class GuildRoleDeleteEvent extends Event { 34 | get guild() { 35 | return this.$refs.guild; 36 | } 37 | 38 | get role() { 39 | return this.$refs.role; 40 | } 41 | 42 | process() { 43 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 44 | if (guild instanceof Guild) { 45 | const role = guild.roles.get(this.data.role_id); 46 | if (role !== null) guild.roles.remove(role); 47 | 48 | this.$refs = { 49 | role: role ?? { id: this.data.role_id }, 50 | guild 51 | }; 52 | 53 | return; 54 | } 55 | 56 | this.$refs = { 57 | role: { id: this.data.role_id }, 58 | guild 59 | }; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/events/guild/roles/GuildRoleUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayGuildRoleUpdateDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../../types'; 25 | import { Guild, GuildRole } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface GuildRoleUpdateRefs { 29 | updated: GuildRole; 30 | old: PartialEntity; 31 | } 32 | 33 | export default class GuildRoleDeleteEvent extends Event { 34 | get role() { 35 | return this.$refs.updated; 36 | } 37 | 38 | get old() { 39 | return this.$refs.old; 40 | } 41 | 42 | process() { 43 | const guild = this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id }; 44 | if (guild instanceof Guild) { 45 | const role = guild.roles.get(this.data.role.id); 46 | if (role !== null) { 47 | const old = role; 48 | role.patch(this.data.role); 49 | 50 | this.$refs = { old, updated: role }; 51 | return; 52 | } 53 | } 54 | 55 | this.$refs = { 56 | old: { id: this.data.role.id }, 57 | updated: new GuildRole(this.client, this.data.role) 58 | }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/events/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | export { default as ChannelPinsUpdateEvent } from './channel/ChannelPinsUpdateEvent'; 24 | export { default as ChannelCreateEvent } from './channel/ChannelCreateEvent'; 25 | export { default as ChannelUpdateEvent } from './channel/ChannelUpdateEvent'; 26 | export { default as ChannelDeleteEvent } from './channel/ChannelDeleteEvent'; 27 | 28 | export { default as InviteCreateEvent } from './invites/InviteCreateEvent'; 29 | export { default as InviteDeleteEvent } from './invites/InviteDeleteEvent'; 30 | 31 | export * from './interaction'; 32 | export * from './presence'; 33 | export * from './message'; 34 | export * from './guild'; 35 | export * from './voice'; 36 | 37 | export * from './WebhooksUpdateEvent'; 38 | export * from './TypingStartEvent'; 39 | export * from './UserUpdateEvent'; 40 | -------------------------------------------------------------------------------- /src/events/interaction/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | export { default as InteractionCreateEvent } from './InteractionCreateEvent'; 24 | -------------------------------------------------------------------------------- /src/events/invites/InviteCreateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayInviteCreateDispatchData } from 'discord-api-types'; 24 | import type { TextableChannel, PartialEntity } from '../../types'; 25 | import GuildInvite from '../../models/guild/GuildInvite'; 26 | import Event from '../Event'; 27 | 28 | interface InviteCreateRefs { 29 | channel: PartialEntity; 30 | invite: GuildInvite; 31 | } 32 | 33 | export default class InviteCreateEvent extends Event { 34 | get channel() { 35 | return this.$refs.channel; 36 | } 37 | 38 | get invite() { 39 | return this.$refs.invite; 40 | } 41 | 42 | process() { 43 | this.$refs = { 44 | channel: this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id }, 45 | invite: new GuildInvite(this.client, this.data) 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/events/invites/InviteDeleteEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayInviteDeleteDispatchData } from 'discord-api-types'; 24 | import type { TextableChannel, PartialEntity } from '../../types'; 25 | import Event from '../Event'; 26 | 27 | interface InviteDeleteRefs { 28 | channel: PartialEntity; 29 | code: string; 30 | } 31 | 32 | export default class InviteDeleteEvent extends Event { 33 | get channel() { 34 | return this.$refs.channel; 35 | } 36 | 37 | get inviteCode() { 38 | return this.$refs.code; 39 | } 40 | 41 | process() { 42 | this.$refs = { 43 | channel: this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id }, 44 | code: this.data.code 45 | }; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/events/message/MessageCreateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayMessageCreateDispatchData } from 'discord-api-types'; 24 | import type { AnyChannel } from '../../types'; 25 | import type { Guild } from '../../models'; 26 | import { Message } from '../../models/Message'; 27 | import Event from '../Event'; 28 | 29 | interface MessageCreateRefs { 30 | channel: C; 31 | guild?: Guild; 32 | } 33 | 34 | export default class MessageCreateEvent extends Event> { 35 | get channel() { 36 | return this.$refs.channel; 37 | } 38 | 39 | get guild() { 40 | return this.$refs.guild; 41 | } 42 | 43 | get message() { 44 | return new Message(this.client, this.data); 45 | } 46 | 47 | async process() { 48 | const channel = this.client.channels.get(this.data.channel_id)! as C; 49 | const guild = this.data.guild_id !== undefined 50 | ? this.client.guilds.get(this.data.guild_id)! 51 | : undefined; 52 | 53 | if (channel !== null && ['news', 'text'].includes(channel.type)) { 54 | (channel as any).messages.cache.set(this.message.id, this.message); 55 | this.client.channels.cache.set(channel.id, channel); 56 | } 57 | 58 | this.$refs = { channel: (channel as unknown as C), guild }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/events/message/MessageDeleteBulkEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { AnyChannel, PartialEntity } from '../../types'; 24 | import type { GatewayMessageDeleteBulkDispatchData } from 'discord-api-types'; 25 | import { Guild, Message } from '../../models'; 26 | import Event from '../Event'; 27 | 28 | interface MessageDeleteBulkRefs { 29 | messages: PartialEntity[]; 30 | channel: PartialEntity; 31 | guild?: PartialEntity; 32 | } 33 | 34 | export default class MessageDeleteBulkEvent extends Event> { 35 | get messages() { 36 | return this.$refs.messages; 37 | } 38 | 39 | get channel() { 40 | return this.$refs.channel; 41 | } 42 | 43 | get guild() { 44 | return this.$refs.guild; 45 | } 46 | 47 | process() { 48 | const channel = this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id }; 49 | const guild = this.data.guild_id !== undefined 50 | ? this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id } 51 | : undefined; 52 | 53 | const messages: PartialEntity[] = []; 54 | if (!channel.hasOwnProperty('messages')) { 55 | messages.push(...this.data.ids.map(s => ({ id: s }))); 56 | this.$refs = { channel: (channel as unknown as C), guild, messages }; 57 | 58 | return; 59 | } 60 | 61 | for (let i = 0; i < this.data.ids.length; i++) { 62 | const id = this.data.ids[i]; 63 | const chan: any = channel; 64 | 65 | const message = chan.messages.get(id); 66 | if (message !== null) { 67 | chan.messages.remove(message.id); 68 | messages.push(message); 69 | } else { 70 | messages.push({ id }); 71 | } 72 | } 73 | 74 | this.$refs = { channel: (channel as unknown as C), guild, messages }; 75 | } 76 | } 77 | 78 | // henlo wah boi here <3 79 | -------------------------------------------------------------------------------- /src/events/message/MessageDeleteEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { AnyChannel, AnyGuildTextableChannel, PartialEntity } from '../../types'; 24 | import type { GatewayMessageDeleteDispatchData } from 'discord-api-types'; 25 | import type { Guild, Message } from '../../models'; 26 | import Event from '../Event'; 27 | 28 | interface MessageDeleteRefs { 29 | message: PartialEntity; 30 | channel: PartialEntity; 31 | guild?: PartialEntity; 32 | } 33 | 34 | export default class MessageDeleteEvent extends Event> { 35 | get message() { 36 | return this.$refs.message; 37 | } 38 | 39 | get channel() { 40 | return this.$refs.channel; 41 | } 42 | 43 | get guild() { 44 | return this.$refs.guild; 45 | } 46 | 47 | process() { 48 | const channel = this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id }; 49 | const guild = this.data.guild_id !== undefined 50 | ? this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id } 51 | : undefined; 52 | 53 | if (!( channel).messages) { 54 | this.shard.debug('Channel was not a text or news channel, skipping'); 55 | this.$refs = { 56 | channel: (channel as unknown as C), 57 | guild, 58 | message: { 59 | id: this.data.id 60 | } 61 | }; 62 | 63 | return; 64 | } 65 | 66 | const message = (channel as AnyGuildTextableChannel).messages.get(this.data.id) ?? { id: this.data.id }; 67 | this.$refs = { 68 | channel: (channel as unknown as C), 69 | guild, 70 | message 71 | }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/events/message/MessageUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { AnyChannel, PartialEntity } from '../../types'; 24 | import type { GatewayMessageUpdateDispatchData } from 'discord-api-types'; 25 | import { Message } from '../../models'; 26 | import Event from '../Event'; 27 | 28 | interface MessageUpdateRefs { 29 | message: PartialEntity; 30 | old: Message | null; 31 | } 32 | 33 | export default class MessageUpdateEvent extends Event> { 34 | get message() { 35 | return this.$refs.message; 36 | } 37 | 38 | get old() { 39 | return this.$refs.old; 40 | } 41 | 42 | process() { 43 | const message = this.data.hasOwnProperty('content') ? new Message(this.client, this.data) : { 44 | channel: this.client.channels.get(this.data.channel_id)!, 45 | id: this.data.id 46 | } as PartialEntity; 47 | 48 | const old = this.client.channels.get(this.data.channel_id)?.messages?.get(this.data.id) ?? null; 49 | 50 | this.$refs = { message: (message as any), old }; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/events/message/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | export { default as MessageReactionRemoveEmojiEvent } from './reaction/MessageReactionRemoveEmojiEvent'; 24 | export { default as MessageReactionRemoveAllEvent } from './reaction/MessageReactionRemoveAllEvent'; 25 | export { default as MessageReactionRemoveEvent } from './reaction/MessageReactionRemoveEvent'; 26 | export { default as MessageReactionAddEvent } from './reaction/MessageReactionAddEvent'; 27 | 28 | export { default as MessageDeleteBulkEvent } from './MessageDeleteBulkEvent'; 29 | export { default as MessageDeleteEvent } from './MessageDeleteEvent'; 30 | export { default as MessageUpdateEvent } from './MessageUpdateEvent'; 31 | export { default as MessageCreateEvent } from './MessageCreateEvent'; 32 | -------------------------------------------------------------------------------- /src/events/message/reaction/MessageReactionAddEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { AnyGuildTextableChannel, PartialEntity, TextableChannel } from '../../../types'; 24 | import { Guild, GuildEmoji, GuildMember, Message, User } from '../../../models'; 25 | import type { GatewayMessageReactionAddDispatchData } from 'discord-api-types'; 26 | import Event from '../../Event'; 27 | 28 | interface MessageReactionAddRefs { 29 | message: PartialEntity; 30 | channel: PartialEntity; 31 | member?: PartialEntity; 32 | guild?: Guild; 33 | emoji: GuildEmoji; 34 | user: PartialEntity; 35 | } 36 | 37 | export default class MessageReactionAddEvent extends Event { 38 | get message() { 39 | return this.$refs.message; 40 | } 41 | 42 | get channel() { 43 | return this.$refs.channel; 44 | } 45 | 46 | get emoji() { 47 | return this.$refs.emoji; 48 | } 49 | 50 | get user() { 51 | return this.$refs.user; 52 | } 53 | 54 | get member() { 55 | return this.$refs.member; 56 | } 57 | 58 | process() { 59 | const channel: PartialEntity = this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id }; 60 | const message = (channel as AnyGuildTextableChannel).messages?.get(this.data.message_id) ?? { id: this.data.message_id }; 61 | const guild = this.data.guild_id !== undefined ? this.client.guilds.get(this.data.guild_id) : undefined; 62 | const member = this.data.member !== undefined && this.data.member.user !== undefined 63 | ? guild?.members.get(this.data.member.user.id) ?? { id: this.data.member.user.id } 64 | : undefined; 65 | 66 | const user = this.client.users.get(this.data.user_id) ?? { id: this.data.user_id }; 67 | this.$refs = { 68 | channel, 69 | message, 70 | member, 71 | emoji: new GuildEmoji(this.client, this.data.emoji), 72 | user 73 | }; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/events/message/reaction/MessageReactionRemoveAllEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { AnyGuildTextableChannel, PartialEntity, TextableChannel } from '../../../types'; 24 | import type { GatewayMessageReactionRemoveAllDispatchData } from 'discord-api-types'; 25 | import type { Guild, Message } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface MessageReactionRemoveAllRefs { 29 | message: PartialEntity; 30 | channel: PartialEntity; 31 | guild?: PartialEntity; 32 | } 33 | 34 | export default class MessageReactionRemoveAllEvent extends Event< 35 | GatewayMessageReactionRemoveAllDispatchData, 36 | MessageReactionRemoveAllRefs 37 | > { 38 | get message() { 39 | return this.$refs.message; 40 | } 41 | 42 | get channel() { 43 | return this.$refs.channel; 44 | } 45 | 46 | get guild() { 47 | return this.$refs.guild; 48 | } 49 | 50 | process() { 51 | const channel = this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id }; 52 | const message = (channel as AnyGuildTextableChannel).messages?.get(this.data.message_id) ?? { id: this.data.message_id }; 53 | const guild = this.data.guild_id !== undefined ? this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id } : undefined; 54 | 55 | this.$refs = { 56 | channel, 57 | message, 58 | guild 59 | }; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/events/message/reaction/MessageReactionRemoveEmojiEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { AnyGuildTextableChannel, PartialEntity, TextableChannel } from '../../../types'; 24 | import type { GatewayMessageReactionRemoveEmojiDispatchData } from 'discord-api-types'; 25 | import { Guild, GuildEmoji, Message } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface MessageReactionRemoveEmojiRefs { 29 | message: PartialEntity; 30 | channel: PartialEntity; 31 | guild?: PartialEntity; 32 | emoji: GuildEmoji; 33 | } 34 | 35 | export default class MessageReactionRemoveEmojiEvent extends Event< 36 | GatewayMessageReactionRemoveEmojiDispatchData, 37 | MessageReactionRemoveEmojiRefs 38 | > { 39 | get message() { 40 | return this.$refs.message; 41 | } 42 | 43 | get channel() { 44 | return this.$refs.channel; 45 | } 46 | 47 | get guild() { 48 | return this.$refs.guild; 49 | } 50 | 51 | get emoji() { 52 | return this.$refs.emoji; 53 | } 54 | 55 | process() { 56 | const channel = this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id }; 57 | const message = (channel as AnyGuildTextableChannel).messages?.get(this.data.message_id) ?? { id: this.data.message_id }; 58 | const guild = this.data.guild_id !== undefined ? this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id } : undefined; 59 | 60 | this.$refs = { 61 | channel, 62 | message, 63 | guild, 64 | emoji: new GuildEmoji(this.client, this.data.emoji) 65 | }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/events/message/reaction/MessageReactionRemoveEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { AnyGuildTextableChannel, PartialEntity, TextableChannel } from '../../../types'; 24 | import type { GatewayMessageReactionRemoveDispatchData } from 'discord-api-types'; 25 | import { Guild, GuildEmoji, Message } from '../../../models'; 26 | import Event from '../../Event'; 27 | 28 | interface MessageReactionRemoveRefs { 29 | message: PartialEntity; 30 | channel: PartialEntity; 31 | guild?: PartialEntity; 32 | emoji: GuildEmoji; 33 | } 34 | 35 | export default class MessageReactionRemoveEvent extends Event< 36 | GatewayMessageReactionRemoveDispatchData, 37 | MessageReactionRemoveRefs 38 | > { 39 | get message() { 40 | return this.$refs.message; 41 | } 42 | 43 | get channel() { 44 | return this.$refs.channel; 45 | } 46 | 47 | get guild() { 48 | return this.$refs.guild; 49 | } 50 | 51 | get emoji() { 52 | return this.$refs.emoji; 53 | } 54 | 55 | process() { 56 | const channel = this.client.channels.get(this.data.channel_id) ?? { id: this.data.channel_id }; 57 | const message = (channel as AnyGuildTextableChannel).messages?.get(this.data.message_id) ?? { id: this.data.message_id }; 58 | const guild = this.data.guild_id !== undefined ? this.client.guilds.get(this.data.guild_id) ?? { id: this.data.guild_id } : undefined; 59 | 60 | this.$refs = { 61 | channel, 62 | message, 63 | guild, 64 | emoji: new GuildEmoji(this.client, this.data.emoji) 65 | }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/events/presence/PresenceUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayPresenceUpdateDispatchData } from 'discord-api-types'; 24 | import { Guild, Presence, User } from '../../models'; 25 | import type { PartialEntity } from '../../types'; 26 | import Event from '../Event'; 27 | 28 | interface PresenceUpdateRefs { 29 | presence: Presence; 30 | guild: PartialEntity | null; 31 | user: PartialEntity; 32 | old: Presence | null; 33 | } 34 | 35 | export default class PresenceUpdateEvent extends Event { 36 | get new() { 37 | return this.$refs.presence; 38 | } 39 | 40 | get old() { 41 | return this.$refs.old; 42 | } 43 | 44 | get user() { 45 | return this.$refs.user; 46 | } 47 | 48 | get guild() { 49 | return this.$refs.guild; 50 | } 51 | 52 | process() { 53 | const guild = this.data.guild_id !== undefined 54 | ? this.client.guilds.get(this.data.guild_id) 55 | : null; 56 | 57 | const old = guild?.presences.get(this.data.user.id) ?? null; 58 | const user = this.client.users.get(this.data.user.id) || { id: this.data.user.id }; 59 | 60 | if (user!.id !== this.data.user.id) return; 61 | 62 | this.$refs = { 63 | presence: new Presence(this.client, this.data), 64 | guild, 65 | user, 66 | old 67 | }; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/events/presence/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | export { default as PresenceUpdateEvent } from './PresenceUpdateEvent'; 24 | -------------------------------------------------------------------------------- /src/events/voice/VoiceServerUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayVoiceServerUpdateDispatchData } from 'discord-api-types'; 24 | import type { PartialEntity } from '../../types'; 25 | import type { Guild } from '../../models'; 26 | import Event from '../Event'; 27 | 28 | interface VoiceServerUpdateRefs { 29 | endpoint: string; 30 | guild: PartialEntity; 31 | token: string; 32 | } 33 | 34 | export default class VoiceServerUpdateEvent extends Event { 35 | get token() { 36 | return this.$refs.token; 37 | } 38 | 39 | get guild() { 40 | return this.$refs.guild; 41 | } 42 | 43 | get endpoint() { 44 | return this.$refs.endpoint; 45 | } 46 | 47 | process() { 48 | this.$refs = { 49 | endpoint: this.data.endpoint, 50 | guild: this.client.guilds.get(this.data.guild_id) || { id: this.data.guild_id }, 51 | token: this.data.token 52 | }; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/events/voice/VoiceStateUpdateEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GatewayVoiceStateUpdateDispatchData } from 'discord-api-types'; 24 | import type { AnyChannel, PartialEntity } from '../../types'; 25 | import { Guild, VoiceState } from '../../models'; 26 | import Event from '../Event'; 27 | 28 | interface VoiceStateUpdateRefs { 29 | channel: PartialEntity | null; 30 | guild: PartialEntity | null; 31 | state: VoiceState; 32 | } 33 | 34 | export default class VoiceStateUpdateEvent extends Event { 35 | get channel() { 36 | return this.$refs.channel; 37 | } 38 | 39 | get guild() { 40 | return this.$refs.guild; 41 | } 42 | 43 | get voiceState() { 44 | return this.$refs.state; 45 | } 46 | 47 | process() { 48 | const channel = this.data.channel_id !== null 49 | ? this.client.channels.get(this.data.channel_id) || { id: this.data.channel_id } 50 | : null; 51 | 52 | const guild = this.data.guild_id !== undefined 53 | ? this.client.guilds.get(this.data.guild_id) || { id: this.data.guild_id } 54 | : null; 55 | 56 | const voiceState = new VoiceState(this.client, this.data); 57 | this.$refs = { 58 | channel, 59 | guild, 60 | state: voiceState 61 | }; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/events/voice/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | export { default as VoiceServerUpdateEvent } from './VoiceServerUpdateEvent'; 24 | export { default as VoiceStateUpdateEvent } from './VoiceStateUpdateEvent'; 25 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | const { version: pkgVersion } = require('../package.json'); 24 | 25 | export { default as InteractionClient } from './interactions/InteractionClient'; 26 | export { DiscordRestError } from './errors/DiscordRestError'; 27 | export { DiscordAPIError } from './errors/DiscordAPIError'; 28 | export { default as Client } from './gateway/WebSocketClient'; 29 | 30 | export * as Constants from './Constants'; 31 | 32 | export * from './interactions/types'; 33 | export * from './events'; 34 | export * from './models'; 35 | export * from './types'; 36 | 37 | // export misc types 38 | export { InteractionClientEvents } from './interactions/InteractionClient'; 39 | export { WebSocketClientEvents } from './gateway/WebSocketClient'; 40 | 41 | /** Returns the version of Wumpcord */ 42 | export const version: string = pkgVersion; 43 | -------------------------------------------------------------------------------- /src/interactions/Command.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type * as interactions from './types'; 24 | import Base from '../models/Base'; 25 | 26 | interface ApplicationCommand extends interactions.ApplicationCommand { 27 | is_guild?: boolean; // eslint-disable-line camelcase 28 | } 29 | 30 | /** 31 | * Represents a interaction command 32 | */ 33 | export default class InteractionCommand extends Base { 34 | /** The application's ID that this command belongs to */ 35 | public applicationID!: string; 36 | 37 | /** The description of the slash command */ 38 | public description!: string; 39 | 40 | /** If the slash command belongs to a guild or is global */ 41 | public isGuild!: boolean; 42 | 43 | /** Any additional options used to run this slash command */ 44 | public options?: interactions.ApplicationCommandOption[]; 45 | 46 | /** The name of the slash command */ 47 | public name!: string; 48 | 49 | constructor(data: ApplicationCommand) { 50 | super(data.id); 51 | 52 | this.patch(data); 53 | } 54 | 55 | patch(data: ApplicationCommand) { 56 | if (data.application_id !== undefined) 57 | this.applicationID = data.application_id; 58 | 59 | if (data.description !== undefined) 60 | this.description = data.description; 61 | 62 | if (data.options !== undefined) 63 | this.options = data.options; 64 | 65 | if (data.is_guild !== undefined) 66 | this.isGuild = data.is_guild ?? false; // we pass this, not discord 67 | 68 | if (data.name !== undefined) 69 | this.name = data.name; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/interactions/InteractionClient.ts: -------------------------------------------------------------------------------- 1 | import WebSocketClient, { WebSocketClientEvents } from '../gateway/WebSocketClient'; 2 | import InteractionCreateEvent from '../events/interaction/InteractionCreateEvent'; 3 | import InteractionHelper from './Helper'; 4 | import { ClientOptions } from '../types'; 5 | 6 | export interface InteractionClientEvents extends WebSocketClientEvents { 7 | interactionReceive(event: InteractionCreateEvent): void; 8 | } 9 | 10 | export default class InteractionClient< 11 | Options extends ClientOptions = ClientOptions, 12 | Events extends InteractionClientEvents = InteractionClientEvents 13 | > extends WebSocketClient { 14 | /** The interactions helper */ 15 | public readonly interactions: InteractionHelper = new InteractionHelper(this); 16 | } 17 | -------------------------------------------------------------------------------- /src/interactions/types.ts: -------------------------------------------------------------------------------- 1 | // Credit: https://github.com/FurryBotCo/FurryBot/blob/master/src/util/DiscordCommands/types.d.ts 2 | /* eslint-disable camelcase */ 3 | 4 | export interface ApplicationCommand extends IApplicationCommand { 5 | application_id: string; 6 | id: string; 7 | } 8 | 9 | export interface IApplicationCommand { 10 | description: string; 11 | options?: ApplicationCommandOption[]; 12 | name: string; 13 | } 14 | 15 | export type ApplicationCommandOptionChoiceArray = [ 16 | ApplicationCommandOptionChoice?, 17 | ApplicationCommandOptionChoice?, 18 | ApplicationCommandOptionChoice?, 19 | ApplicationCommandOptionChoice?, 20 | ApplicationCommandOptionChoice?, 21 | ApplicationCommandOptionChoice?, 22 | ApplicationCommandOptionChoice?, 23 | ApplicationCommandOptionChoice?, 24 | ApplicationCommandOptionChoice?, 25 | ApplicationCommandOptionChoice? 26 | ]; 27 | 28 | export interface ApplicationCommandOption { 29 | description: string; 30 | required?: boolean; 31 | default?: boolean; 32 | options?: ApplicationCommandOption[]; 33 | choices?: ApplicationCommandOptionChoiceArray; 34 | type: typeof ApplicationCommandOptionType[keyof typeof ApplicationCommandOptionType]; 35 | name: string; 36 | } 37 | 38 | export interface ApplicationCommandOptionChoice { 39 | value: string; 40 | name: string; 41 | } 42 | 43 | export interface Interaction { 44 | channel_id: string; 45 | guild_id: string; 46 | version: number; 47 | member: any; 48 | token: string; 49 | data: ApplicationCommandInteractionData; 50 | type: typeof InteractionType[keyof typeof InteractionType]; 51 | } 52 | 53 | export interface ApplicationCommandInteractionData { 54 | options?: ApplicationCommandInteractionDataOption[]; 55 | name: string; 56 | id: string; 57 | } 58 | 59 | export interface ApplicationCommandInteractionDataOption { 60 | options?: ApplicationCommandInteractionDataOption[]; 61 | value?: unknown; 62 | name: string; 63 | } 64 | 65 | export interface InteractionResponse { 66 | data?: InteractionApplicationCommandCallbackData; 67 | type: typeof InteractionResponseType[keyof typeof InteractionResponseType]; 68 | } 69 | 70 | export interface InteractionApplicationCommandCallbackData { 71 | allowed_mentions?: any; 72 | embeds?: any; 73 | content: string; 74 | tts?: boolean; 75 | } 76 | 77 | export enum ApplicationCommandOptionType { 78 | SUB_COMMAND = 1, 79 | SUB_COMMAND_GROUP = 2, 80 | STRING = 3, 81 | INTEGER = 4, 82 | BOOLEAN = 5, 83 | USER = 6, 84 | CHANNEL = 7, 85 | ROLE = 8 86 | } 87 | 88 | export enum InteractionType { 89 | PING = 1, 90 | APPLICATION_COMMAND = 2 91 | } 92 | 93 | export enum InteractionResponseType { 94 | PONG = 1, 95 | 96 | /** @deprecated */ 97 | ACKNOWLEDGE = 2, 98 | 99 | /** @deprecated */ 100 | CHANNEL_MESSAGE = 3, 101 | 102 | CHANNEL_MESSAGE_WITH_SOURCE = 4, 103 | 104 | ACK_WITH_SOURCE = 5 105 | } 106 | -------------------------------------------------------------------------------- /src/managers/ChannelManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import { Channel } from '../models'; 25 | import BaseManager from './BaseManager'; 26 | 27 | export default class ChannelManager extends BaseManager { 28 | /** 29 | * Creates a new [ChannelManager] instance 30 | * @param client The [WebSocketClient] attached to it 31 | */ 32 | constructor(client: WebSocketClient) { 33 | super(client, Channel); 34 | } 35 | 36 | /** 37 | * Fetches a channel from Discord and caches it if we can 38 | * @param id The channel's ID 39 | */ 40 | fetch(id: string) { 41 | return this.client.rest.dispatch({ 42 | endpoint: `/channels/${id}`, 43 | method: 'GET' 44 | }).then(data => this.add(Channel.from(this.client, data)) as T); 45 | } 46 | 47 | /** 48 | * @inheritdoc 49 | */ 50 | get(id: string) { 51 | return super.get(id) as T | null; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/managers/ChannelMessagesManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import { APIMessage } from 'discord-api-types'; 24 | import type WebSocketClient from '../gateway/WebSocketClient'; 25 | import { Message } from '../models'; 26 | import BaseManager from './BaseManager'; 27 | 28 | export default class ChannelMessagesManager extends BaseManager { 29 | constructor(client: WebSocketClient) { 30 | super(client, Message); 31 | } 32 | 33 | fetch(channelID: string, messageID: string) { 34 | return this.client.rest.dispatch({ 35 | endpoint: `/channels/${channelID}/messages/${messageID}`, 36 | method: 'GET' 37 | }).then((data) => this.add(new Message(this.client, data))); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/managers/GuildEmojiManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import type { APIEmoji } from 'discord-api-types'; 25 | import { GuildEmoji } from '../models'; 26 | import BaseManager from './BaseManager'; 27 | 28 | export default class GuildEmojiManager extends BaseManager { 29 | constructor(client: WebSocketClient) { 30 | super(client, GuildEmoji); 31 | } 32 | 33 | fetch(guildID: string, emojiID: string) { 34 | return this.client.rest.dispatch({ 35 | endpoint: `/guilds/${guildID}/emojis/${emojiID}`, 36 | method: 'GET' 37 | }).then(data => this.add(new GuildEmoji(this.client, { guild_id: guildID, ...data }))); // eslint-disable-line camelcase 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/managers/GuildManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import type { APIGuild } from 'discord-api-types'; 25 | import UnavailableGuild from '../models/guild/UnavailableGuild'; 26 | import BaseManager from './BaseManager'; 27 | import { Guild } from '../models'; 28 | 29 | export default class GuildManager extends BaseManager { 30 | constructor(client: WebSocketClient) { 31 | super(client, Guild); 32 | } 33 | 34 | fetch(id: string) { 35 | return this.client.rest.dispatch({ 36 | endpoint: `/guilds/${id}`, 37 | method: 'GET' 38 | }).then(data => { 39 | const shard = this.client.shards.filter(shard => shard.guilds.has(data.id)); 40 | let shardID = 0; 41 | 42 | if (shard.length > 0) shardID = shard[0].id; 43 | if (data.unavailable !== undefined && data.unavailable === true) return this.add(new UnavailableGuild({ 44 | shard_id: shardID, // eslint-disable-line camelcase 45 | unavailable: true, 46 | id: data.id 47 | })); 48 | 49 | return this.add(new Guild(this.client, { shard_id: shardID, ...data })); // eslint-disable-line camelcase 50 | }); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/managers/GuildMemberManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { APIGuildMember } from 'discord-api-types'; 24 | import type WebSocketClient from '../gateway/WebSocketClient'; 25 | import { GuildMember } from '../models'; 26 | import BaseManager from './BaseManager'; 27 | 28 | export default class GuildMemberManager extends BaseManager { 29 | constructor(client: WebSocketClient) { 30 | super(client, GuildMember); 31 | } 32 | 33 | fetch(guildID: string, memberID: string) { 34 | return this.client.rest.dispatch({ 35 | endpoint: `/guilds/${guildID}/members/${memberID}`, 36 | method: 'GET' 37 | }).then((data) => this.add(new GuildMember(this.client, { guild_id: guildID, ...data }))); // eslint-disable-line camelcase 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/managers/GuildPresencesManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import { Presence } from '../models'; 25 | import BaseManager from './BaseManager'; 26 | 27 | export default class GuildPresencesManager extends BaseManager { 28 | constructor(client: WebSocketClient) { 29 | super(client, Presence); 30 | } 31 | 32 | // Guild Presences can't be fetched, so let's not override it 33 | } 34 | -------------------------------------------------------------------------------- /src/managers/GuildRoleManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import { DiscordRestError } from '../errors/DiscordRestError'; 25 | import type { APIRole } from 'discord-api-types'; 26 | import BaseManager from './BaseManager'; 27 | import GuildRole from '../models/guild/GuildRole'; 28 | 29 | export default class GuildRoleManager extends BaseManager { 30 | constructor(client: WebSocketClient) { 31 | super(client, GuildRole); 32 | } 33 | 34 | fetch(guildID: string, roleID: string) { 35 | return this.client.rest.dispatch({ 36 | endpoint: `/guilds/${guildID}/roles`, 37 | method: 'GET' 38 | }).then(data => { 39 | const role = data.find(role => role.id === roleID); 40 | if (!role) throw new DiscordRestError(404, `Role "${roleID}" was not found in guild "${guildID}"`); 41 | 42 | return this.add(new GuildRole(this.client, { guild_id: guildID, ...role })); // eslint-disable-line camelcase 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/managers/GuildVoiceStateManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import { VoiceState } from '../models/VoiceState'; 25 | import BaseManager from './BaseManager'; 26 | 27 | export default class GuildVoiceStateManager extends BaseManager { 28 | constructor(client: WebSocketClient) { 29 | super(client, VoiceState); 30 | } 31 | 32 | // Voice States can't be fetched, so let's not override it 33 | } 34 | -------------------------------------------------------------------------------- /src/managers/UserManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import type { APIUser } from 'discord-api-types'; 25 | import BaseManager from './BaseManager'; 26 | import { User } from '../models'; 27 | 28 | export default class UserManager extends BaseManager { 29 | constructor(client: WebSocketClient) { 30 | super(client, User); 31 | } 32 | 33 | /** 34 | * Fetches a channel from Discord and caches it if we can 35 | * @param id The channel's ID 36 | */ 37 | fetch(id: string) { 38 | return this.client.rest.dispatch({ 39 | endpoint: `/users/${id}`, 40 | method: 'GET' 41 | }).then(data => this.add(new User(this.client, data))); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/models/Attachment.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { APIAttachment } from 'discord-api-types'; 24 | import Base from './Base'; 25 | 26 | export class Attachment extends Base { 27 | public proxyUrl: string; 28 | public height: number | null; 29 | public width: number | null; 30 | public size: number; 31 | public url: string; 32 | 33 | constructor(data: APIAttachment) { 34 | super(data.id); 35 | 36 | this.proxyUrl = data.proxy_url; 37 | this.height = data.height; 38 | this.width = data.width; 39 | this.size = data.size; 40 | this.url = data.url; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/models/Base.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | const EPOCH = 1420070400000; 24 | const DELTA = 4194304; 25 | 26 | /** 27 | * Represents a base entity 28 | * @template D The data payload from Discord 29 | */ 30 | export default class Base { 31 | /** The entity's ID */ 32 | public id!: string; 33 | 34 | /** 35 | * Creates a new [Base] instance 36 | * @param id The ID of the entity 37 | */ 38 | constructor(id?: string) { 39 | if (id) this.id = id; 40 | } 41 | 42 | /** 43 | * Patches any updates from Discord 44 | * @param data The data payload 45 | */ 46 | patch(data: D) { 47 | // noop 48 | } 49 | 50 | /** 51 | * Returns when the entity was created at 52 | */ 53 | get createdAt() { 54 | return new Date(Math.floor(Number(this.id) / DELTA) + EPOCH); 55 | } 56 | 57 | toString() { 58 | return `[wumpcord.Base (${this.id ?? ''})]`; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/models/Channel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { APIPartialChannel } from 'discord-api-types/v8'; 24 | import type WebSocketClient from '../gateway/WebSocketClient'; 25 | import type { AnyChannel } from '../types'; 26 | import { ChannelTypesObject } from '../Constants'; 27 | import Base from './Base'; 28 | 29 | export class Channel extends Base { 30 | /** The type of channel */ 31 | public type!: 'text' | 'dm' | 'voice' | 'group' | 'category' | 'news' | 'store' | 'stage'; 32 | 33 | constructor(data: APIPartialChannel) { 34 | super(data.id); 35 | 36 | this.patch(data); 37 | } 38 | 39 | patch(data: APIPartialChannel) { 40 | this.type = ChannelTypesObject[data.type]; 41 | } 42 | 43 | /** 44 | * Statically create a channel from it's type 45 | * @param client The client to construct a channel 46 | * @param data The data received from Discord 47 | * @returns An [[AnyChannel]] type of what was received. Use the [T] generic 48 | * to return whatever you specified (for TypeScript users) 49 | */ 50 | static from(client: WebSocketClient, data: any): T | null { 51 | const { NewsChannel } = require('./channel/NewsChannel'); 52 | const { DMChannel } = require('./channel/DMChannel'); 53 | const { TextChannel } = require('./channel/TextChannel'); 54 | const { CategoryChannel } = require('./channel/CategoryChannel'); 55 | const { VoiceChannel } = require('./channel/VoiceChannel'); 56 | const { StoreChannel } = require('./channel/StoreChannel'); 57 | const { GroupChannel } = require('./channel/GroupChannel'); 58 | const { StageChannel } = require('./channel/StageChannel'); 59 | 60 | switch (data.type) { 61 | case 0: return new TextChannel(client, data); 62 | case 1: return new DMChannel(client, data); 63 | case 2: return new VoiceChannel(data); 64 | case 3: return new GroupChannel(client, data); 65 | case 4: return new CategoryChannel(data); 66 | case 5: return new NewsChannel(client, data); 67 | case 6: return new StoreChannel(client, data); 68 | case 13: return new StageChannel(data); 69 | default: 70 | client.debug(`Unknown Type [${data.type}]`, 'Channel type is not available on this version of Wumpcord you\'re running. Switch to indev branch or submit a PR?'); 71 | return null; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/models/PermissionOverwrite.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import { APIOverwrite, OverwriteType } from 'discord-api-types'; 24 | import Permission from '../util/Permissions'; 25 | import Base from './Base'; 26 | 27 | export class PermissionOverwrite extends Base { 28 | /** List of permissions available for this [PermissionOverwrite] */ 29 | public permissions!: Permission; 30 | 31 | /** The overwrite type */ 32 | public type!: 'role' | 'member'; 33 | 34 | /** 35 | * Creates a new [PermissionOverwrite] instance 36 | * @param data The data from Discord 37 | */ 38 | constructor(data: APIOverwrite) { 39 | super(data.id); 40 | 41 | this.patch(data); 42 | } 43 | 44 | patch(data: APIOverwrite) { 45 | this.permissions = new Permission(data.allow, data.deny); 46 | this.type = data.type === OverwriteType.Role ? 'role' : 'member'; 47 | } 48 | 49 | toString() { 50 | return `[wumpcord.PermissionOverwrite]`; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/models/SelfUser.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../gateway/WebSocketClient'; 24 | import type { APIUser } from 'discord-api-types'; 25 | import { User } from './User'; 26 | 27 | export class SelfUser extends User { 28 | /** If the user has MFA enabled (why do bots have this) */ 29 | public mfaEnabled!: boolean; 30 | 31 | /** If the bot is verified or not */ 32 | public verified!: boolean; 33 | 34 | /** 35 | * Creates a new [SelfUser] instance 36 | * @param client The [WebSocketClient] attached 37 | * @param data The data supplied from Discord 38 | */ 39 | constructor(client: WebSocketClient, data: APIUser) { 40 | super(client, data); 41 | 42 | this.patch(data); 43 | } 44 | 45 | patch(data: APIUser) { 46 | super.patch(data); 47 | 48 | if (data.mfa_enabled !== undefined) 49 | this.mfaEnabled = data.mfa_enabled; 50 | 51 | if (data.verified !== undefined) 52 | this.verified = data.verified; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/models/Template.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { APITemplate } from 'discord-api-types'; 24 | import type WebSocketClient from '../gateway/WebSocketClient'; 25 | import { Guild } from './Guild'; 26 | 27 | export class Template { 28 | public sourceGuildID!: string; 29 | public description!: string | null; 30 | public sourceGuild!: Guild; 31 | public usageCount!: number; 32 | public createdAt!: Date; 33 | public updatedAt!: Date; 34 | public creatorID!: string; 35 | public unsynced!: boolean; 36 | private client: WebSocketClient; 37 | public code!: string; 38 | public name!: string; 39 | 40 | constructor(client: WebSocketClient, data: APITemplate) { 41 | this.client = client; 42 | this.patch(data); 43 | } 44 | 45 | private patch(data: APITemplate) { 46 | if (data.serialized_source_guild !== undefined) 47 | this.sourceGuild = this.client.guilds.add(new Guild(this.client, data.serialized_source_guild)); 48 | 49 | if (data.source_guild_id !== undefined) 50 | this.sourceGuildID = data.source_guild_id; 51 | 52 | if (data.updated_at !== undefined) 53 | this.updatedAt = new Date(data.updated_at); 54 | 55 | if (data.created_at !== undefined) 56 | this.createdAt = new Date(data.created_at); 57 | 58 | if (data.description !== undefined) 59 | this.description = data.description; 60 | 61 | if (data.creator_id !== undefined) 62 | this.creatorID = data.creator_id; 63 | 64 | if (data.usage_count !== undefined) 65 | this.usageCount = data.usage_count; 66 | 67 | if (data.is_dirty !== undefined) 68 | this.unsynced = Boolean(data.is_dirty); 69 | 70 | if (data.code !== undefined) 71 | this.code = data.code; 72 | 73 | if (data.name !== undefined) 74 | this.name = data.name; 75 | } 76 | 77 | fetch() { 78 | return this.client.rest.dispatch({ 79 | endpoint: `/guilds/templates/${this.code}`, 80 | method: 'GET' 81 | }).then(data => { 82 | this.patch(data); 83 | return this; 84 | }); 85 | } 86 | 87 | get url() { 88 | return `https://discord.new/${this.code}`; 89 | } 90 | 91 | toString() { 92 | return `[wumpcord.Template<${this.url}>]`; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/models/audits/AuditLogs.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { APIAuditLog } from 'discord-api-types/v8'; 24 | import type WebSocketClient from '../../gateway/WebSocketClient'; 25 | import GuildIntegration from '../guild/GuildIntegration'; 26 | import AuditLogEntry from './AuditLogEntry'; 27 | import { Webhook } from '../Webhook'; 28 | import { User } from '../User'; 29 | 30 | export default class AuditLogs { 31 | /** List of intergrations affected in the audit logs */ 32 | public integrations!: GuildIntegration[]; 33 | 34 | /** The [WebSocketClient] attached */ 35 | private client: WebSocketClient; 36 | 37 | /** List of webhooks affected in the audit logs */ 38 | public webhooks!: Webhook[]; 39 | 40 | /** List of available entries */ 41 | public entries!: AuditLogEntry[]; 42 | 43 | /** Any users affected in the audit logs */ 44 | public users!: User[]; 45 | 46 | /** 47 | * Creates a new [AuditLogEntry] instance 48 | * @param client The WebSocket client attached 49 | * @param data The data from Discord 50 | */ 51 | constructor(client: WebSocketClient, data: APIAuditLog) { 52 | this.client = client; 53 | this.patch(data); 54 | } 55 | 56 | private patch(data: APIAuditLog) { 57 | this.integrations = data.integrations.map(integration => new GuildIntegration(this.client, integration)); 58 | this.webhooks = data.webhooks.map(webhook => new Webhook(this.client, webhook)); 59 | this.entries = data.audit_log_entries.map(data => new AuditLogEntry(this.client, data)); 60 | this.users = data.users.map(user => this.client.users.add(new User(this.client, user))); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/models/channel/CategoryChannel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { AnyGuildChannel } from '../../types'; 24 | import GuildChannel from './GuildChannel'; 25 | 26 | export class CategoryChannel extends GuildChannel { 27 | /** 28 | * Returns the childern list of this [CategoryChannel] 29 | */ 30 | get children(): AnyGuildChannel[] { 31 | return this['client'].channels.cache.filter((channel: GuildChannel) => 32 | (channel.hasOwnProperty('parentID') && channel.parentID !== null) && 33 | channel.parentID === this.id 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/models/channel/DMChannel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../../gateway/WebSocketClient'; 24 | import type { APIChannel } from 'discord-api-types/v8'; 25 | import TextableChannel from '../inherit/TextableChannel'; 26 | import { User } from '../User'; 27 | 28 | export class DMChannel extends TextableChannel { 29 | /** Represents the last message ID, useful for fetching messages in this channel */ 30 | public lastMessageID?: string | null; 31 | 32 | /** List of recipients that are in this group DM */ 33 | public recipient!: User; 34 | 35 | /** 36 | * Creates a new [DMChannel] instance 37 | * @param client The [WebSocket] client attached 38 | * @param data The data from Discord 39 | */ 40 | constructor(client: WebSocketClient, data: APIChannel) { 41 | super(client, data); 42 | 43 | this.patch(data); 44 | } 45 | 46 | patch(data: APIChannel) { 47 | super.patch(data); 48 | 49 | if (data.last_message_id !== undefined) 50 | this.lastMessageID = data.last_message_id; 51 | 52 | this.recipient = this['client'].users.add(new User(this['client'], data.recipients![0])); 53 | } 54 | 55 | toString() { 56 | return `[wumpcord.DMChannel]`; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/models/channel/GroupChannel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../../gateway/WebSocketClient'; 24 | import type { APIChannel } from 'discord-api-types/v8'; 25 | import TextableChannel from '../inherit/TextableChannel'; 26 | import { User } from '../User'; 27 | 28 | export class GroupChannel extends TextableChannel { 29 | /** The last pinned message's timestamp */ 30 | public lastPinTimestamp?: string | null; 31 | 32 | /** Represents the last message ID, useful for fetching messages in this channel */ 33 | public lastMessageID?: string | null; 34 | 35 | /** List of recipients that are in this group DM */ 36 | public recipients!: User[]; 37 | 38 | /** The owner's ID, who-ever created the group DM */ 39 | public ownerID?: string; 40 | 41 | /** The name of the group DM */ 42 | public name?: string; 43 | 44 | /** The group DM's icon */ 45 | public icon?: string | null; 46 | 47 | /** 48 | * Creates a new [GroupChannel] instance 49 | * @param client The [WebSocket] client attached 50 | * @param data The data from Discord 51 | */ 52 | constructor(client: WebSocketClient, data: APIChannel) { 53 | super(client, data); 54 | 55 | this.patch(data); 56 | } 57 | 58 | patch(data: APIChannel) { 59 | super.patch(data); 60 | 61 | if (data.last_message_id !== undefined) 62 | this.lastMessageID = data.last_message_id; 63 | 64 | if (data.last_pin_timestamp !== undefined) 65 | this.lastPinTimestamp = data.last_pin_timestamp; 66 | 67 | if (data.owner_id !== undefined) 68 | this.ownerID = data.owner_id; 69 | 70 | if (data.name !== undefined) 71 | this.name = data.name; 72 | 73 | if (data.icon !== undefined) 74 | this.icon = data.icon; 75 | 76 | this.recipients = data.recipients!.map(data => this['client'].users.add(new User(this['client'], data))); 77 | } 78 | 79 | toString() { 80 | return `[wumpcord.GroupChannel "${this.name}"]`; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/models/channel/NewsChannel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* eslint-disable camelcase */ 24 | 25 | import type { RESTPostAPIChannelMessageJSONBody, APIMessage } from 'discord-api-types/v8'; 26 | import type { MessageContent, MessageContentOptions } from '../../types'; 27 | import GuildTextableChannel from './GuildTextableChannel'; 28 | import { Message } from '../Message'; 29 | import Util from '../../util'; 30 | 31 | interface FollowedChannel { 32 | channel_id: string; 33 | webhook_id: string; 34 | } 35 | 36 | export class NewsChannel extends GuildTextableChannel { 37 | /** 38 | * Follows this [NewsChannel] to a different channel 39 | * @param channelID The channel's ID 40 | * @returns The result, if it was a success or not 41 | */ 42 | follow(channelID: string) { 43 | return this['client'].rest.dispatch({ 44 | endpoint: `/channels/${this.id}/followers`, 45 | method: 'post', 46 | data: { 47 | webhook_channel_id: channelID 48 | } 49 | }); 50 | } 51 | 52 | /** 53 | * Crossposts a message to all the followers who subscribed to this [NewsChannel] 54 | * @param messageID The message ID to crosspost 55 | * @param content The content to send out 56 | * @param options Any additional options, if needed 57 | * @returns A new [Message] instance indicating it was sent 58 | */ 59 | crosspost(messageID: string, content: MessageContent, options?: MessageContentOptions) { 60 | const data = Util.formatMessage(this['client'], content, options); 61 | const file = data.file; 62 | 63 | // delete it so it doesn't bleed when sending 64 | delete data.file; 65 | 66 | return this['client'].rest.dispatch({ 67 | endpoint: `/channels/${this.id}/messages/${messageID}/crosspost`, 68 | method: 'post', 69 | file, 70 | data 71 | }).then(data => new Message(this['client'], data)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/models/channel/StageChannel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* eslint-disable camelcase */ 24 | 25 | import type { APIChannel } from 'discord-api-types'; 26 | import GuildChannel from './GuildChannel'; 27 | 28 | interface APIStageChannel extends Pick { 29 | /** 30 | * The voice region of the stage channel. (`null`: automatic based on the guild) 31 | */ 32 | rtc_region: string | null; 33 | } 34 | 35 | export class StageChannel extends GuildChannel { 36 | /** The limit that users can join this [VoiceChannel] */ 37 | public userLimit?: number; 38 | 39 | /** The bitrate of the voice channel */ 40 | public bitrate?: number; 41 | 42 | /** The voice region of the stage channel. (`null`: automatic based on the guild) */ 43 | public region!: string | null; 44 | 45 | /** The topic people are discussing in this [[StageChannel]]. `null` is set when there is nobody in the stage channel. */ 46 | public topic!: string | null; 47 | 48 | /** 49 | * Constructs a new [[StageChannel]] instance 50 | * @param client The [[WebSocketClient]] attached 51 | * @param data The data passed in from Discord 52 | */ 53 | constructor(data: APIStageChannel) { 54 | super(data); 55 | 56 | this.patch(data); 57 | } 58 | 59 | /** 60 | * Patch any updates from Discord 61 | * @param data The partial data 62 | */ 63 | patch(data: Partial) { 64 | super.patch(data as APIStageChannel); 65 | 66 | if (data.bitrate !== undefined) 67 | this.bitrate = data.bitrate; 68 | 69 | if (data.user_limit !== undefined) 70 | this.userLimit = data.user_limit; 71 | 72 | if (data.rtc_region !== undefined) 73 | this.region = data.rtc_region; 74 | 75 | if (data.topic !== undefined) 76 | this.topic = data.topic; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/models/channel/StoreChannel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import GuildChannel from './GuildChannel'; 24 | 25 | export class StoreChannel extends GuildChannel {} 26 | -------------------------------------------------------------------------------- /src/models/channel/TextChannel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../../gateway/WebSocketClient'; 24 | import GuildTextableChannel from './GuildTextableChannel'; 25 | import type { APIChannel } from 'discord-api-types/v8'; 26 | 27 | export class TextChannel extends GuildTextableChannel { 28 | /** The ratelimit per user, how long they can send a message */ 29 | public ratelimitPerUser?: number; 30 | 31 | /** The channel's topic */ 32 | public topic!: string | null; 33 | 34 | /** 35 | * Creates a new [TextChannel] instance 36 | * @param client The [WebSocketClient] attached 37 | * @param data The data supplied from Discord 38 | */ 39 | constructor(client: WebSocketClient, data: APIChannel) { 40 | super(client, data); 41 | 42 | this.patch(data); 43 | } 44 | 45 | patch(data: APIChannel) { 46 | super.patch(data); 47 | 48 | if (data.rate_limit_per_user !== undefined) 49 | this.ratelimitPerUser = data.rate_limit_per_user; 50 | 51 | if (data.topic !== undefined) 52 | this.topic = data.topic; 53 | } 54 | 55 | toString() { 56 | return `[wumpcord.TextChannel<${this.name}>]`; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/models/channel/VoiceChannel.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* eslint-disable camelcase */ 24 | 25 | import type WebSocketClient from '../../gateway/WebSocketClient'; 26 | import type { APIChannel } from 'discord-api-types/v8'; 27 | import { Permissions } from '../../Constants'; 28 | import GuildChannel from './GuildChannel'; 29 | import Permission from '../../util/Permissions'; 30 | 31 | interface APIVoiceChannel extends Pick { 32 | /** 33 | * The voice region of the stage channel. (`null`: automatic based on the guild) 34 | */ 35 | rtc_region: string | null; 36 | } 37 | 38 | export class VoiceChannel extends GuildChannel { 39 | /** The limit that users can join this [VoiceChannel] */ 40 | public userLimit?: number; 41 | 42 | /** The bitrate of the voice channel */ 43 | public bitrate?: number; 44 | 45 | /** The voice region of the stage channel. (`null`: automatic based on the guild) */ 46 | public region!: string | null; 47 | 48 | /** 49 | * Creates a new [VoiceChannel] instance 50 | * @param client The [WebSocket] client attached to this [VoiceChannel] 51 | * @param data The data from Discord 52 | */ 53 | constructor(data: APIVoiceChannel) { 54 | super(data); 55 | 56 | this.patch(data); 57 | } 58 | 59 | patch(data: APIVoiceChannel) { 60 | super.patch(data); 61 | 62 | if (data.bitrate !== undefined) 63 | this.bitrate = data.bitrate; 64 | 65 | if (data.user_limit !== undefined) 66 | this.userLimit = data.user_limit; 67 | 68 | if (data.rtc_region !== undefined) 69 | this.region = data.rtc_region; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/models/guild/GuildBan.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../../gateway/WebSocketClient'; 24 | import type { APIUser } from 'discord-api-types/v8'; 25 | import { User } from '../User'; 26 | 27 | interface GuildBanProperties { 28 | reason?: string; 29 | user: APIUser; 30 | } 31 | 32 | export default class GuildBan { 33 | /** The reason of the ban */ 34 | public reason?: string; 35 | 36 | /** The user's ID who was banned */ 37 | public userID!: string; 38 | 39 | /** The [WebSocketClient] attached to this [GuildBan] */ 40 | private client: WebSocketClient; 41 | 42 | /** The user who was banned, if cached */ 43 | public user!: User; 44 | 45 | /** 46 | * Creates a new [GuildBan] instance 47 | * @param client The [WebSocketClient] attached 48 | * @param data The data from Discord 49 | */ 50 | constructor(client: WebSocketClient, data: GuildBanProperties) { 51 | this.client = client; 52 | 53 | this.patch(data); 54 | } 55 | 56 | private patch(data: GuildBanProperties) { 57 | this.userID = data.user.id; 58 | this.user = this.client.users.add(new User(this.client, data.user)); 59 | 60 | if (data.reason !== undefined) 61 | this.reason = data.reason; 62 | } 63 | 64 | toString() { 65 | return `[wumpcord.GuildBan]`; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/models/guild/GuildEmoji.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type WebSocketClient from '../../gateway/WebSocketClient'; 24 | import type { APIEmoji } from 'discord-api-types'; 25 | import { User } from '../User'; 26 | import Base from '../Base'; 27 | 28 | interface DiscordEmoji extends APIEmoji { 29 | guild_id?: string; // eslint-disable-line camelcase 30 | } 31 | 32 | export default class GuildEmoji extends Base { 33 | public requireColons?: boolean; 34 | public available?: boolean; 35 | public animated?: boolean; 36 | public managed?: boolean; 37 | public guildID?: string; 38 | private client: WebSocketClient; 39 | public name!: string | null; 40 | public user?: User; 41 | 42 | constructor(client: WebSocketClient, data: DiscordEmoji) { 43 | super(data.id!); 44 | 45 | this.client = client; 46 | this.patch(data); 47 | } 48 | 49 | patch(data: DiscordEmoji) { 50 | if (data.require_colons !== undefined) 51 | this.requireColons = data.require_colons; 52 | 53 | if (data.available !== undefined) 54 | this.available = data.available; 55 | 56 | if (data.animated !== undefined) 57 | this.animated = data.animated; 58 | 59 | if (data.managed !== undefined) 60 | this.managed = data.managed; 61 | 62 | if (data.guild_id !== undefined) 63 | this.guildID = data.guild_id; 64 | 65 | if (data.user !== undefined) 66 | this.user = this.client.users.add(new User(this.client, data.user)); 67 | 68 | if (data.name !== undefined) 69 | this.name = data.name; 70 | } 71 | 72 | get mention() { 73 | const prefix = this.animated ? 'a:' : ':'; 74 | return `<${prefix}:${this.name}:${this.id}>`; 75 | } 76 | 77 | get guild() { 78 | if (!this.guildID) return null; 79 | 80 | return this.client.guilds.get(this.guildID); 81 | } 82 | 83 | toString() { 84 | return `[wumpcord.GuildEmoji]`; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/models/guild/UnavailableGuild.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import { APIUnavailableGuild } from 'discord-api-types'; 24 | import Base from '../Base'; 25 | 26 | interface IUnavailableGuild extends APIUnavailableGuild { 27 | shard_id: number; // eslint-disable-line camelcase 28 | } 29 | 30 | export default class UnavailableGuild extends Base { 31 | public unavailable: boolean; 32 | public shardID: number; 33 | 34 | constructor(data: IUnavailableGuild) { 35 | super(data.id); 36 | 37 | this.unavailable = true; 38 | this.shardID = data.shard_id; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/models/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | export * from './presence'; 24 | export * from './util'; 25 | 26 | export { default as GuildInvite } from './guild/GuildInvite'; 27 | export { default as GuildMember } from './guild/GuildMember'; 28 | export { default as GuildEmoji } from './guild/GuildEmoji'; 29 | export { default as GuildRole } from './guild/GuildRole'; 30 | export * from './channel/CategoryChannel'; 31 | export * from './channel/GroupChannel'; 32 | export * from './channel/StoreChannel'; 33 | export * from './channel/VoiceChannel'; 34 | export * from './channel/NewsChannel'; 35 | export * from './channel/TextChannel'; 36 | export * from './PermissionOverwrite'; 37 | export * from './InteractionMessage'; 38 | export * from './channel/DMChannel'; 39 | export * from './VoiceState'; 40 | export * from './SelfUser'; 41 | export * from './Template'; 42 | export * from './Channel'; 43 | export * from './Message'; 44 | export * from './Webhook'; 45 | export * from './Guild'; 46 | export * from './User'; 47 | -------------------------------------------------------------------------------- /src/models/presence/Activity.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { 24 | GatewayActivity, 25 | GatewayActivityTimestamps, 26 | GatewayActivityParty, 27 | GatewayActivityEmoji, 28 | ActivityType 29 | } from 'discord-api-types'; 30 | 31 | export default class Activity { 32 | /** The timestamps available for this [Activity] */ 33 | public timestamps!: GatewayActivityTimestamps; 34 | 35 | /** Details on when the activity started displaying */ 36 | public createdAt!: Date; 37 | 38 | /** The details of the [Activity], indicating this is a Rich Presence */ 39 | public details!: string | null; 40 | 41 | /** Assets available for this [Activity], if any */ 42 | public assets!: GatewayActivity['assets']; 43 | 44 | /** The partial emoji instance */ 45 | public emoji!: GatewayActivityEmoji; 46 | 47 | /** The state of the [Activity], indicating this is a Rich Presence */ 48 | public state!: string | null; 49 | 50 | /** The party details for this [Activity], if any */ 51 | public party!: GatewayActivityParty; 52 | 53 | /** The type of the activity */ 54 | public type: ActivityType; 55 | 56 | /** The name of the activity */ 57 | public name: string; 58 | 59 | /** If this activity is a Rich Presence activity or not */ 60 | public rpc!: boolean; 61 | 62 | /** 63 | * Creates a new [Activity] instance 64 | * @param data The activity data 65 | */ 66 | constructor(data: GatewayActivity) { 67 | this.createdAt = new Date(data.created_at); 68 | this.type = data.type; 69 | this.name = data.name; 70 | 71 | this.patch(data); 72 | } 73 | 74 | patch(data: GatewayActivity) { 75 | this.rpc = data.hasOwnProperty('details') && data.hasOwnProperty('state'); 76 | 77 | if (data.timestamps !== undefined) 78 | this.timestamps = data.timestamps; 79 | 80 | if (data.details !== undefined) 81 | this.details = data.details; 82 | 83 | if (data.state !== undefined) 84 | this.state = data.state; 85 | 86 | if (data.emoji !== undefined) 87 | this.emoji = data.emoji; 88 | 89 | if (data.assets !== undefined) 90 | this.assets = data.assets; 91 | 92 | if (data.party !== undefined) 93 | this.party = data.party; 94 | } 95 | 96 | toString() { 97 | return `[wumpcord.PresenceActivity]`; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/models/presence/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | export { default as Presence } from './Presence'; 24 | export { default as Activity } from './Activity'; 25 | -------------------------------------------------------------------------------- /src/models/teams/Team.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { APITeam } from 'discord-api-types'; 24 | import type WebSocketClient from '../../gateway/WebSocketClient'; 25 | import Member from './TeamMember'; 26 | import Base from '../Base'; 27 | 28 | export default class Team extends Base { 29 | public members!: Member[]; 30 | public ownerID!: string; 31 | private client: WebSocketClient; 32 | public icon!: string | null; 33 | 34 | constructor(client: WebSocketClient, data: APITeam) { 35 | super(data.id); 36 | 37 | this.client = client; 38 | this.patch(data); 39 | } 40 | 41 | patch(data: APITeam) { 42 | if (data.owner_user_id !== undefined) 43 | this.ownerID = data.owner_user_id; 44 | 45 | if (data.members !== undefined) 46 | this.members = data.members.map(member => new Member(this.client, member)); 47 | 48 | if (data.icon !== undefined) 49 | this.icon = data.icon; 50 | } 51 | 52 | toString() { 53 | return `[wumpcord.Team]`; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/models/teams/TeamMember.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { APITeamMember } from 'discord-api-types'; 24 | import type WebSocketClient from '../../gateway/WebSocketClient'; 25 | import { User } from '../User'; 26 | 27 | export default class TeamMember { 28 | public permissions!: string[]; 29 | public membership!: number; 30 | private client: WebSocketClient; 31 | public teamID!: string; 32 | public user!: User; 33 | 34 | constructor(client: WebSocketClient, data: APITeamMember) { 35 | this.client = client; 36 | this.patch(data); 37 | } 38 | 39 | private patch(data: APITeamMember) { 40 | if (data.permissions !== undefined) 41 | this.permissions = data.permissions; 42 | 43 | if (data.membership_state !== undefined) 44 | this.membership = data.membership_state; 45 | 46 | if (data.team_id !== undefined) 47 | this.teamID = data.team_id; 48 | 49 | if (data.user !== undefined) 50 | this.user = this.client.users.add(new User(this.client, data.user)); 51 | } 52 | 53 | toString() { 54 | return `[wumpcord.TeamMember]`; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/models/util/ReactionCollector.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { GuildEmoji } from '..'; 24 | import { Collection } from '@augu/collections'; 25 | import { EventBus } from '@augu/utils'; 26 | import { Message } from '../Message'; 27 | import Util from '../../util'; 28 | 29 | type FilterFunction = (message: Message) => boolean; 30 | type DisposeReason = 'end' | 'max.tries' | 'min.tries' | 'none'; 31 | 32 | interface ReactionCollectorEvents { 33 | dispose(reactions: Collection, reason: DisposeReason): void; 34 | end(reactions: Collection): void; 35 | } 36 | 37 | interface ReactionCollectorOptions { 38 | time?: number; 39 | max?: number; 40 | } 41 | 42 | export default class ReactionCollector extends EventBus { 43 | private reactions: Collection; 44 | private _timeout!: NodeJS.Timeout; 45 | private message: Message; 46 | private options: ReactionCollectorOptions; 47 | private filter: FilterFunction; 48 | 49 | constructor( 50 | message: Message, 51 | filter: FilterFunction, 52 | options: ReactionCollectorOptions 53 | ) { 54 | super(); 55 | 56 | this.reactions = new Collection(); 57 | this.message = message; 58 | this.options = Util.merge(options, { 59 | time: 60000, 60 | max: 10 61 | }); 62 | 63 | this.filter = filter; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/models/util/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | //export { default as ReactionCollector } from './ReactionCollector'; 24 | export { default as MessageCollector, Filter } from './MessageCollector'; 25 | export { default as EmbedBuilder } from './EmbedBuilder'; 26 | -------------------------------------------------------------------------------- /src/rest/RatelimitBucket.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import type { IncomingMessage } from 'http'; 24 | 25 | /** 26 | * Represents the ratelimit information for [[Ratelimit.handle]] 27 | */ 28 | export interface RatelimitInfo { 29 | /** 30 | * If we have been ratelimited or not 31 | */ 32 | ratelimited: boolean; 33 | 34 | /** 35 | * How many times Wumpcord can create a request until being hit 36 | */ 37 | remaining: number; 38 | 39 | /** 40 | * The reset duration in milliseconds 41 | */ 42 | resetTime: number; 43 | } 44 | 45 | const getAPIOffset = (date: string) => new Date(date).getTime() - Date.now(); 46 | const calculate = (reset: number, serverDate: string) => new Date(reset * 1000).getTime() - getAPIOffset(serverDate); 47 | 48 | /** 49 | * Represents a bucket for handling ratelimiting with Discord 50 | */ 51 | export class RatelimitBucket { 52 | /** The remaining requests we can do before locking the rest client */ 53 | private remaining: number = 0; 54 | 55 | /** The reset timestamp */ 56 | private resetTime: number = 0; 57 | 58 | /** 59 | * Handles ratelimiting 60 | * @param endpoint The endpoint 61 | * @param res The response from the http request 62 | * @returns Promise of ratelimit info (because we hit a 429) or `null` if we aren't being ratelimited. 63 | */ 64 | handle(endpoint: string, req: IncomingMessage) { 65 | const resetTime = Number(req.headers['x-ratelimit-reset']); 66 | const serverDate = req.headers.date; 67 | const remaining = req.headers['x-ratelimit-remaining']; 68 | 69 | this.resetTime = resetTime ? calculate(resetTime, serverDate!) : Date.now(); 70 | this.remaining = remaining ? Number(remaining) : 0; 71 | 72 | // view https://github.com/discordapp/discord-api-docs/issues/182 73 | if (endpoint.includes('reactions')) 74 | this.resetTime = new Date(serverDate!).getTime() - getAPIOffset(serverDate!) + 250; 75 | 76 | return { 77 | ratelimited: req.statusCode === 429, 78 | remaining: this.remaining, 79 | resetTime: this.resetTime 80 | }; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/util/Permissions.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020-2021 August 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | import { Permissions } from '../Constants'; 24 | 25 | /** 26 | * Utility to handle permissions 27 | */ 28 | export default class Permission { 29 | /** The bit for the allowed permission */ 30 | public allow: bigint; 31 | 32 | /** The bit for the denied permission */ 33 | public denied: bigint; 34 | 35 | /** 36 | * Utility to handle permissions 37 | * @param allow The allowed permission 38 | * @param deny The denied permissions 39 | */ 40 | constructor(allow: string, deny: string = '0') { 41 | this.denied = BigInt(deny); 42 | this.allow = BigInt(allow); 43 | } 44 | 45 | /** 46 | * Returns a JSON structure of all the permissions available to this class 47 | */ 48 | toJSON() { 49 | const json = {}; 50 | for (const key of Object.keys(Permissions)) { 51 | if (!key.startsWith('all')) { 52 | if (this.allow & Permissions[key]) 53 | json[key] = true; 54 | else if (this.denied & Permissions[key]) 55 | json[key] = false; 56 | } 57 | } 58 | 59 | return json; 60 | } 61 | 62 | /** 63 | * Checks if `key` exists in the bitfield 64 | * @param key The key to check 65 | */ 66 | has(key: keyof typeof Permissions) { 67 | if (!Permissions.hasOwnProperty(key)) return false; 68 | 69 | return !!(this.allow & Permissions[key]); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@augu/tsconfig", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "moduleResolution": "node", 6 | "types": ["node"], 7 | "outDir": "./build", 8 | "rootDir": "./src" 9 | }, 10 | "include": ["src/**/*"], 11 | "exclude": ["node_modules"] 12 | } 13 | -------------------------------------------------------------------------------- /typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "excludeProtected": true, 3 | "excludePrivate": true, 4 | "highlightTheme": "nord", 5 | "tsconfig": "tsconfig.json", 6 | "readme": "README.md", 7 | "name": "Wumpcord" 8 | } 9 | --------------------------------------------------------------------------------