mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 06:33:05 -04:00
make all image responses use the same embed type
This commit is contained in:
parent
951cb87a82
commit
43d8801821
14 changed files with 138 additions and 152 deletions
|
@ -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.`)]})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,11 @@ 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`
|
||||
}
|
||||
})]})
|
||||
|
||||
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.`)]})
|
||||
|
|
|
@ -22,15 +22,11 @@ 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`
|
||||
}
|
||||
})]})
|
||||
|
||||
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.`)]})
|
||||
|
|
|
@ -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.`)]})
|
||||
|
|
|
@ -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.`)]})
|
||||
|
|
|
@ -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.")] })
|
||||
}
|
||||
},
|
||||
}
|
|
@ -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)] })
|
||||
}
|
||||
|
|
|
@ -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)] })
|
||||
}
|
||||
|
|
|
@ -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)] })
|
||||
}
|
||||
|
|
|
@ -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)]})
|
||||
|
|
|
@ -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.`)]})
|
||||
|
|
|
@ -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.`) ] })
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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.`) ] })
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue