This repository was archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: general commands #19
Open
nsylke
wants to merge
5
commits into
main
Choose a base branch
from
feat/general-cmds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
df0e082
feat: follow command
nsylke e66ae4c
refactor: use env for channel to follow; clean up code
nsylke 486b143
Merge branch 'main' into feat/general-cmds
nsylke 574a5b7
Merge branch 'main' into feat/general-cmds
nsylke 672b399
feat: vote command
nsylke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import Command, { | ||
| basicInteractionResponse, | ||
| } from "../../common/command/Command.ts"; | ||
| import { bot } from "../../cache.ts"; | ||
| import { enTranslate, translate } from "../../common/util/i18next.ts"; | ||
| import { | ||
| DiscordApplicationCommandOptionTypes, | ||
| followChannel, | ||
| getChannelWebhooks, | ||
| snowflakeToBigint, | ||
| validatePermissions, | ||
| } from "../../../../deps.ts"; | ||
|
|
||
| const FollowCommand: Command = async (interaction) => { | ||
| const guildId: bigint = snowflakeToBigint(interaction.guildId!); | ||
|
|
||
| if ( | ||
| !validatePermissions(snowflakeToBigint(interaction.member!.permissions), [ | ||
| "MANAGE_WEBHOOKS", | ||
| ]) | ||
| ) { | ||
| return basicInteractionResponse( | ||
| interaction.id, | ||
| interaction.token, | ||
| translate(guildId, "permission:USER_MISSING_PERMISSION", { | ||
| permission: "Manage Webhooks", | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| const raw = interaction.data?.options?.[0]; | ||
|
|
||
| if (raw?.name === "announcements") { | ||
| const channelId: bigint = snowflakeToBigint(interaction.channelId!); | ||
|
|
||
| const channelWebhooks = await getChannelWebhooks( | ||
| channelId, | ||
| ); | ||
|
|
||
| if (channelWebhooks.size >= 10) { | ||
| return basicInteractionResponse( | ||
| interaction.id, | ||
| interaction.token, | ||
| translate(guildId, "commands/general/follow:WEBHOOK_LIMIT"), | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| // 268559149175013376 is the ID of our announcement channel. | ||
| await followChannel(snowflakeToBigint("268559149175013376"), channelId); | ||
nsylke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch { | ||
| return basicInteractionResponse( | ||
| interaction.id, | ||
| interaction.token, | ||
| translate(guildId, "permission:SELF_MISSING_PERMISSION", { | ||
| permission: "Manage Webhooks", | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| return basicInteractionResponse( | ||
| interaction.id, | ||
| interaction.token, | ||
| translate(guildId, "commands/general/follow:ANNOUNCEMENTS_FOLLOWED"), | ||
| ); | ||
| } else if (raw?.name === "status") { | ||
| const channelId: bigint = snowflakeToBigint(interaction.channelId!); | ||
|
|
||
| const channelWebhooks = await getChannelWebhooks( | ||
| channelId, | ||
| ); | ||
|
|
||
| if (channelWebhooks.size >= 10) { | ||
| return basicInteractionResponse( | ||
| interaction.id, | ||
| interaction.token, | ||
| translate(guildId, "commands/general/follow:WEBHOOK_LIMIT"), | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| // 621817852726607882 is the ID of our status channel. | ||
| await followChannel(snowflakeToBigint("621817852726607882"), channelId); | ||
nsylke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch { | ||
| return basicInteractionResponse( | ||
| interaction.id, | ||
| interaction.token, | ||
| translate(guildId, "permission:SELF_MISSING_PERMISSION", { | ||
| permission: "Manage Webhooks", | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| return basicInteractionResponse( | ||
| interaction.id, | ||
| interaction.token, | ||
| translate(guildId, "commands/general/follow:STATUS_FOLLOWED"), | ||
| ); | ||
| } else { | ||
| return basicInteractionResponse( | ||
| interaction.id, | ||
| interaction.token, | ||
| translate(guildId, "commands/general/follow:INVALID_ARGUMENT"), | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| FollowCommand.options = { | ||
| name: "follow", | ||
| description: enTranslate("commands/general/follow:COMMAND_DESCRIPTION"), | ||
| options: [ | ||
| { | ||
| required: false, | ||
| name: "announcements", | ||
| description: enTranslate( | ||
| "commands/general/follow:SUBCOMMAND_DESCRIPTION_ANNOUNCEMENTS", | ||
| ), | ||
| type: DiscordApplicationCommandOptionTypes.SubCommand, | ||
| }, | ||
| { | ||
| required: false, | ||
| name: "status", | ||
| description: enTranslate( | ||
| "commands/general/follow:SUBCOMMAND_DESCRIPTION_STATUS", | ||
| ), | ||
| type: DiscordApplicationCommandOptionTypes.SubCommand, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| bot.commands.add(FollowCommand); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "COMMAND_DESCRIPTION": "Creates a webhook to follow TypicalBot announcements or status updates in this channel.", | ||
| "SUBCOMMAND_DESCRIPTION_ANNOUNCEMENTS": "Follow TypicalBot announcements in this channel.", | ||
| "SUBCOMMAND_DESCRIPTION_STATUS": "Follow TypicalBot status updates in this channel.", | ||
| "INVALID_ARGUMENT": "Please specify which TypicalBot channel you want to follow.", | ||
| "WEBHOOK_LIMIT": "The maximum webhooks that Discord allows in one channel is 10. Please remove a webhook and try again.", | ||
| "ANNOUNCEMENTS_FOLLOWED": "You have successfully followed TypicalBot announcements in this channel.", | ||
| "STATUS_FOLLOWED": "You have successfully followed TypicalBot status updates in this channel." | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.