diff --git a/commands/interaction/slash/rewrite.js b/commands/interaction/slash/rewrite.js deleted file mode 100644 index 1c0ff4b..0000000 --- a/commands/interaction/slash/rewrite.js +++ /dev/null @@ -1,77 +0,0 @@ -const { REWRITE_STYLES } = require('#constants'); - -const { createEmbed } = require('#utils/embed'); -const { iconPill, codeblock } = require('#utils/markdown'); - -const { InteractionCallbackTypes, ApplicationCommandOptionTypes, MessageFlags } = require('detritus-client/lib/constants'); - -const superagent = require('superagent') - -module.exports = { - description: 'Use AI to rewrite your messages.', - name: 'rewrite', - guildIds: ["409840884713127956"], - options: [ - { - name: 'message', - description: 'Message to rewrite', - type: ApplicationCommandOptionTypes.STRING, - required: true - }, - { - name: 'style', - description: 'Style to use', - choices: REWRITE_STYLES, - required: true - }, - ], - run: async (context, args) => { - - await context.respond({data: { flags: MessageFlags.EPHEMERAL }, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE}) - - try{ - // Use the last 10 chat messages as context for the rewrite - let messageContext = []; - const messages = await context.channel.fetchMessages({limit: 10}); - - for(const m of messages){ - if(!m[1].content) continue; - let ctx = { - username: m[1].author.username, - content: m[1].content - } - - if(m[1].content.length > 200) ctx.content = ctx.content.substr(0, 200) + "..." - - messageContext.push(ctx) - } - - // Call the custom message rewriting api - // TODO: move this once monolith/pelican is ready - let res = await superagent.post(`${process.env.AI_SERVER}/boulevard:rewriteMessage`) - .set({ - Authorization: process.env.AI_SERVER_KEY - }) - .send({ - input: args.message, - style: args.style, - context: messageContext - }) - - let input = args.message - if(input.length >= 50) input = input.substr(0, 50) + "..." - - if(!res.body.output) return context.editOrRespond({ embeds: [createEmbed("error", context, "Unable to generate rewrite. Try again later.")], flags: MessageFlags.EPHEMERAL }) - - return context.editOrRespond({ embeds: [createEmbed("defaultNoFooter", context, { - description: `${iconPill("generativeai_text", input)}\n${res.body.output.map((o)=> codeblock("text", [o.replace(/\nRewritten: .*?/gs, '')])).join(' ')}` - })], flags: MessageFlags.EPHEMERAL }) - }catch(e){ - console.log(e) - await context.editOrRespond({ - embeds: [createEmbed("error", context, "Unable to generate text. Try again later.")], - flags: MessageFlags.EPHEMERAL - }) - } - }, -}; \ No newline at end of file diff --git a/commands/interaction/slash/utils/emoji.js b/commands/interaction/slash/utils/emoji.js index f2106c0..85ebdbc 100644 --- a/commands/interaction/slash/utils/emoji.js +++ b/commands/interaction/slash/utils/emoji.js @@ -119,7 +119,7 @@ module.exports = { // Regular Emoji Handling ingest("emoji_enlarge", "slash_command_ran"); - if(emoji.length == 0) return await editOrReply(context, createEmbed("warning", context, "You need to specify an emoji to enlarge.")) + if(emoji.length === 0) return await editOrReply(context, createEmbed("warning", context, "You need to specify an emoji to enlarge.")) let res; try{ @@ -131,31 +131,18 @@ module.exports = { if(Object.keys(res.data.platforms).length === 0) return await editOrReply(context, createEmbed("error", context, "No images available for this emoji.")); + let currentPlatform = "twitter"; + + if(!res.data.platforms[currentPlatform]) currentPlatform = Object.keys(res.data.platforms)[0] + else currentPlatform = "twitter" + // Use the high-res emojipedia icon, if available let ico = `https://abs.twimg.com/emoji/v2/72x72/${toCodePoint(emoji[0])}.png` - ico = res.data.platforms["twitter"].images[0].src + if(res.data.platforms[currentPlatform]) ico = res.data.platforms[currentPlatform].images[0].src - const DEFAULT_PLATFORM = "twitter" - let platformEmoji = res.data.platforms["twitter"] - - if(platformEmoji.images.length == 1) return editOrReply(context, createEmbed("default", context, { - author: { - iconUrl: ico, - name: `${res.data.name} • ${res.data.platforms[DEFAULT_PLATFORM].images[0].version}`, - url: res.data.link - }, - description: res.data.codes.map((c)=>pill(c)).join(' '), - image: { - url: res.data.platforms[DEFAULT_PLATFORM].images[0].src || STATIC_ASSETS.emoji_placeholder - }, - footer: { - iconUrl: STATICS.emojipedia, - text: `Emojipedia • ${context.application.name}` - } - })) + const DEFAULT_PLATFORM = currentPlatform let currentView; - let currentPlatform = "twitter"; let currentRevision = ""; const components = new Components({ @@ -166,34 +153,32 @@ module.exports = { // this sucks but works, ensures the newly selected option stays selected // update 25/03/24 - it sucks even more now - if(ctx.data.customId == "emoji-type"){ + if(ctx.data.customId === "emoji-type"){ currentPlatform = ctx.data.values[0]; currentRevision = res.data.platforms[currentPlatform].images[0].id for (let i = 0; i < components.components[0].components[0].options.length; i++) { - components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value == currentPlatform) + components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value === currentPlatform) } - - let newVersionOptions = res.data.platforms[currentPlatform].images.map((r) => { + + components.components[1].components[0].options = res.data.platforms[currentPlatform].images.map((r) => { return { label: r.version, value: r.id, - default: (r.id == res.data.platforms[currentPlatform].images[0].id) + default: (r.id === res.data.platforms[currentPlatform].images[0].id) } }) - components.components[1].components[0].options = newVersionOptions - - } else if(ctx.data.customId == "emoji-version"){ + } else if(ctx.data.customId === "emoji-version"){ for (let i = 0; i < components.components[1].components[0].options.length; i++) { - components.components[1].components[0].options[i].default = (components.components[1].components[0].options[i].value == ctx.data.values[0]) + components.components[1].components[0].options[i].default = (components.components[1].components[0].options[i].value === ctx.data.values[0]) } currentRevision = ctx.data.values[0]; } const emojiAsset = res.data.platforms[currentPlatform].images.filter((p)=>{ - return p.id == currentRevision + return p.id === currentRevision }) currentView = createEmbed("default", context, { @@ -220,7 +205,7 @@ module.exports = { return { label: r.version, value: r.id, - default: (r.id == res.data.platforms[DEFAULT_PLATFORM].images[0].id) + default: (r.id === res.data.platforms[DEFAULT_PLATFORM].images[0].id) } }) @@ -231,20 +216,22 @@ module.exports = { return { label: pl.name, value: r, - default: (r == "twitter") + default: (r === DEFAULT_PLATFORM) } }) components.addSelectMenu({ placeholder: "Select platform type", customId: "emoji-type", - options: selectTypeOptions + options: selectTypeOptions, + disabled: (res.data.platforms.length === 1) }) components.addSelectMenu({ placeholder: "Select emoji revision", customId: "emoji-version", - options: selectOptions + options: selectOptions, + disabled: (res.data.platforms[DEFAULT_PLATFORM].images.length === 1) }) currentView = createEmbed("default", context, { diff --git a/commands/message/info/appinfo.js b/commands/message/info/appinfo.js index a6a2168..80ede62 100644 --- a/commands/message/info/appinfo.js +++ b/commands/message/info/appinfo.js @@ -7,6 +7,8 @@ const { Permissions } = require("detritus-client/lib/constants"); const superagent = require('superagent'); +const { Routes } = require('detritus-client-rest/lib/endpoints'); + const applicationFlags = { EMBEDDED_RELEASED: 1, GATEWAY_PRESENCE: 12, @@ -59,14 +61,14 @@ module.exports = { let application; let assets; try{ - application = await superagent.get(`https://discord.com/api/v9/applications/${id}/rpc`) + application = await superagent.get(`${Routes.URL}/api/v9/applications/${id}/rpc`) application = application.body }catch(e){ return editOrReply(context, createEmbed("warning", context, "Invalid Application")) } - + try{ - assets = await superagent.get(`https://discord.com/api/oauth2/applications/${id}/assets`) + assets = await superagent.get(`${Routes.URL}/api/oauth2/applications/${id}/assets`) assets = assets.body }catch(e){ // :)