-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created and implemented an admin-only command to get a users KTH ID f…
…rom their user ID/mentioning them
- Loading branch information
alfredfl
committed
Dec 8, 2024
1 parent
9f13226
commit 9b5a39b
Showing
6 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js"; | ||
import { CommandNames } from "../commands.names"; | ||
import { KthIdVariables } from "./kthid.variables"; | ||
|
||
export const kthIdCommand = new SlashCommandBuilder() | ||
.setName(CommandNames.KTHID) | ||
.setDescription("Get the KTH ID of a user") | ||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild); | ||
|
||
kthIdCommand.addStringOption((option) => | ||
option | ||
.setName(KthIdVariables.USER) | ||
.setDescription( | ||
"A valid user or user ID." | ||
) | ||
.setRequired(true) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getKthIdByUserId} from "../../db/db"; | ||
import { GuildChatInputCommandInteraction } from "../../shared/types/GuildChatInputCommandType"; | ||
import { KthIdVariables } from "./kthid.variables"; | ||
|
||
export const handleKthId = async ( | ||
interaction: GuildChatInputCommandInteraction | ||
): Promise<void> => { | ||
const { options } = interaction; | ||
const user = options | ||
.getString(KthIdVariables.USER, true) | ||
.replace(/[\D]/g, ''); | ||
const kthId = await getKthIdByUserId(user); | ||
await interaction.deferReply({ ephemeral: true }); | ||
if (!kthId) { | ||
await interaction.editReply({ | ||
content: `Found no KTH ID mathing the provided Discord account`, | ||
}); | ||
} else { | ||
await interaction.editReply({ | ||
content: `The KTH ID of the provided user is: **${kthId}**`, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum KthIdVariables { | ||
USER = "user" | ||
} |