all repos — stealth-developers @ 4e553f790a21ed2b4273883ae8705f53d8fdd014

src/interactions/commands/uwuifyProxy.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
import { db, userPreferences } from "@/database";
import {
	type ChatInputCommandInteraction,
	type Client,
	SlashCommandBuilder,
} from "discord.js";
import { eq } from "drizzle-orm";

const commandData = new SlashCommandBuilder()
	.setName("uwuify-toggle")
	.setDescription("toggle automatic uwuification of your messages");

async function execute(
	_client: Client,
	interaction: ChatInputCommandInteraction,
) {
	const userId = interaction.user.id;

	const existing = db
		.select()
		.from(userPreferences)
		.where(eq(userPreferences.userId, userId))
		.get();

	const isCurrentlyEnabled = existing?.uwuifyMessages === "enabled";
	const newState = isCurrentlyEnabled ? "disabled" : "enabled";

	if (existing) {
		await db
			.update(userPreferences)
			.set({ uwuifyMessages: newState })
			.where(eq(userPreferences.userId, userId));
	} else {
		await db.insert(userPreferences).values({
			userId,
			uwuifyMessages: newState,
		});
	}

	const status = newState === "enabled" ? "enabled" : "disabled";
	await interaction.reply({
		content: `✅ uwuification ${status}!`,
		flags: ["Ephemeral"],
	});
}

export default {
	data: commandData,
	execute,
};