-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * feat: lock command
- Loading branch information
geisterfurz007
authored
Feb 18, 2024
1 parent
5fac98c
commit 51f6a2c
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,68 @@ | ||
import { | ||
Command, | ||
CommandHandler, | ||
DiscordEvent, | ||
} from "../../event-distribution"; | ||
import { | ||
ApplicationCommandOptionType, | ||
ChannelType, | ||
ChatInputCommandInteraction, | ||
} from "discord.js"; | ||
import Tools from "../../common/tools"; | ||
|
||
const enum Errors { | ||
NOT_IN_GUILD = "NOT_IN_GUILD", | ||
SUPPORT_NOT_FOUND = "SUPPORT_NOT_FOUND", | ||
} | ||
|
||
@Command({ | ||
event: DiscordEvent.SLASH_COMMAND, | ||
root: "lock", | ||
description: "Quickly lock a chat if it starts getting out of hand", | ||
options: [ | ||
{ | ||
type: ApplicationCommandOptionType.Channel, | ||
description: "The channel to lock", | ||
name: "channel", | ||
required: false, | ||
}, | ||
], | ||
errors: { | ||
[Errors.NOT_IN_GUILD]: "The command can only be used on a server!", | ||
}, | ||
}) | ||
class LockChannel extends CommandHandler<DiscordEvent.SLASH_COMMAND> { | ||
async handle(interaction: ChatInputCommandInteraction): Promise<void> { | ||
const channelOption = interaction.options.getChannel("channel"); | ||
const optionChannel = | ||
interaction.guild && channelOption | ||
? await interaction.guild.channels.fetch(channelOption.id) | ||
: undefined; | ||
|
||
const channel = optionChannel ?? interaction.channel; | ||
if (channel?.type !== ChannelType.GuildText) { | ||
throw new Error(Errors.NOT_IN_GUILD); | ||
} | ||
|
||
await interaction.deferReply({ ephemeral: true }); | ||
|
||
const support = Tools.getRoleByName("Support", channel.guild); | ||
if (!support) { | ||
throw new Error(Errors.SUPPORT_NOT_FOUND); | ||
} | ||
|
||
await channel.permissionOverwrites.create(support, { | ||
SendMessages: true, | ||
}); | ||
await channel.permissionOverwrites.edit(channel.guild.roles.everyone, { | ||
SendMessages: false, | ||
}); | ||
|
||
await channel.send("This channel has been temporarily locked!"); | ||
|
||
await interaction.editReply({ | ||
content: | ||
"The channel has been locked. Go to its permissions and set 'Send Messages' for the Member or everyone role **TO NEUTRAL** unlock it!", | ||
}); | ||
} | ||
} |