diff --git a/commands/message/info/appinfo.js b/commands/message/info/appinfo.js new file mode 100644 index 0000000..5677b9a --- /dev/null +++ b/commands/message/info/appinfo.js @@ -0,0 +1,145 @@ +const { createEmbed } = require("../../../labscore/utils/embed"); +const { editOrReply } = require("../../../labscore/utils/message"); +const superagent = require('superagent'); +const { icon, highlight, link } = require('../../../labscore/utils/markdown') + +const applicationFlags = { + EMBEDDED_RELEASED: 1, + GATEWAY_PRESENCE: 12, + GATEWAY_PRESENCE_LIMITED: 13, + GATEWAY_GUILD_MEMBERS: 14, + GATEWAY_GUILD_MEMBERS_LIMITED: 15, + VERIFICATION_PENDING_GUILD_LIMIT: 16, + EMBEDDED: 17, + GATEWAY_MESSAGE_CONTENT: 18, + GATEWAY_MESSAGE_CONTENT_LIMITED: 19, + EMBEDDED_FIRST_PARTY: 20, + APPLICATION_COMMAND_BADGE: 23 +} + +const applicationFlagNames = { + EMBEDDED_RELEASED: "Embedded Released", + GATEWAY_PRESENCE: "Presence Intent", + GATEWAY_PRESENCE_LIMITED: "Presence Intent (not approved)", + GATEWAY_GUILD_MEMBERS: "Guild Members Intent", + GATEWAY_GUILD_MEMBERS_LIMITED: "Guild Members Intent (not approved)", + VERIFICATION_PENDING_GUILD_LIMIT: "Pending Guild Limit", + EMBEDDED: "Embedded", + GATEWAY_MESSAGE_CONTENT: "Message Content Intent", + GATEWAY_MESSAGE_CONTENT_LIMITED: "Message Content Intent (Not approved)", + EMBEDDED_FIRST_PARTY: "Embedded First Party", + APPLICATION_COMMAND_BADGE: `${icon("badge_slash")} Has Slash Commands` +} + +module.exports = { + name: 'appinfo', + label: 'id', + aliases: ['ai'], + metadata: { + description: 'app info', + examples: ['ai 682654466453012553'], + category: 'info', + usage: 'appinfo ' + }, + run: async (context, args) => { + context.triggerTyping(); + let id; + if(/[0-9]{17,19}/.test(args.id)){ + id = args.id.match(/[0-9]{17,19}/) + } else { + return editOrReply(context, createEmbed("warning", context, "Invalid Application ID")) + } + + let application; + let assets; + try{ + application = await superagent.get(`https://discord.com/api/v9/applications/${id}/rpc`) + application = application.body + assets = await superagent.get(`https://discord.com/api/oauth2/applications/${id}/assets`) + assets = assets.body + }catch(e){ + return editOrReply(context, createEmbed("warning", context, "Invalid Application")) + } + let embed = createEmbed("default", context, { + description: `${icon("robot")} **${application.name}** ${highlight(`(${application.id})`)}\n${application.description}`, + fields: [] + }) + + if(application.icon !== null) embed.thumbnail = { + url: `https://cdn.discordapp.com/app-icons/${application.id}/${application.icon}.png?size=4096` + } + + if(application.terms_of_service_url || application.privacy_policy_url){ + let content = [] + if(application.terms_of_service_url) content.push(`${icon("rules")} ${link(application.terms_of_service_url, "Terms of Service")}`) + if(application.privacy_policy_url) content.push(`${icon("lock")} ${link(application.privacy_policy_url, "Privacy Policy")}`) + + embed.fields.push({ + name: `${icon("link")} Links`, + value: content.join('\n'), + inline: true + }) + } + + if("bot_public" in application){ + let content = [] + if(application.bot_public) content.push(`• Bot is public`) + if(application.custom_install_url) content.push(`${icon("link")} ${link(application.custom_install_url, "Invite Bot")}`) + if(application.install_params) content.push(`${icon("downloading")} ${link(`https://discord.com/api/oauth2/authorize?client_id=${application.id}&permissions=${application.install_params.permissions}&scope=${application.install_params.scopes.join('+')}`, "Invite Bot")}`) + if(application.bot_require_code_grant) content.push(`\n• Bot requires code grant`) + + if(content.length) embed.fields.push({ + name: `${icon("robouser")} Bot`, + value: content.join('\n'), + inline: true + }) + } + + if(application.tags){ + embed.fields.push({ + name: `${icon("activity")} Tags`, + value: application.tags.map(t => highlight(t)).join(', '), + inline: true + }) + } + + if(application.max_participants){ + let content = []; + + content.push(`Max Participants: **${application.max_participants}**`) + if(application.embedded_activity_config !== null){ + if(application.embedded_activity_config.supported_platforms) content.push(`Supported Platforms: ${application.embedded_activity_config.supported_platforms.map(t => highlight(t)).join(', ')}`) + } + + embed.fields.push({ + name: `${icon("rocket")} Embedded Activity`, + value: content.join('\n'), + inline: true + }) + } + + if(application.flags){ + let fl = []; + for (const flag of Object.keys(applicationFlags)) { + if (application.flags & 1 << applicationFlags[flag]) fl.push('• ' + applicationFlagNames[flag]) + } + + embed.fields.push({ + name: `${icon("flag")} Flags`, + value: fl.join('\n'), + inline: true + }) + } + + if(assets.length){ + let asset = assets.map(a => link(`https://cdn.discordapp.com/app-assets/${application.id}/${a.id}.png?size=4096`, a.name)) + embed.fields.push({ + name: `${icon("image")} Assets`, + value: '• ' + asset.join('\n• '), + inline: true + }) + } + + return editOrReply(context, embed) + }, +}; \ No newline at end of file diff --git a/labscore/constants.js b/labscore/constants.js index 4ae1ad2..487f458 100644 --- a/labscore/constants.js +++ b/labscore/constants.js @@ -72,7 +72,12 @@ module.exports.ICONS = Object.freeze({ "reddit_helpful": "<:rdt_helpful:993630362372677774>", "online": "<:ico_online:994362211772399736>", "offline": "<:ico_offline:994362210061123598>", - "link": "<:ico_link:994364481792647229>" + "link": "<:ico_link:994364481792647229>", + "robot": "<:ico_robot:1002944678112530547>", + "robouser": "<:ico_robouser:1002944679744131092>", + "lock": "<:ico_lock:1002948236971085924>", + "badge_slash": "<:badge_slash:1002954716315140167>", + "flag": "<:ico_flag:1002957495138009251>" }) const GUILD_FEATURE_ICONS = Object.freeze({