diff --git a/commands/message/dev/debug/test.js b/commands/message/dev/debug/test.js index f8fc789..ddd5a35 100644 --- a/commands/message/dev/debug/test.js +++ b/commands/message/dev/debug/test.js @@ -1,11 +1,14 @@ const { createEmbed } = require("../../../../labscore/utils/embed"); const { link } = require("../../../../labscore/utils/markdown"); const { editOrReply } = require("../../../../labscore/utils/message"); -const { getUser } = require("../../../../labscore/utils/users"); +const { flag } = require("../../../../service/makesweet"); +const { getRecentImage } = require("../../../../labscore/utils/attachment"); + +const superagent = require('superagent') module.exports = { name: 'test', - label: 'input', + label: 'text', metadata: { description: 'test', examples: ['test'], @@ -13,12 +16,19 @@ module.exports = { usage: 'test' }, run: async (context, args) => { - try{ - return editOrReply(context, createEmbed("default", context, { - description: `${link("https://google.com","Masked Link","Masked Link Tooltip")}` - })) - }catch(e){ + if(context.user.id !== "223518178100248576") return; + let image = await getRecentImage(context, 50) + if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] }) + if(!args.text) args.text = "" + try { + let mkswt = await flag(image) + console.log(mkswt.body) + return editOrReply(context, { content:"ww", files: [{ + filename: "makesweet.gif", + value: mkswt.body + }] }) + } catch (e) { console.log(e) } }, -}; \ No newline at end of file +} \ No newline at end of file diff --git a/commands/message/image/makesweet/billboard.js b/commands/message/image/makesweet/billboard.js new file mode 100644 index 0000000..7bde33d --- /dev/null +++ b/commands/message/image/makesweet/billboard.js @@ -0,0 +1,46 @@ +const { createEmbed } = require("../../../../labscore/utils/embed"); +const { editOrReply } = require("../../../../labscore/utils/message"); + +const { getRecentImage } = require("../../../../labscore/utils/attachment"); + +const { billboardCityscape } = require("../../../../service/makesweet"); +const { STATICS } = require("../../../../labscore/utils/statics"); + +module.exports = { + name: 'billboard', + label: 'text', + metadata: { + description: 'makesweet billboard', + examples: ['billboard'], + category: 'image', + usage: 'billboard' + }, + run: async (context, args) => { + + let image = await getRecentImage(context, 50) + if(!image) return editOrReply(context, createEmbed("warning", context, "No images found.")) + + let response = await editOrReply(context, createEmbed("loading", context, `Generating image...`)) + + if(!args.text) args.text = "" + try { + 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 + }] }) + } catch (e) { + await response.edit({ embeds: [createEmbed("error", context, e)] }) + } + }, +} \ No newline at end of file diff --git a/commands/message/image/makesweet/circuitboard.js b/commands/message/image/makesweet/circuitboard.js new file mode 100644 index 0000000..95e96dc --- /dev/null +++ b/commands/message/image/makesweet/circuitboard.js @@ -0,0 +1,46 @@ +const { createEmbed } = require("../../../../labscore/utils/embed"); +const { editOrReply } = require("../../../../labscore/utils/message"); + +const { getRecentImage } = require("../../../../labscore/utils/attachment"); + +const { circuitBoard } = require("../../../../service/makesweet"); +const { STATICS } = require("../../../../labscore/utils/statics"); + +module.exports = { + name: 'circuitboard', + label: 'text', + metadata: { + description: 'makesweet circuit board', + examples: ['circuitboard'], + category: 'image', + usage: 'circuitboard' + }, + run: async (context, args) => { + + let image = await getRecentImage(context, 50) + if(!image) return editOrReply(context, createEmbed("warning", context, "No images found.")) + + let response = await editOrReply(context, createEmbed("loading", context, `Generating image...`)) + + if(!args.text) args.text = "" + try { + 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 + }] }) + } catch (e) { + await response.edit({ embeds: [createEmbed("error", context, e)] }) + } + } +} \ No newline at end of file diff --git a/commands/message/image/makesweet/flag.js b/commands/message/image/makesweet/flag.js new file mode 100644 index 0000000..38caa2c --- /dev/null +++ b/commands/message/image/makesweet/flag.js @@ -0,0 +1,46 @@ +const { createEmbed } = require("../../../../labscore/utils/embed"); +const { editOrReply } = require("../../../../labscore/utils/message"); + +const { getRecentImage } = require("../../../../labscore/utils/attachment"); + +const { flag } = require("../../../../service/makesweet"); +const { STATICS } = require("../../../../labscore/utils/statics"); + +module.exports = { + name: 'flag', + label: 'text', + metadata: { + description: 'makesweet flag', + examples: ['flag'], + category: 'image', + usage: 'flag' + }, + run: async (context, args) => { + + let image = await getRecentImage(context, 50) + if(!image) return editOrReply(context, createEmbed("warning", context, "No images found.")) + + let response = await editOrReply(context, createEmbed("loading", context, `Generating image...`)) + + if(!args.text) args.text = "" + try { + 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 + }] }) + } catch (e) { + await response.edit({ embeds: [createEmbed("error", context, e)] }) + } + }, +} \ No newline at end of file diff --git a/commands/message/image/makesweet/heartlocket.js b/commands/message/image/makesweet/heartlocket.js new file mode 100644 index 0000000..b7798fe --- /dev/null +++ b/commands/message/image/makesweet/heartlocket.js @@ -0,0 +1,46 @@ +const { createEmbed } = require("../../../../labscore/utils/embed"); +const { editOrReply } = require("../../../../labscore/utils/message"); + +const { getRecentImage } = require("../../../../labscore/utils/attachment"); + +const { heartLocket } = require("../../../../service/makesweet"); +const { STATICS } = require("../../../../labscore/utils/statics"); + +module.exports = { + name: 'heartlocket', + label: 'text', + metadata: { + description: 'makesweet heart locket', + examples: ['heartlocket'], + category: 'image', + usage: 'heartlocket' + }, + run: async (context, args) => { + + let image = await getRecentImage(context, 50) + if(!image) return editOrReply(context, createEmbed("warning", context, "No images found.")) + + let response = await editOrReply(context, createEmbed("loading", context, `Generating image...`)) + + if(!args.text) args.text = "" + try { + 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 + }] }) + } catch (e) { + await response.edit({ embeds: [createEmbed("error", context, e)] }) + } + } +} \ No newline at end of file diff --git a/labscore/utils/statics.js b/labscore/utils/statics.js index e0c3e8a..11244b3 100644 --- a/labscore/utils/statics.js +++ b/labscore/utils/statics.js @@ -4,32 +4,32 @@ const { Hosts } = require('../api/endpoints') // Update the revision id to break discord cache const Statics = Object.freeze({ brands: { - photofunia: { - file: "brands/photofunia.png", - revision: 1 + bing: { + file: "brands/bing.png", + revision: 0 }, genius: { file: "brands/genius.png", revision: 0 }, - bing: { - file: "brands/bing.png", - revision: 0 - }, google: { file: "brands/google.png", revision: 0 }, - wolframalpha: { - file: "brands/wolframalpha.png", - revision: 1 - }, inferkit: { file: "brands/inferkit.png", revision: 0 }, - youtube: { - file: "brands/youtube.png", + makesweet: { + file: "brands/makesweet.png", + revision: 0 + }, + photofunia: { + file: "brands/photofunia.png", + revision: 1 + }, + tineye: { + file: "brands/tineye.png", revision: 1 }, urbandictionary: { @@ -40,8 +40,12 @@ const Statics = Object.freeze({ file: "brands/wikihow.png", revision: 1 }, - tineye: { - file: "brands/tineye.png", + wolframalpha: { + file: "brands/wolframalpha.png", + revision: 1 + }, + youtube: { + file: "brands/youtube.png", revision: 1 } } @@ -52,14 +56,15 @@ function staticAsset(static) { } module.exports.STATICS = Object.freeze({ - photofunia: staticAsset(Statics.brands.photofunia), - genius: staticAsset(Statics.brands.genius), bing: staticAsset(Statics.brands.bing), + genius: staticAsset(Statics.brands.genius), google: staticAsset(Statics.brands.google), - wolframalpha: staticAsset(Statics.brands.wolframalpha), inferkit: staticAsset(Statics.brands.inferkit), - youtube: staticAsset(Statics.brands.youtube), + makesweet: staticAsset(Statics.brands.makesweet), + photofunia: staticAsset(Statics.brands.photofunia), + tineye: staticAsset(Statics.brands.tineye), urbandictionary: staticAsset(Statics.brands.urbandictionary), wikihow: staticAsset(Statics.brands.wikihow), - tineye: staticAsset(Statics.brands.tineye) + wolframalpha: staticAsset(Statics.brands.wolframalpha), + youtube: staticAsset(Statics.brands.youtube) }) \ No newline at end of file diff --git a/service/makesweet.js b/service/makesweet.js new file mode 100644 index 0000000..96a7cec --- /dev/null +++ b/service/makesweet.js @@ -0,0 +1,70 @@ +const superagent = require('superagent') + +const effects = [ + "billboard-cityscape", + "circuit-board", + "flag", + "flying-bear", + "heart-locket", + "nesting-doll" +] + +async function fetchImage(url) { + try{ + let res = await superagent.get(`https://external-content.duckduckgo.com/iu/`) + .query({ + u: url + }) + return res.body + }catch(e){ + return null; + } +} + +async function processMakesweet(effect, args, image) { + try{ + if(image){ + image = await fetchImage(image) + if(!image) throw "Unable to fetch image" + + let res = await superagent.post(`http://api.makesweet.com/make/${effect}`) + .set("Authorization", process.env.makesweet) + .buffer(true) + .query(args) + .attach('image', image, 'image.png') + return res; + } + let res = await superagent.post(`http://api.makesweet.com/make/${effect}`) + .set("Authorization", process.env.makesweet) + .buffer(true) + .query(args) + return res + }catch(e){ + console.log(e) + throw "Unable to generate image." + } +} + +exports.heartLocket = async (text, url) => { + return await processMakesweet("heart-locket", { text: text, textfirst: 1 }, url) +} + +exports.billboardCityscape = async (url) => { + return await processMakesweet("billboard-cityscape", {}, url) +} + +exports.circuitBoard = async (url) => { + return await processMakesweet("circuit-board", {}, url) +} + +exports.flag = async (url) => { + return await processMakesweet("flag", {}, url) +} + +/*exports.flyingBear = async (text, url) => { + return await processMakesweet("flying-bear", { text: text, textfirst: 1 }, url) +} + +exports.nestingDoll = async (text, url) => { + return await processMakesweet("nesting-doll", { text: text, textfirst: 1 }, url) +}*/ \ No newline at end of file