-
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.
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
Showing
2 changed files
with
88 additions
and
5 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
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: [] | ||
} | ||
}) | ||
} | ||
} | ||
} |
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