Skip to content

Commit

Permalink
Feat/lock command (#1237)
Browse files Browse the repository at this point in the history
* 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.
68 changes: 68 additions & 0 deletions src/programs/lock/lock.ts
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!",
});
}
}

0 comments on commit 51f6a2c

Please sign in to comment.