From f56a84cf58dcc59a9e94ee26cc004d1b7359a166 Mon Sep 17 00:00:00 2001 From: "Muhammed Reza Mehdi Hamid Muhammed (Linux Mint on IdeaPad 1i)" Date: Thu, 9 Apr 2026 19:17:57 +0200 Subject: [PATCH 1/5] feat: boilerplate for the /unverify command. --- src/commands/unverify/unverify.command.ts | 14 ++++++++++++++ src/commands/unverify/unverify.handler.ts | 0 src/commands/unverify/unverify.variables.ts | 3 +++ 3 files changed, 17 insertions(+) create mode 100644 src/commands/unverify/unverify.command.ts create mode 100644 src/commands/unverify/unverify.handler.ts create mode 100644 src/commands/unverify/unverify.variables.ts diff --git a/src/commands/unverify/unverify.command.ts b/src/commands/unverify/unverify.command.ts new file mode 100644 index 00000000..8b8c7e4b --- /dev/null +++ b/src/commands/unverify/unverify.command.ts @@ -0,0 +1,14 @@ +import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js"; +import { UnverifyVariables } from "./unverify.variables"; + +export const unverifyCommand = new SlashCommandBuilder() + .setName("unverify") + .setDescription("Remove a user's verification from HarmonyDB.") + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator); + +unverifyCommand.addUserOption((option) => + option + .setName(UnverifyVariables.USER) + .setDescription("A valid user or user ID.") + .setRequired(true) +) \ No newline at end of file diff --git a/src/commands/unverify/unverify.handler.ts b/src/commands/unverify/unverify.handler.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/commands/unverify/unverify.variables.ts b/src/commands/unverify/unverify.variables.ts new file mode 100644 index 00000000..f23c0784 --- /dev/null +++ b/src/commands/unverify/unverify.variables.ts @@ -0,0 +1,3 @@ +export enum UnverifyVariables { + USER = "user", +} \ No newline at end of file From 05b12f495ad39e5e3150bce99488c1f37748ae18 Mon Sep 17 00:00:00 2001 From: "Muhammed Reza Mehdi Hamid Muhammed (Linux Mint on IdeaPad 1i)" Date: Thu, 9 Apr 2026 21:20:00 +0200 Subject: [PATCH 2/5] refactor: remove test logging. --- src/shared/utils/auth.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/shared/utils/auth.ts b/src/shared/utils/auth.ts index 48ab553b..6099f4a1 100644 --- a/src/shared/utils/auth.ts +++ b/src/shared/utils/auth.ts @@ -140,8 +140,6 @@ export async function setAliasRole( year += 2000; - log.info(`${year}`); - const date = new Date(); const difference = date.getFullYear() - year - (date.getMonth() < 8 ? 1 : 0); From ebef88ba8d7306f39a65dc06e1344b2ffa4d151f Mon Sep 17 00:00:00 2001 From: "Muhammed Reza Mehdi Hamid Muhammed (Linux Mint on IdeaPad 1i)" Date: Thu, 9 Apr 2026 21:20:20 +0200 Subject: [PATCH 3/5] feat: remove user by Discord ID. --- src/db/db.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/db/db.ts b/src/db/db.ts index cf737be0..9f60b848 100644 --- a/src/db/db.ts +++ b/src/db/db.ts @@ -48,6 +48,15 @@ export async function insertUser( return true; } +export async function deleteUser(discordId: string): Promise { + try { + await sql`delete from users where discord_id = ${discordId}`; + } catch (err) { + return false; + } + return true; +} + export async function getDiscordIdByKthid( kthId: string ): Promise { From fea5df4a1de77e469487a50d37c373981e375192 Mon Sep 17 00:00:00 2001 From: "Muhammed Reza Mehdi Hamid Muhammed (Linux Mint on IdeaPad 1i)" Date: Thu, 9 Apr 2026 21:20:39 +0200 Subject: [PATCH 4/5] feat: finished /unverify command. --- src/commands/commands.names.ts | 1 + src/commands/commands.ts | 2 ++ src/commands/handle-commands.ts | 4 +++ src/commands/unverify/unverify.handler.ts | 32 +++++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/src/commands/commands.names.ts b/src/commands/commands.names.ts index ed2625a8..cf733891 100644 --- a/src/commands/commands.names.ts +++ b/src/commands/commands.names.ts @@ -12,4 +12,5 @@ export enum CommandNames { NOLLEGRUPP = "nollegrupp", MOTTAGNINGEN = "mottagningen", TEST = "test", + UNVERIFY = "unverify", } diff --git a/src/commands/commands.ts b/src/commands/commands.ts index 438809c1..ff6cd76e 100644 --- a/src/commands/commands.ts +++ b/src/commands/commands.ts @@ -11,6 +11,7 @@ import { messageCommand } from "./message/message.command"; import { ContextMenuCommandBuilder, SlashCommandBuilder } from "discord.js"; import { kthIdCommand } from "./kthid/kthid.command"; import { mottagningenCommand } from "./mottagningen/mottagningen.command"; +import { unverifyCommand } from "./unverify/unverify.command"; type ApplicationCommandBuilder = | SlashCommandBuilder @@ -31,6 +32,7 @@ export const getOfficialBotCommands = async (): Promise< kthIdCommand, nollegruppCommand, mottagningenCommand, + unverifyCommand, ]; export const getLightBotCommands = async (): Promise< diff --git a/src/commands/handle-commands.ts b/src/commands/handle-commands.ts index 2238b031..c81c3eac 100644 --- a/src/commands/handle-commands.ts +++ b/src/commands/handle-commands.ts @@ -33,6 +33,7 @@ import { handleNollegrupp } from "./nollegrupp/nollegrupp.handler"; import * as log from "../shared/utils/log"; import { handleMottagningen } from "./mottagningen/mottagningen.handler"; import { handleTest } from "../tests/test"; +import { handleUnverify } from "./unverify/unverify.handler"; export async function handleInteractions( interaction: Interaction @@ -175,6 +176,9 @@ const handleChatInputCommand = async ( case CommandNames.TEST: await handleTest(guildInteraction); return; + case CommandNames.UNVERIFY: + await handleUnverify(guildInteraction); + return; default: throw new CommandNotFoundError( guildInteraction.commandName diff --git a/src/commands/unverify/unverify.handler.ts b/src/commands/unverify/unverify.handler.ts index e69de29b..e0316b9b 100644 --- a/src/commands/unverify/unverify.handler.ts +++ b/src/commands/unverify/unverify.handler.ts @@ -0,0 +1,32 @@ +import { MessageFlags } from "discord.js"; +import { GuildChatInputCommandInteraction } from "../../shared/types/GuildChatInputCommandType"; +import { UnverifyVariables } from "./unverify.variables"; +import { deleteUser } from "../../db/db"; +import { removeRole } from "../../shared/utils/roles"; +import * as log from "../../shared/utils/log"; + +export async function handleUnverify( + interaction: GuildChatInputCommandInteraction +): Promise { + const { options } = interaction; + const user = options.getUser(UnverifyVariables.USER, true); + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + + const success = await deleteUser(user.id); + + if (!success) { + interaction.editReply({ content: "Unverification failed under mysterious circumstances. Contact D-Sys to unverify the user." }); + log.warning("Unverification failed under mysterious circumstances.") + } + + // And now, remove the verified role on all servers. + const guilds = await interaction.client.guilds.fetch(); + + Promise.all(guilds.map(async (e): Promise => { + const guild = await e.fetch(); + removeRole(user, "verified", guild); + })); + + interaction.editReply({ content: "You have been unverified!" }); + log.info(`Successfully unverified user with user.id = "${user.id}", user.username = "${user.username})".`) +} \ No newline at end of file From f3314f9e9637ef0f7c299c7630c53adb88762e77 Mon Sep 17 00:00:00 2001 From: "Muhammed Reza Mehdi Hamid Muhammed (Linux Mint on IdeaPad 1i)" Date: Thu, 9 Apr 2026 21:22:30 +0200 Subject: [PATCH 5/5] chore: format code. --- src/commands/unverify/unverify.command.ts | 16 ++++---- src/commands/unverify/unverify.handler.ts | 45 ++++++++++++--------- src/commands/unverify/unverify.variables.ts | 4 +- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/commands/unverify/unverify.command.ts b/src/commands/unverify/unverify.command.ts index 8b8c7e4b..966b2c32 100644 --- a/src/commands/unverify/unverify.command.ts +++ b/src/commands/unverify/unverify.command.ts @@ -2,13 +2,13 @@ import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js"; import { UnverifyVariables } from "./unverify.variables"; export const unverifyCommand = new SlashCommandBuilder() - .setName("unverify") - .setDescription("Remove a user's verification from HarmonyDB.") - .setDefaultMemberPermissions(PermissionFlagsBits.Administrator); + .setName("unverify") + .setDescription("Remove a user's verification from HarmonyDB.") + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator); unverifyCommand.addUserOption((option) => - option - .setName(UnverifyVariables.USER) - .setDescription("A valid user or user ID.") - .setRequired(true) -) \ No newline at end of file + option + .setName(UnverifyVariables.USER) + .setDescription("A valid user or user ID.") + .setRequired(true) +); diff --git a/src/commands/unverify/unverify.handler.ts b/src/commands/unverify/unverify.handler.ts index e0316b9b..92a2581d 100644 --- a/src/commands/unverify/unverify.handler.ts +++ b/src/commands/unverify/unverify.handler.ts @@ -6,27 +6,34 @@ import { removeRole } from "../../shared/utils/roles"; import * as log from "../../shared/utils/log"; export async function handleUnverify( - interaction: GuildChatInputCommandInteraction + interaction: GuildChatInputCommandInteraction ): Promise { - const { options } = interaction; - const user = options.getUser(UnverifyVariables.USER, true); - await interaction.deferReply({ flags: MessageFlags.Ephemeral }); + const { options } = interaction; + const user = options.getUser(UnverifyVariables.USER, true); + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); - const success = await deleteUser(user.id); - - if (!success) { - interaction.editReply({ content: "Unverification failed under mysterious circumstances. Contact D-Sys to unverify the user." }); - log.warning("Unverification failed under mysterious circumstances.") - } + const success = await deleteUser(user.id); - // And now, remove the verified role on all servers. - const guilds = await interaction.client.guilds.fetch(); + if (!success) { + interaction.editReply({ + content: + "Unverification failed under mysterious circumstances. Contact D-Sys to unverify the user.", + }); + log.warning("Unverification failed under mysterious circumstances."); + } - Promise.all(guilds.map(async (e): Promise => { - const guild = await e.fetch(); - removeRole(user, "verified", guild); - })); + // And now, remove the verified role on all servers. + const guilds = await interaction.client.guilds.fetch(); - interaction.editReply({ content: "You have been unverified!" }); - log.info(`Successfully unverified user with user.id = "${user.id}", user.username = "${user.username})".`) -} \ No newline at end of file + Promise.all( + guilds.map(async (e): Promise => { + const guild = await e.fetch(); + removeRole(user, "verified", guild); + }) + ); + + interaction.editReply({ content: "You have been unverified!" }); + log.info( + `Successfully unverified user with user.id = "${user.id}", user.username = "${user.username})".` + ); +} diff --git a/src/commands/unverify/unverify.variables.ts b/src/commands/unverify/unverify.variables.ts index f23c0784..0f114bd3 100644 --- a/src/commands/unverify/unverify.variables.ts +++ b/src/commands/unverify/unverify.variables.ts @@ -1,3 +1,3 @@ export enum UnverifyVariables { - USER = "user", -} \ No newline at end of file + USER = "user", +}