pissbot-9000/commands/message/image/photofunia/retro-wave.js
2024-09-09 23:28:30 +02:00

64 lines
No EOL
3 KiB
JavaScript

const { retroWave } = require('#api')
const { createEmbed } = require('#utils/embed')
const { editOrReply } = require('#utils/message')
const { STATICS } = require('#utils/statics')
// TODO: Turn this into a general purpose permissions constant
const { Permissions } = require("detritus-client/lib/constants");
const { link } = require("#utils/markdown");
module.exports = {
name: 'retro',
label: 'text',
metadata: {
description: 'Generates an image with a retro style.',
description_short: 'Retro-styled text',
examples: ['retro crazy|chaos in|cyberspace'],
category: 'image',
usage: 'retro <line1|line2|line3> [-background <1-5>] [-style <1-4>]'
},
args: [
{default: 5, name: 'background', type: 'integer', help: "Background Style ` 1, 2, 3, 4, 5 `"},
{default: 4, name: 'style', type: 'integer', help: "Text Style ` 1, 2, 3, 4 `"},
],
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.ATTACH_FILES, Permissions.READ_MESSAGE_HISTORY],
run: async (context, args) => {
return editOrReply(context, createEmbed("default", context, {
description: `Image manipulation commands are **no longer supported** in ${context.client.application.name}.\n\nIf you're looking for a suitable replacement, check out ${link("https://canary.discord.com/oauth2/authorize?client_id=571661221854707713", "Assyst", "Invite Assyst Bot")}.`,
image: {
url: "https://cdn.discordapp.com/attachments/1029331568315093043/1282814251005775902/attachment.gif?ex=66e0b95e&is=66df67de&hm=81087808fd9bcd31886050280cae535827c274efdf6d04a318a073c40dc5a554&"
}
}))
context.triggerTyping();
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
if(args.background > 5 || args.background < 1) return editOrReply(context, createEmbed("warning", context, `Invalid Parameter (background).`))
if(args.style > 4 || args.style < 1) return editOrReply(context, createEmbed("warning", context, `Invalid Parameter (style).`))
let lines = `${args.text}| | `.split('|')
if(args.text.includes('|')) lines = [lines[1], lines[2], lines[0]]
try{
let res = await retroWave(context, args.background, args.style, lines[2], lines[0], lines[1])
if(res.response.body.status == 1) return editOrReply(context, createEmbed("warning", context, res.response.body.errors[0]))
image = res.response.body.data.images[res.response.body.data.best_quality]
return editOrReply(context, createEmbed("image", context, {
url: image,
time: res.timings,
provider: {
icon: STATICS.photofunia,
text: "PhotoFunia"
}
}))
}catch(e){
console.log(e)
if(e.response?.body?.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
return editOrReply(context, createEmbed("error", context, `Unable to generate image.`))
}
}
};