diff --git a/commands/message/fun/otter.js b/commands/message/fun/otter.js index ecc5131..3994a8f 100644 --- a/commands/message/fun/otter.js +++ b/commands/message/fun/otter.js @@ -17,23 +17,13 @@ module.exports = { let res = await superagent.get(`https://otter.bruhmomentlol.repl.co/random`) .set("User-Agent","labscore/2.0") - await editOrReply(context, { - embeds: [ - createEmbed("default", context, { - image: { - url: `attachment://otter.${res.headers["x-file-ext"]}` - } - }) - ], - files: [ - { - filename: `otter.${res.headers["x-file-ext"]}`, - value: res.body - } - ] + return await editOrReply(context, { + embeds: [ createEmbed("image", context, { + url: `otter.${res.headers["x-file-ext"]}` + })], + files: [{ filename: `otter.${res.headers["x-file-ext"]}`, value: res.body }] }) }catch(e){ - console.log(e) return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to fetch otter.`)]}) } } diff --git a/commands/message/image/deepai/deepdream.js b/commands/message/image/deepai/deepdream.js index 55a5b2e..ebb418e 100644 --- a/commands/message/image/deepai/deepdream.js +++ b/commands/message/image/deepai/deepdream.js @@ -21,16 +21,12 @@ module.exports = { let res = await deepdream(context, image) - 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` - } - })]}) + 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, `Unable to modify image.`)]}) diff --git a/commands/message/image/deepai/superresolution.js b/commands/message/image/deepai/superresolution.js index 316a47a..3b71a95 100644 --- a/commands/message/image/deepai/superresolution.js +++ b/commands/message/image/deepai/superresolution.js @@ -21,16 +21,12 @@ module.exports = { let res = await superresolution(context, image) - 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` - } - })]}) + 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, `Unable to modify image.`)]}) diff --git a/commands/message/image/deepai/text2image.js b/commands/message/image/deepai/text2image.js index f9f3874..6d99f23 100644 --- a/commands/message/image/deepai/text2image.js +++ b/commands/message/image/deepai/text2image.js @@ -22,15 +22,11 @@ module.exports = { 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` - } - })]}) + + 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, `Unable to generate image.`)]}) diff --git a/commands/message/image/deepai/waifu2x.js b/commands/message/image/deepai/waifu2x.js index 9d1f02d..994086d 100644 --- a/commands/message/image/deepai/waifu2x.js +++ b/commands/message/image/deepai/waifu2x.js @@ -22,15 +22,11 @@ module.exports = { let res = await waifu2x(context, image) 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` - } - })]}) + + 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, `Unable to modify image.`)]}) diff --git a/commands/message/image/makesweet/billboard.js b/commands/message/image/makesweet/billboard.js index 7bde33d..c3b822b 100644 --- a/commands/message/image/makesweet/billboard.js +++ b/commands/message/image/makesweet/billboard.js @@ -27,20 +27,20 @@ module.exports = { const timings = Date.now(); let mkswt = await billboardCityscape(image) - await response.edit({ embeds: [createEmbed("default", context, { - image: { - url: "attachment://makesweet.gif" - }, - footer: { - iconUrl: STATICS.makesweet, - text: `MakeSweet • Took ${((Date.now() - timings) / 1000).toFixed(2)}s` - } - })], files: [{ - filename: "makesweet.gif", - value: mkswt.body - }] }) + return await response.edit({ + embeds: [createEmbed("image", context, { + url: "makesweet.gif", + time: ((Date.now() - timings) / 1000).toFixed(2), + provider: { + icon: STATICS.makesweet, + text: "MakeSweet" + } + })], + files: [{ filename: "makesweet.gif", value: mkswt.body }] + }) } catch (e) { - await response.edit({ embeds: [createEmbed("error", context, e)] }) + console.log(e) + await response.edit({ embeds: [createEmbed("error", context, "Something went wrong.")] }) } }, } \ No newline at end of file diff --git a/commands/message/image/makesweet/circuitboard.js b/commands/message/image/makesweet/circuitboard.js index 95e96dc..0b078a5 100644 --- a/commands/message/image/makesweet/circuitboard.js +++ b/commands/message/image/makesweet/circuitboard.js @@ -27,18 +27,17 @@ module.exports = { const timings = Date.now(); let mkswt = await circuitBoard(image) - await response.edit({ embeds: [createEmbed("default", context, { - image: { - url: "attachment://makesweet.gif" - }, - footer: { - iconUrl: STATICS.makesweet, - text: `MakeSweet • Took ${((Date.now() - timings) / 1000).toFixed(2)}s` - } - })], files: [{ - filename: "makesweet.gif", - value: mkswt.body - }] }) + return await response.edit({ + embeds: [createEmbed("image", context, { + url: "makesweet.gif", + time: ((Date.now() - timings) / 1000).toFixed(2), + provider: { + icon: STATICS.makesweet, + text: "MakeSweet" + } + })], + files: [{ filename: "makesweet.gif", value: mkswt.body }] + }) } catch (e) { await response.edit({ embeds: [createEmbed("error", context, e)] }) } diff --git a/commands/message/image/makesweet/flag.js b/commands/message/image/makesweet/flag.js index 38caa2c..d70d049 100644 --- a/commands/message/image/makesweet/flag.js +++ b/commands/message/image/makesweet/flag.js @@ -27,18 +27,17 @@ module.exports = { const timings = Date.now(); let mkswt = await flag(image) - await response.edit({ embeds: [createEmbed("default", context, { - image: { - url: "attachment://makesweet.gif" - }, - footer: { - iconUrl: STATICS.makesweet, - text: `MakeSweet • Took ${((Date.now() - timings) / 1000).toFixed(2)}s` - } - })], files: [{ - filename: "makesweet.gif", - value: mkswt.body - }] }) + return await response.edit({ + embeds: [createEmbed("image", context, { + url: "makesweet.gif", + time: ((Date.now() - timings) / 1000).toFixed(2), + provider: { + icon: STATICS.makesweet, + text: "MakeSweet" + } + })], + files: [{ filename: "makesweet.gif", value: mkswt.body }] + }) } catch (e) { await response.edit({ embeds: [createEmbed("error", context, e)] }) } diff --git a/commands/message/image/makesweet/heartlocket.js b/commands/message/image/makesweet/heartlocket.js index b7798fe..3f1e10a 100644 --- a/commands/message/image/makesweet/heartlocket.js +++ b/commands/message/image/makesweet/heartlocket.js @@ -27,18 +27,17 @@ module.exports = { const timings = Date.now(); let mkswt = await heartLocket(args.text, image) - await response.edit({ embeds: [createEmbed("default", context, { - image: { - url: "attachment://makesweet.gif" - }, - footer: { - iconUrl: STATICS.makesweet, - text: `MakeSweet • Took ${((Date.now() - timings) / 1000).toFixed(2)}s` - } - })], files: [{ - filename: "makesweet.gif", - value: mkswt.body - }] }) + return await response.edit({ + embeds: [createEmbed("image", context, { + url: "makesweet.gif", + time: ((Date.now() - timings) / 1000).toFixed(2), + provider: { + icon: STATICS.makesweet, + text: "MakeSweet" + } + })], + files: [{ filename: "makesweet.gif", value: mkswt.body }] + }) } catch (e) { await response.edit({ embeds: [createEmbed("error", context, e)] }) } diff --git a/commands/message/image/photofunia/retro-wave.js b/commands/message/image/photofunia/retro-wave.js index e67fabc..d4f96f7 100644 --- a/commands/message/image/photofunia/retro-wave.js +++ b/commands/message/image/photofunia/retro-wave.js @@ -29,15 +29,15 @@ module.exports = { if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]}) image = res.response.body.data.images[res.response.body.data.best_quality] - return editOrReply(context, {embeds:[createEmbed("default", context, { - image: { - url: image - }, - footer: { - iconUrl: STATICS.photofunia, - text: `PhotoFunia • ${context.application.name} • Took ${res.timings}s` + + 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, {embeds:[createEmbed("error", context, e.response.body.message)]}) diff --git a/commands/message/image/photofunia/yacht.js b/commands/message/image/photofunia/yacht.js index 9c3bec4..0667d01 100644 --- a/commands/message/image/photofunia/yacht.js +++ b/commands/message/image/photofunia/yacht.js @@ -20,16 +20,15 @@ module.exports = { try{ let res = await yacht(context, args.text) image = res.response.body.data.images[res.response.body.data.best_quality] - return editOrReply(context, {embeds:[createEmbed("default", context, { - description: `⛵`, - image: { - url: image - }, - footer: { - iconUrl: STATICS.photofunia, - text: `PhotoFunia • ${context.application.name} • Took ${res.timings}s` + + return editOrReply(context, createEmbed("image", context, { + url: image, + time: res.timings, + provider: { + icon: STATICS.photofunia, + text: "PhotoFunia" } - })]}) + })) }catch(e){ console.log(e) return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]}) diff --git a/commands/message/utils/qr.js b/commands/message/utils/qr.js index 7222ce9..e8d8ff3 100644 --- a/commands/message/utils/qr.js +++ b/commands/message/utils/qr.js @@ -24,26 +24,15 @@ module.exports = { "data": args.text }) - await response.edit({ - embeds: [ - createEmbed("default", context, { - image: { - url: `attachment://qrcode.png` - }, - footer: { - iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`, - text: `labsCore • Took ${((Date.now() - t) / 1000).toFixed(2)}s` - } - }) - ], - files: [{ - filename: "qrcode.png", - value: res.body - }] + return await response.edit({ + embeds: [createEmbed("image", context, { + url: "qrcode.png", + time: ((Date.now() - t) / 1000).toFixed(2) + })], + files: [{ filename: "qrcode.png", value: res.body }] }) }catch(e){ - console.log(e) - return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate qr code.`)]}) + return await response.edit({ embeds: [createEmbed("error", context, `Unable to generate qr code.`) ] }) } } }; \ No newline at end of file diff --git a/commands/message/utils/screenshot.js b/commands/message/utils/screenshot.js index bfa303e..c2b0f21 100644 --- a/commands/message/utils/screenshot.js +++ b/commands/message/utils/screenshot.js @@ -14,7 +14,10 @@ module.exports = { }, run: async (context, args) => { context.triggerTyping(); - if(!args.url) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] }) + if(!args.url) return editOrReply(context, { embeds: [createEmbed("warning", context, "No url supplied.")] }) + + let response = await editOrReply(context, createEmbed("loading", context, `Creating website screenshot...`)) + try{ let ss = await screenshot(context, args.url) if(ss.response.body.status){ @@ -32,20 +35,16 @@ module.exports = { return editOrReply(context, { embeds: [createEmbed("error", context, "Unable to create screenshot.")] }) } } - return editOrReply(context, { embeds: [createEmbed("default", context, { - image: { - url: `attachment://screenshot.png` - }, - footer: { - iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`, - text: `${context.application.name} • Took ${ss.timings}s` - } - })], files: [{ - filename: "screenshot.png", - value: ss.response.body - }]}) + + return await response.edit({ + embeds: [createEmbed("image", context, { + url: "screenshot.png", + time: ss.timings + })], + files: [{ filename: "screenshot.png", value: ss.response.body }] + }) } catch(e){ - console.log(e) + return await response.edit({ embeds: [createEmbed("error", context, `Unable to create screenshot.`) ] }) } } }; \ No newline at end of file diff --git a/labscore/utils/embed.js b/labscore/utils/embed.js index 6299706..411dc17 100644 --- a/labscore/utils/embed.js +++ b/labscore/utils/embed.js @@ -11,6 +11,15 @@ const embedTypes = Object.freeze({ } } }, + "image": (context) => { + return { + color: COLORS.embed, + footer: { + iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`, + text: context.application.name + } + } + }, "defaultNoFooter": (context) => { return { color: COLORS.embed @@ -68,10 +77,29 @@ module.exports.createEmbed = function(type, context, content){ if(!embedTypes[type]) throw "Invalid Embed Type" if(!content) embedTypes[type](context) let emb = embedTypes[type](context) + + // Special handling if(["success","warning","error","loading"].includes(type)){ emb.author.name = content return emb } + + if(["image"].includes(type)){ + if(content.url.includes('://')){ + emb.image = { url: content.url } + } else { + emb.image = { url: `attachment://${content.url}` } + } + + if(content.provider){ + if(content.provider.text) emb.footer.text = `${content.provider.text} • ${context.application.name}` + if(content.provider.icon) emb.footer.iconUrl = content.provider.icon + } + + if(content.time) emb.footer.text = `${emb.footer.text} • Took ${content.time}s` + + return emb + } return Object.assign(emb, content) } @@ -79,7 +107,7 @@ module.exports.createEmbed = function(type, context, content){ module.exports.formatPaginationEmbeds = function(embeds){ // No formatting if we only have one page if(embeds.length == 1) return embeds; - + let i = 0; let l = embeds.length; let formatted = [];