all repos — stealth-developers @ 6ac5bc72ec4532c8740a8eb324b23149192c2a80

src/interactions/commands/pronouns.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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
import {
	type Client,
	type ChatInputCommandInteraction,
	SlashCommandBuilder,
} from "discord.js";
import { db, moderators } from "@/database";
import config from "@/config";

const pronounTypes = {
	subjective: "Subject (e.g., **They** are a moderator)",
	objective: "Object (e.g., Send **them** a message)",
	"possessive-determiner":
		"Possessive Determiner (e.g., This is **their** post)",
	"possessive-pronoun": "Possessive Pronoun (e.g., The post is **theirs**)",
	reflexive: "Reflexive (e.g., They assigned it to **themself**)",
};

const command = new SlashCommandBuilder()
	.setName("woke")
	.setDescription("Set your pronouns.");

Object.entries(pronounTypes).forEach(([key, description]) => {
	command.addStringOption((option) =>
		option.setName(key).setDescription(description).setRequired(true),
	);
});

command.addUserOption((option) =>
	option
		.setName("user")
		.setRequired(false)
		.setDescription("The user to set pronouns for."),
);

async function execute(
	_client: Client,
	interaction: ChatInputCommandInteraction,
) {
	const id = interaction.options.getUser("user")?.id || interaction.user.id;
	if (
		interaction.options.getUser("user") &&
		interaction.user.id !== config.developerId
	) {
		await interaction.reply({
			content: "You cannot use this command.",
			ephemeral: true,
		});
		return;
	}

	const pronounData = {
		subjective: interaction.options.getString("subjective", true),
		objective: interaction.options.getString("objective", true),
		possessiveDeterminer: interaction.options.getString(
			"possessive-determiner",
			true,
		),
		possessive: interaction.options.getString("possessive-pronoun", true),
		reflexive: interaction.options.getString("reflexive", true),
	};

	await db
		.insert(moderators)
		.values({
			user_id: id,
			...pronounData,
		})
		.onConflictDoUpdate({
			target: moderators.user_id,
			set: pronounData,
		});

	await interaction.reply({
		content: "Pronouns updated.",
		flags: ["Ephemeral"],
	});
}

export default {
	data: command,
	execute,
};