Skip to content

Commit

Permalink
Added /idcard command
Browse files Browse the repository at this point in the history
This commit adds the `/idcard` command, which allows a Discord user to display information about their linked Kerberos identity in a channel. The user can also choose to display their MIT ID card photo (if desired).
  • Loading branch information
ZelnickB committed Nov 29, 2024
1 parent b3ce7f2 commit 6f0efd7
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 5 deletions.
64 changes: 64 additions & 0 deletions discordBot/commands/ChatInput/logic/idcard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { getUserInfo, UnlinkedUserError } from '../../common/whois/retrievers.js'
import { AttachmentBuilder, EmbedBuilder } from 'discord.js'

export default async function (interaction) {
const showIdPhoto = interaction.options.getBoolean('withpicture') !== false
const ephemeral = interaction.options.getBoolean('preview') === true
interaction.deferReply({ ephemeral })
try {
const userInfo = await getUserInfo(interaction.user, showIdPhoto)
console.log(userInfo)
const embedBuilder = new EmbedBuilder()
.setAuthor({
name: 'Massachusetts Institute of Technology'
})
.setColor(0x750014)
.setTitle('Discord ID Card')
.addFields([
{
name: 'Discord User',
value: `<@${interaction.user.id}> (\`${interaction.user.id}\`)`
},
{
name: 'Name',
value: userInfo.userInfo.displayName,
inline: true
}
])
.setTimestamp(new Date())
.setFooter({
text: 'Not valid for official identification purposes. Sent upon request.'
})
if (userInfo.userInfo.affiliations.length > 0) {
const affiliationType = userInfo.userInfo.affiliations[0].type
embedBuilder.addFields({
name: 'Affiliation',
value: affiliationType.charAt(0).toUpperCase() + affiliationType.substring(1),
inline: true
})
}
embedBuilder.addFields({
name: 'Email/Kerberos',
value: `${userInfo.userInfo.email.replaceAll('_', '\\_')} (\`${userInfo.userInfo.kerberosId}\`)`,
inline: true
})
const files = []
if (userInfo.image !== undefined) {
files.push(new AttachmentBuilder(userInfo.image, { name: 'user.jpeg' }))
embedBuilder.setThumbnail('attachment://user.jpeg')
}
return await interaction.editReply({
embeds: [embedBuilder],
files
})
} catch (e) {
if (e instanceof UnlinkedUserError) {
return await interaction.editReply({
content: `The user <@${interaction.user.id}> does not have a linked Kerberos identity.`,
allowedMentions: {
parse: []
}
})
}
}
}
29 changes: 24 additions & 5 deletions discordBot/commands/ChatInput/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@
}
]
},
{
"name": "idcard",
"type": 1,
"description": "Displays the actual identity corresponding to your linked Kerberos.",
"options": [
{
"type": 5,
"name": "withpicture",
"required": false,
"description": "Show your MIT ID card photo. Defaults to true."
},
{
"type": 5,
"name": "preview",
"required": false,
"description": "Display the card only for yourself, without showing others in the channel. Defaults to false."
}
]
},
{
"name": "localtime",
"type": 1,
Expand All @@ -37,6 +56,11 @@
}
]
},
{
"name": "ping",
"type": 1,
"description": "Checks whether IdentiBot is online and measures latency."
},
{
"name": "resetnick",
"type": 1,
Expand All @@ -54,11 +78,6 @@
}
]
},
{
"name": "ping",
"type": 1,
"description": "Checks whether IdentiBot is online and measures latency."
},
{
"name": "searchdir",
"type": 1,
Expand Down

0 comments on commit 6f0efd7

Please sign in to comment.