From f35586fe893f76a581700a1141ce6726dfcb24d1 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Thu, 23 Feb 2023 22:48:36 +0100 Subject: [PATCH] editimage command --- commands/message/image/deepai/deepdream.js | 2 +- commands/message/image/deepai/imageedit.js | 39 +++++++++++++++++++ .../message/image/deepai/superresolution.js | 2 +- commands/message/image/deepai/text2image.js | 2 +- commands/message/image/deepai/waifu2x.js | 2 +- labscore/api/endpoints.js | 1 + labscore/api/index.js | 7 ++++ 7 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 commands/message/image/deepai/imageedit.js diff --git a/commands/message/image/deepai/deepdream.js b/commands/message/image/deepai/deepdream.js index 0153eb2..b6d95e2 100644 --- a/commands/message/image/deepai/deepdream.js +++ b/commands/message/image/deepai/deepdream.js @@ -30,7 +30,7 @@ module.exports = { })) }catch(e){ console.log(e) - return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]}) + return editOrReply(context, {embeds:[createEmbed("error", context, `Deepdream timed out.`)]}) } }, }; \ No newline at end of file diff --git a/commands/message/image/deepai/imageedit.js b/commands/message/image/deepai/imageedit.js new file mode 100644 index 0000000..7951299 --- /dev/null +++ b/commands/message/image/deepai/imageedit.js @@ -0,0 +1,39 @@ +const { getRecentImage } = require("../../../../labscore/utils/attachment"); +const { createEmbed } = require("../../../../labscore/utils/embed"); +const { editOrReply } = require("../../../../labscore/utils/message"); + +const { deepdream, imageedit } = require('../../../../labscore/api') + +module.exports = { + name: 'editimage', + aliases: ['ei'], + label: 'prompt', + metadata: { + description: 'Edits an image using AI.', + description_short: 'AI image editing', + examples: ['editimage With a crown'], + category: 'image', + usage: 'editimage ' + }, + run: async (context, args) => { + context.triggerTyping(); + try{ + if(!args.prompt) return editOrReply(context, { embeds: [createEmbed("warning", context, "Missing prompt.")] }) + + let image = await getRecentImage(context, 50) + if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] }) + + let res = await imageedit(context, image, args.prompt) + + if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]}) + + return editOrReply(context, createEmbed("image", context, { + url: res.response.body.image, + time: res.timings + })) + }catch(e){ + console.log(e) + return editOrReply(context, {embeds:[createEmbed("error", context, `Image editing timed out.`)]}) + } + }, +}; \ No newline at end of file diff --git a/commands/message/image/deepai/superresolution.js b/commands/message/image/deepai/superresolution.js index d7eb36d..627e173 100644 --- a/commands/message/image/deepai/superresolution.js +++ b/commands/message/image/deepai/superresolution.js @@ -30,7 +30,7 @@ module.exports = { })) }catch(e){ console.log(e) - return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]}) + return editOrReply(context, {embeds:[createEmbed("error", context, `Superresolution timed out.`)]}) } }, }; \ No newline at end of file diff --git a/commands/message/image/deepai/text2image.js b/commands/message/image/deepai/text2image.js index dde69cb..c43bdb8 100644 --- a/commands/message/image/deepai/text2image.js +++ b/commands/message/image/deepai/text2image.js @@ -30,7 +30,7 @@ module.exports = { })) }catch(e){ console.log(e) - return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]}) + return editOrReply(context, {embeds:[createEmbed("error", context, `Text2image timed out.`)]}) } }, }; \ No newline at end of file diff --git a/commands/message/image/deepai/waifu2x.js b/commands/message/image/deepai/waifu2x.js index 907c78c..570e6c1 100644 --- a/commands/message/image/deepai/waifu2x.js +++ b/commands/message/image/deepai/waifu2x.js @@ -30,7 +30,7 @@ module.exports = { })) }catch(e){ console.log(e) - return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]}) + return editOrReply(context, {embeds:[createEmbed("error", context, `Waifu2x timed out.`)]}) } }, }; \ No newline at end of file diff --git a/labscore/api/endpoints.js b/labscore/api/endpoints.js index 49d3b1f..11eddce 100644 --- a/labscore/api/endpoints.js +++ b/labscore/api/endpoints.js @@ -17,6 +17,7 @@ const Api = Object.freeze({ GOOGLE_VISION_WEBDETECTION: '/google/vision/webdetection', IMAGE_DEEPDREAM: '/image/deepai/deepdream', + IMAGE_IMAGEEDITOR: '/image/deepai/imageedit', IMAGE_SUPERRESOLUTION: '/image/deepai/superresolution', IMAGE_TEXT2IMAGE: '/image/deepai/text2image', IMAGE_WAIFU2X: '/image/deepai/waifu2x', diff --git a/labscore/api/index.js b/labscore/api/index.js index f698e6b..3bda0e1 100644 --- a/labscore/api/index.js +++ b/labscore/api/index.js @@ -222,6 +222,13 @@ module.exports.deepdream = async function(context, url){ }) } +module.exports.imageedit = async function(context, url, prompt){ + return await request(Api.IMAGE_IMAGEEDITOR, "GET", {}, { + url: url, + prompt: prompt + }) +} + module.exports.waifu2x = async function(context, url){ return await request(Api.IMAGE_WAIFU2X, "GET", {}, { url: url