diff --git a/commands/interaction/slash/info/user.js b/commands/interaction/slash/info/user.js new file mode 100644 index 0000000..f27d40d --- /dev/null +++ b/commands/interaction/slash/info/user.js @@ -0,0 +1,97 @@ +const { Constants } = require('detritus-client'); +const { InteractionCallbackTypes, ApplicationCommandOptionTypes } = Constants; + +const { createEmbed } = require('../../../../labscore/utils/embed'); +const { smallIconPill, highlight, smallPill, icon, timestamp } = require('../../../../labscore/utils/markdown'); +const { renderBadges } = require('../../../../labscore/utils/users'); +const { BADGE_ICONS } = require('../../../../labscore/constants'); +const { editOrReply } = require('../../../../labscore/utils/message'); +const { UserFlags } = require('detritus-client/lib/constants'); + +module.exports = { + description: 'Displays information about a user', + name: 'user', + contexts: [ + 0, + 1, + 2 + ], + integrationTypes: [ + 1 + ], + options: [ + { + name: 'user', + description: 'The User.', + type: ApplicationCommandOptionTypes.USER, + required: false + } + ], + run: async (context, args) => { + try{ + await context.respond({data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) + + const { user, member } = args; + + let u = user; + let m = member; + + if(!args.user){ + u = context.user; + m = context.member; + } + + let botTag = '' + if (u.bot) botTag = "" + if (u.hasFlag(UserFlags.VERIFIED_BOT)) botTag = "" + + let usernameDisplay = u.username + if (u.discriminator && u.discriminator !== "0") usernameDisplay += `#${u.discriminator}` + + usernameDisplay = `**@${usernameDisplay}**${botTag} ${highlight(`(${u.id})`)}` + if (m && m.nick !== null) usernameDisplay += `\n${smallIconPill("user_card", "Nickname")} ${smallPill(m.nick)}` + + let userCard = createEmbed("default", context, { + description: `${icon("user")} ${usernameDisplay}`, + thumbnail: { + url: u.avatarUrl + `?size=4096` + }, + fields: [{ + name: `${icon("calendar")} Dates`, + value: `**Account Created: **${timestamp(u.createdAt, "f")}`, + inline: false + }] + }) + if (u.banner) userCard.image = { url: u.bannerUrl + `?size=4096` } + + // Guild Container + if (m) { + userCard.fields[0].value = userCard.fields[0].value + `\n**Joined Server: **${timestamp(m.joinedAt, "f")}` + let guildFields = [] + + if (m.isOwner) guildFields.push(`${icon("user_king")} **Server Owner**`) + if(context.guild) if (m.roles.length >= 1) guildFields.push(`${icon("user_shield")} **Roles: ** ${m.roles.length}/${context.guild?.roles.length}`) + if (m.premiumSince) guildFields.push(`**Boosting since: ** ${timestamp(m.premiumSince, 'f')}`) + if(guildFields.length >= 1) userCard.fields.push({ + name: `${icon("home")} Server`, + value: guildFields.join('\n'), + inline: true + }) + } + + // Badge Container + let b = renderBadges(u) + if (u.avatarUrl.endsWith('.gif') || u.banner) { b.push(BADGE_ICONS.nitro) } + if (b.length >= 1) { + userCard.fields.push({ + name: `${icon("nitro")} Badges`, + value: b.join(''), + inline: true + }) + } + return editOrReply(context, userCard) + }catch(e){ + console.log(e) + } + }, +}; \ No newline at end of file diff --git a/commands/interaction/user/avatar.js b/commands/interaction/user/avatar.js new file mode 100644 index 0000000..b98a812 --- /dev/null +++ b/commands/interaction/user/avatar.js @@ -0,0 +1,31 @@ +const { Constants } = require('detritus-client'); +const { InteractionCallbackTypes, ApplicationCommandTypes } = Constants; + +const { createEmbed } = require('../../../labscore/utils/embed'); +const { editOrReply } = require('../../../labscore/utils/message'); + +module.exports = { + name: 'Get User Avatar', + type: ApplicationCommandTypes.USER, + contexts: [ + 0, + 1, + 2 + ], + integrationTypes: [ + 1 + ], + run: async (context, args) => { + try{ + await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) + + return editOrReply(context, createEmbed("default", context, { + image: { + url: args.user.avatarUrl + '?size=4096' + } + })) + }catch(e){ + console.log(e) + } + }, +}; \ No newline at end of file diff --git a/commands/interaction/user/user.js b/commands/interaction/user/user.js new file mode 100644 index 0000000..d053f54 --- /dev/null +++ b/commands/interaction/user/user.js @@ -0,0 +1,84 @@ +const { Constants } = require('detritus-client'); +const { InteractionCallbackTypes, ApplicationCommandTypes } = Constants; + +const { createEmbed } = require('../../../labscore/utils/embed'); +const { smallIconPill, highlight, smallPill, icon, timestamp } = require('../../../labscore/utils/markdown'); +const { renderBadges } = require('../../../labscore/utils/users'); +const { BADGE_ICONS } = require('../../../labscore/constants'); +const { editOrReply } = require('../../../labscore/utils/message'); +const { UserFlags } = require('detritus-client/lib/constants'); + +module.exports = { + name: 'View User Details', + type: ApplicationCommandTypes.USER, + contexts: [ + 0, + 1, + 2 + ], + integrationTypes: [ + 1 + ], + run: async (context, args) => { + try{ + await context.respond({ data: {}, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE }) + + const { user, member } = args; + + let u = user; + let m = member; + + let botTag = '' + if (u.bot) botTag = "" + if (u.hasFlag(UserFlags.VERIFIED_BOT)) botTag = "" + + let usernameDisplay = u.name + if (u.discriminator && u.discriminator !== "0") usernameDisplay += `#${u.discriminator}` + + usernameDisplay = `**@${usernameDisplay}**${botTag} ${highlight(`(${u.id})`)}` + if (m && m.nick !== null) usernameDisplay += `\n${smallIconPill("user_card", "Nickname")} ${smallPill(m.nick)}` + + let userCard = createEmbed("default", context, { + description: `${icon("user")} ${usernameDisplay}`, + thumbnail: { + url: u.avatarUrl + `?size=4096` + }, + fields: [{ + name: `${icon("calendar")} Dates`, + value: `**Account Created: **${timestamp(u.createdAt, "f")}`, + inline: false + }] + }) + if (u.banner) userCard.image = { url: u.bannerUrl + `?size=4096` } + + // Guild Container + if (m) { + userCard.fields[0].value = userCard.fields[0].value + `\n**Joined Server: **${timestamp(m.joinedAt, "f")}` + let guildFields = [] + + if (m.isOwner) guildFields.push(`${icon("user_king")} **Server Owner**`) + if(context.guild) if (m.roles.length >= 1) guildFields.push(`${icon("user_shield")} **Roles: ** ${m.roles.length}/${context.guild?.roles.length}`) + if (m.premiumSince) guildFields.push(`**Boosting since: ** ${timestamp(m.premiumSince, 'f')}`) + if(guildFields.length >= 1) userCard.fields.push({ + name: `${icon("home")} Server`, + value: guildFields.join('\n'), + inline: true + }) + } + + // Badge Container + let b = renderBadges(u) + if (u.avatarUrl.endsWith('.gif') || u.banner) { b.push(BADGE_ICONS.nitro) } + if (b.length >= 1) { + userCard.fields.push({ + name: `${icon("nitro")} Badges`, + value: b.join(''), + inline: true + }) + } + return editOrReply(context, userCard) + }catch(e){ + console.log(e) + } + }, +}; \ No newline at end of file diff --git a/labscore/client.js b/labscore/client.js index 8d3f468..8f00344 100644 --- a/labscore/client.js +++ b/labscore/client.js @@ -159,6 +159,7 @@ commandClient.on('commandRunError', async ({context, error}) => { await commandClient.run() await interactionClient.addMultipleIn('../commands/interaction/context'); + await interactionClient.addMultipleIn('../commands/interaction/user'); await interactionClient.addMultipleIn('../commands/interaction/slash'); await interactionClient.run(); } catch(e){