mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 14:43: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`)
|
let res = await superagent.get(`https://otter.bruhmomentlol.repl.co/random`)
|
||||||
.set("User-Agent","labscore/2.0")
|
.set("User-Agent","labscore/2.0")
|
||||||
|
|
||||||
await editOrReply(context, {
|
return await editOrReply(context, {
|
||||||
embeds: [
|
embeds: [ createEmbed("image", context, {
|
||||||
createEmbed("default", context, {
|
url: `otter.${res.headers["x-file-ext"]}`
|
||||||
image: {
|
})],
|
||||||
url: `attachment://otter.${res.headers["x-file-ext"]}`
|
files: [{ filename: `otter.${res.headers["x-file-ext"]}`, value: res.body }]
|
||||||
}
|
|
||||||
})
|
|
||||||
],
|
|
||||||
files: [
|
|
||||||
{
|
|
||||||
filename: `otter.${res.headers["x-file-ext"]}`,
|
|
||||||
value: res.body
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(e)
|
|
||||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to fetch otter.`)]})
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to fetch otter.`)]})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,11 @@ module.exports = {
|
||||||
let res = await deepdream(context, image)
|
let res = await deepdream(context, image)
|
||||||
|
|
||||||
if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]})
|
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: {
|
return editOrReply(context, createEmbed("image", context, {
|
||||||
url: res.response.body.image
|
url: res.response.body.image,
|
||||||
},
|
time: res.timings
|
||||||
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){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
|
||||||
|
|
|
@ -22,15 +22,11 @@ module.exports = {
|
||||||
let res = await superresolution(context, image)
|
let res = await superresolution(context, image)
|
||||||
|
|
||||||
if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]})
|
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: {
|
return editOrReply(context, createEmbed("image", context, {
|
||||||
url: res.response.body.image
|
url: res.response.body.image,
|
||||||
},
|
time: res.timings
|
||||||
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){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
|
||||||
|
|
|
@ -22,15 +22,11 @@ module.exports = {
|
||||||
let res = await text2image(context, args.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])]})
|
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: {
|
return editOrReply(context, createEmbed("image", context, {
|
||||||
url: res.response.body.image
|
url: res.response.body.image,
|
||||||
},
|
time: res.timings
|
||||||
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){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]})
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]})
|
||||||
|
|
|
@ -22,15 +22,11 @@ module.exports = {
|
||||||
let res = await waifu2x(context, image)
|
let res = await waifu2x(context, image)
|
||||||
|
|
||||||
if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]})
|
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: {
|
return editOrReply(context, createEmbed("image", context, {
|
||||||
url: res.response.body.image
|
url: res.response.body.image,
|
||||||
},
|
time: res.timings
|
||||||
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){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
|
||||||
|
|
|
@ -27,20 +27,20 @@ module.exports = {
|
||||||
const timings = Date.now();
|
const timings = Date.now();
|
||||||
let mkswt = await billboardCityscape(image)
|
let mkswt = await billboardCityscape(image)
|
||||||
|
|
||||||
await response.edit({ embeds: [createEmbed("default", context, {
|
return await response.edit({
|
||||||
image: {
|
embeds: [createEmbed("image", context, {
|
||||||
url: "attachment://makesweet.gif"
|
url: "makesweet.gif",
|
||||||
},
|
time: ((Date.now() - timings) / 1000).toFixed(2),
|
||||||
footer: {
|
provider: {
|
||||||
iconUrl: STATICS.makesweet,
|
icon: STATICS.makesweet,
|
||||||
text: `MakeSweet • Took ${((Date.now() - timings) / 1000).toFixed(2)}s`
|
text: "MakeSweet"
|
||||||
}
|
}
|
||||||
})], files: [{
|
})],
|
||||||
filename: "makesweet.gif",
|
files: [{ filename: "makesweet.gif", value: mkswt.body }]
|
||||||
value: mkswt.body
|
})
|
||||||
}] })
|
|
||||||
} catch (e) {
|
} 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();
|
const timings = Date.now();
|
||||||
let mkswt = await circuitBoard(image)
|
let mkswt = await circuitBoard(image)
|
||||||
|
|
||||||
await response.edit({ embeds: [createEmbed("default", context, {
|
return await response.edit({
|
||||||
image: {
|
embeds: [createEmbed("image", context, {
|
||||||
url: "attachment://makesweet.gif"
|
url: "makesweet.gif",
|
||||||
},
|
time: ((Date.now() - timings) / 1000).toFixed(2),
|
||||||
footer: {
|
provider: {
|
||||||
iconUrl: STATICS.makesweet,
|
icon: STATICS.makesweet,
|
||||||
text: `MakeSweet • Took ${((Date.now() - timings) / 1000).toFixed(2)}s`
|
text: "MakeSweet"
|
||||||
}
|
}
|
||||||
})], files: [{
|
})],
|
||||||
filename: "makesweet.gif",
|
files: [{ filename: "makesweet.gif", value: mkswt.body }]
|
||||||
value: mkswt.body
|
})
|
||||||
}] })
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await response.edit({ embeds: [createEmbed("error", context, e)] })
|
await response.edit({ embeds: [createEmbed("error", context, e)] })
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,18 +27,17 @@ module.exports = {
|
||||||
const timings = Date.now();
|
const timings = Date.now();
|
||||||
let mkswt = await flag(image)
|
let mkswt = await flag(image)
|
||||||
|
|
||||||
await response.edit({ embeds: [createEmbed("default", context, {
|
return await response.edit({
|
||||||
image: {
|
embeds: [createEmbed("image", context, {
|
||||||
url: "attachment://makesweet.gif"
|
url: "makesweet.gif",
|
||||||
},
|
time: ((Date.now() - timings) / 1000).toFixed(2),
|
||||||
footer: {
|
provider: {
|
||||||
iconUrl: STATICS.makesweet,
|
icon: STATICS.makesweet,
|
||||||
text: `MakeSweet • Took ${((Date.now() - timings) / 1000).toFixed(2)}s`
|
text: "MakeSweet"
|
||||||
}
|
}
|
||||||
})], files: [{
|
})],
|
||||||
filename: "makesweet.gif",
|
files: [{ filename: "makesweet.gif", value: mkswt.body }]
|
||||||
value: mkswt.body
|
})
|
||||||
}] })
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await response.edit({ embeds: [createEmbed("error", context, e)] })
|
await response.edit({ embeds: [createEmbed("error", context, e)] })
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,18 +27,17 @@ module.exports = {
|
||||||
const timings = Date.now();
|
const timings = Date.now();
|
||||||
let mkswt = await heartLocket(args.text, image)
|
let mkswt = await heartLocket(args.text, image)
|
||||||
|
|
||||||
await response.edit({ embeds: [createEmbed("default", context, {
|
return await response.edit({
|
||||||
image: {
|
embeds: [createEmbed("image", context, {
|
||||||
url: "attachment://makesweet.gif"
|
url: "makesweet.gif",
|
||||||
},
|
time: ((Date.now() - timings) / 1000).toFixed(2),
|
||||||
footer: {
|
provider: {
|
||||||
iconUrl: STATICS.makesweet,
|
icon: STATICS.makesweet,
|
||||||
text: `MakeSweet • Took ${((Date.now() - timings) / 1000).toFixed(2)}s`
|
text: "MakeSweet"
|
||||||
}
|
}
|
||||||
})], files: [{
|
})],
|
||||||
filename: "makesweet.gif",
|
files: [{ filename: "makesweet.gif", value: mkswt.body }]
|
||||||
value: mkswt.body
|
})
|
||||||
}] })
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await response.edit({ embeds: [createEmbed("error", context, 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])]})
|
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]
|
image = res.response.body.data.images[res.response.body.data.best_quality]
|
||||||
return editOrReply(context, {embeds:[createEmbed("default", context, {
|
|
||||||
image: {
|
return editOrReply(context, createEmbed("image", context, {
|
||||||
url: image
|
url: image,
|
||||||
},
|
time: res.timings,
|
||||||
footer: {
|
provider: {
|
||||||
iconUrl: STATICS.photofunia,
|
icon: STATICS.photofunia,
|
||||||
text: `PhotoFunia • ${context.application.name} • Took ${res.timings}s`
|
text: "PhotoFunia"
|
||||||
}
|
}
|
||||||
})]})
|
}))
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
if(e.response?.body?.message) return editOrReply(context, {embeds:[createEmbed("error", context, e.response.body.message)]})
|
if(e.response?.body?.message) return editOrReply(context, {embeds:[createEmbed("error", context, e.response.body.message)]})
|
||||||
|
|
|
@ -20,16 +20,15 @@ module.exports = {
|
||||||
try{
|
try{
|
||||||
let res = await yacht(context, args.text)
|
let res = await yacht(context, args.text)
|
||||||
image = res.response.body.data.images[res.response.body.data.best_quality]
|
image = res.response.body.data.images[res.response.body.data.best_quality]
|
||||||
return editOrReply(context, {embeds:[createEmbed("default", context, {
|
|
||||||
description: `⛵`,
|
return editOrReply(context, createEmbed("image", context, {
|
||||||
image: {
|
url: image,
|
||||||
url: image
|
time: res.timings,
|
||||||
},
|
provider: {
|
||||||
footer: {
|
icon: STATICS.photofunia,
|
||||||
iconUrl: STATICS.photofunia,
|
text: "PhotoFunia"
|
||||||
text: `PhotoFunia • ${context.application.name} • Took ${res.timings}s`
|
|
||||||
}
|
}
|
||||||
})]})
|
}))
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]})
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]})
|
||||||
|
|
|
@ -24,26 +24,15 @@ module.exports = {
|
||||||
"data": args.text
|
"data": args.text
|
||||||
})
|
})
|
||||||
|
|
||||||
await response.edit({
|
return await response.edit({
|
||||||
embeds: [
|
embeds: [createEmbed("image", context, {
|
||||||
createEmbed("default", context, {
|
url: "qrcode.png",
|
||||||
image: {
|
time: ((Date.now() - t) / 1000).toFixed(2)
|
||||||
url: `attachment://qrcode.png`
|
})],
|
||||||
},
|
files: [{ filename: "qrcode.png", value: res.body }]
|
||||||
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
|
|
||||||
}]
|
|
||||||
})
|
})
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(e)
|
return await response.edit({ embeds: [createEmbed("error", context, `Unable to generate qr code.`) ] })
|
||||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate qr code.`)]})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -14,7 +14,10 @@ module.exports = {
|
||||||
},
|
},
|
||||||
run: async (context, args) => {
|
run: async (context, args) => {
|
||||||
context.triggerTyping();
|
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{
|
try{
|
||||||
let ss = await screenshot(context, args.url)
|
let ss = await screenshot(context, args.url)
|
||||||
if(ss.response.body.status){
|
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("error", context, "Unable to create screenshot.")] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return editOrReply(context, { embeds: [createEmbed("default", context, {
|
|
||||||
image: {
|
return await response.edit({
|
||||||
url: `attachment://screenshot.png`
|
embeds: [createEmbed("image", context, {
|
||||||
},
|
url: "screenshot.png",
|
||||||
footer: {
|
time: ss.timings
|
||||||
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 }]
|
||||||
}
|
})
|
||||||
})], files: [{
|
|
||||||
filename: "screenshot.png",
|
|
||||||
value: ss.response.body
|
|
||||||
}]})
|
|
||||||
} catch(e){
|
} 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) => {
|
"defaultNoFooter": (context) => {
|
||||||
return {
|
return {
|
||||||
color: COLORS.embed
|
color: COLORS.embed
|
||||||
|
@ -68,10 +77,29 @@ module.exports.createEmbed = function(type, context, content){
|
||||||
if(!embedTypes[type]) throw "Invalid Embed Type"
|
if(!embedTypes[type]) throw "Invalid Embed Type"
|
||||||
if(!content) embedTypes[type](context)
|
if(!content) embedTypes[type](context)
|
||||||
let emb = embedTypes[type](context)
|
let emb = embedTypes[type](context)
|
||||||
|
|
||||||
|
// Special handling
|
||||||
if(["success","warning","error","loading"].includes(type)){
|
if(["success","warning","error","loading"].includes(type)){
|
||||||
emb.author.name = content
|
emb.author.name = content
|
||||||
return emb
|
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)
|
return Object.assign(emb, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue