forked from cosmic/scythe
1
0
Fork 0
scythe/src/commands/starboard.ts

72 lines
1.8 KiB
TypeScript

import {
ApplicationCommandOptionType,
CommandInteraction,
MessageFlags,
TextChannel,
} from "discord.js";
import { Discord, Slash, SlashOption } from "discordx";
import db from "../db";
import { starboardSettingsTable } from "../db/schema";
import { eq } from "drizzle-orm";
@Discord()
export class StarboardCmds {
@Slash({ name: "starboard-setup", description: "setup the starboard" })
async starboardSetup(
@SlashOption({
name: "channel",
description: "channel to post starboard messages to",
type: ApplicationCommandOptionType.Channel,
required: true,
})
channel: TextChannel,
@SlashOption({
name: "threshold",
description: "number of reacts needed to post to starboard",
type: ApplicationCommandOptionType.Integer,
required: true,
})
threshold: number,
inter: CommandInteraction,
) {
if (inter.user.id !== inter.guild?.ownerId) {
return await inter.reply("can't use this one silly!");
}
await db.insert(starboardSettingsTable).values({
guild: inter.guildId!,
channel: channel.id,
threshold,
enabled: 1,
});
await inter.reply({ content: "Done", flags: MessageFlags.Ephemeral });
}
@Slash({
name: "starboard-enable",
description: "enable/disable the starboard",
})
async starboardEnable(
@SlashOption({
name: "setting",
description: "enable/disable",
type: ApplicationCommandOptionType.Boolean,
required: true,
})
setting: boolean,
inter: CommandInteraction,
) {
if (inter.user.id !== inter.guild?.ownerId) {
return await inter.reply("can't use this one silly!");
}
await db
.update(starboardSettingsTable)
.set({
enabled: setting ? 1 : 0,
})
.where(eq(starboardSettingsTable.guild, inter.guildId!));
await inter.reply({
content: "Setting Changed",
flags: MessageFlags.Ephemeral,
});
}
}