diff --git a/commands/message/image/deepai/text2image.js b/commands/message/image/deepai/text2image.js new file mode 100644 index 0000000..f9f3874 --- /dev/null +++ b/commands/message/image/deepai/text2image.js @@ -0,0 +1,39 @@ +const { getRecentImage } = require("../../../../labscore/utils/attachment"); +const { createEmbed } = require("../../../../labscore/utils/embed"); +const { editOrReply } = require("../../../../labscore/utils/message"); + +const { text2image } = require('../../../../labscore/api'); + +module.exports = { + name: 'text2image', + label: 'text', + aliases: ['t2i'], + metadata: { + description: 'text2image', + examples: ['text2image Mushroom'], + category: 'image', + usage: 'text2image ' + }, + run: async (context, args) => { + context.triggerTyping(); + try{ + if(!args.text) return editOrReply(context, { embeds: [createEmbed("warning", context, "Missing parameter (text).")] }) + + let res = await text2image(context, args.text) + + if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]}) + return editOrReply(context, {embeds:[createEmbed("default", context, { + image: { + url: res.response.body.image + }, + footer: { + iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`, + text: `${context.application.name} • Took ${res.timings}s` + } + })]}) + }catch(e){ + console.log(e) + return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]}) + } + }, +}; \ No newline at end of file diff --git a/labscore/api/endpoints.js b/labscore/api/endpoints.js index 8156ce5..75b6a55 100644 --- a/labscore/api/endpoints.js +++ b/labscore/api/endpoints.js @@ -19,6 +19,7 @@ const Api = Object.freeze({ IMAGE_DEEPDREAM: '/image/deepdream', IMAGE_SUPERRESOLUTION: '/image/superresolution', + IMAGE_TEXT2IMAGE: '/image/text2image', IMAGE_WAIFU2X: '/image/waifu2x', PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave', diff --git a/labscore/api/index.js b/labscore/api/index.js index c339b2c..a0480b6 100644 --- a/labscore/api/index.js +++ b/labscore/api/index.js @@ -180,6 +180,12 @@ module.exports.superresolution = async function(context, url){ }) } +module.exports.text2image = async function(context, text){ + return await request(Api.IMAGE_TEXT2IMAGE, "GET", {}, { + text: text + }) +} + module.exports.imtranslator = async function(context, text, voice){ return await request(Api.TTS_IMTRANSLATOR, "GET", {}, { text: text,