111 lines
3.5 KiB
TypeScript
111 lines
3.5 KiB
TypeScript
/**
|
|
* Channel command - restrict Joel to a specific channel
|
|
*/
|
|
|
|
import { SlashCommandBuilder, ChannelType, PermissionFlagsBits } from "discord.js";
|
|
import type { Command } from "../types";
|
|
import { db } from "../../database";
|
|
import { botOptions } from "../../database/schema";
|
|
import { eq } from "drizzle-orm";
|
|
|
|
const command: Command = {
|
|
data: new SlashCommandBuilder()
|
|
.setName("channel")
|
|
.setDescription("Restrict Joel to respond only in a specific channel")
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName("set")
|
|
.setDescription("Set the channel where Joel is allowed to respond")
|
|
.addChannelOption(option =>
|
|
option
|
|
.setName("channel")
|
|
.setDescription("The channel to restrict Joel to")
|
|
.addChannelTypes(ChannelType.GuildText)
|
|
.setRequired(true)
|
|
)
|
|
)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName("clear")
|
|
.setDescription("Remove channel restriction - Joel can respond anywhere")
|
|
)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName("status")
|
|
.setDescription("Check the current channel restriction")
|
|
)
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) as SlashCommandBuilder,
|
|
category: "moderation",
|
|
execute: async (interaction) => {
|
|
if (!interaction.inGuild()) {
|
|
await interaction.reply({ content: "This command can only be used in a server.", ephemeral: true });
|
|
return;
|
|
}
|
|
|
|
const guildId = interaction.guildId;
|
|
const subcommand = interaction.options.getSubcommand();
|
|
|
|
// Get or create bot options for this guild
|
|
const existing = await db
|
|
.select()
|
|
.from(botOptions)
|
|
.where(eq(botOptions.guild_id, guildId))
|
|
.limit(1);
|
|
|
|
if (subcommand === "set") {
|
|
const channel = interaction.options.getChannel("channel", true);
|
|
|
|
if (existing.length === 0) {
|
|
await db.insert(botOptions).values({
|
|
guild_id: guildId,
|
|
restricted_channel_id: channel.id,
|
|
});
|
|
} else {
|
|
await db
|
|
.update(botOptions)
|
|
.set({
|
|
restricted_channel_id: channel.id,
|
|
updated_at: new Date().toISOString(),
|
|
})
|
|
.where(eq(botOptions.guild_id, guildId));
|
|
}
|
|
|
|
await interaction.reply({
|
|
content: `✅ Joel is now restricted to <#${channel.id}>.\n\n*Though knowing Joel, he might occasionally break the rules anyway...*`,
|
|
ephemeral: true,
|
|
});
|
|
} else if (subcommand === "clear") {
|
|
if (existing.length > 0) {
|
|
await db
|
|
.update(botOptions)
|
|
.set({
|
|
restricted_channel_id: null,
|
|
updated_at: new Date().toISOString(),
|
|
})
|
|
.where(eq(botOptions.guild_id, guildId));
|
|
}
|
|
|
|
await interaction.reply({
|
|
content: "✅ Channel restriction removed. Joel can now respond in any channel.",
|
|
ephemeral: true,
|
|
});
|
|
} else if (subcommand === "status") {
|
|
const restrictedChannelId = existing[0]?.restricted_channel_id;
|
|
|
|
if (restrictedChannelId) {
|
|
await interaction.reply({
|
|
content: `📍 Joel is currently restricted to <#${restrictedChannelId}>.\n\nUse \`/channel clear\` to remove the restriction.`,
|
|
ephemeral: true,
|
|
});
|
|
} else {
|
|
await interaction.reply({
|
|
content: "🌐 Joel is not restricted to any channel - he can respond anywhere.\n\nUse `/channel set` to restrict him.",
|
|
ephemeral: true,
|
|
});
|
|
}
|
|
}
|
|
},
|
|
};
|
|
|
|
export default command;
|