mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 14:13:02 -04:00
major cleanup
This commit is contained in:
parent
ddd918470e
commit
a8cf49e31e
60 changed files with 537 additions and 619 deletions
|
@ -1,5 +1,5 @@
|
|||
const { codeblock, highlight, icon, link, pill, smallPill, iconPill } = require('../../../labscore/utils/markdown')
|
||||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { codeblock, icon, link, pill, smallPill, iconPill } = require('../../../labscore/utils/markdown')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
|
||||
const { DISCORD_INVITES, DEFAULT_BOT_PREFIX } = require('../../../labscore/constants')
|
||||
|
||||
|
@ -9,86 +9,80 @@ const { editOrReply } = require('../../../labscore/utils/message');
|
|||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
const { canUseLimitedTestCommands } = require('../../../labscore/utils/testing');
|
||||
|
||||
function createHelpPage(context, title, contents, descriptions){
|
||||
return {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
description: `${title}\n\n` +
|
||||
renderCommandList(contents, descriptions) +
|
||||
`\n\n${icon("question")} Use ${smallPill(`${DEFAULT_BOT_PREFIX}help <command>`)} to view more information about a command.`
|
||||
})
|
||||
]
|
||||
}
|
||||
function createHelpPage(context, title, contents, descriptions) {
|
||||
return page(createEmbed("default", context, {
|
||||
description: `${title}\n\n` +
|
||||
renderCommandList(contents, descriptions) +
|
||||
`\n\n${icon("question")} Use ${smallPill(`${DEFAULT_BOT_PREFIX}help <command>`)} to view more information about a command.`
|
||||
}))
|
||||
}
|
||||
|
||||
function renderCommandList(commands, descriptions, limit){
|
||||
function renderCommandList(commands, descriptions, limit) {
|
||||
let len = Math.max(...(commands.map(el => el.length))) + 3;
|
||||
let render = []
|
||||
let i = 0;
|
||||
for(const c of commands){
|
||||
for (const c of commands) {
|
||||
let pad = len - c.length;
|
||||
|
||||
let desc = descriptions[i]
|
||||
if(desc.includes('\n')) desc = desc.split('\n')[0]
|
||||
if(desc.length >= 41) desc = desc.substr(0, 40) + '...'
|
||||
if (desc.includes('\n')) desc = desc.split('\n')[0]
|
||||
if (desc.length >= 41) desc = desc.substr(0, 40) + '...'
|
||||
|
||||
render.push(` \` ${c}${' '.repeat(pad)}\` ${desc}`)
|
||||
i++
|
||||
}
|
||||
|
||||
if(limit && render.length > limit) render.splice(limit, 999)
|
||||
if (limit && render.length > limit) render.splice(limit, 999)
|
||||
|
||||
return render.join('\n')
|
||||
}
|
||||
|
||||
function createCommandPage(context, prefix, command){
|
||||
function createCommandPage(context, prefix, command) {
|
||||
alias = ' '
|
||||
if(command.aliases.length >= 1){
|
||||
for(const al of command.aliases) alias += smallPill(al)
|
||||
if (command.aliases.length >= 1) {
|
||||
for (const al of command.aliases) alias += smallPill(al)
|
||||
alias += "\n"
|
||||
}
|
||||
|
||||
let explicit = '';
|
||||
if(command.metadata.explicit) explicit = `\n${icon('channel_nsfw')} This command contains explicit content and can only be used in Age-Restricted channels. ${link("https://support.discord.com/hc/en-us/articles/115000084051-Age-Restricted-Channels-and-Content", "Learn More")}\n`
|
||||
if (command.metadata.explicit) explicit = `\n${icon('channel_nsfw')} This command contains explicit content and can only be used in Age-Restricted channels. ${link("https://support.discord.com/hc/en-us/articles/115000084051-Age-Restricted-Channels-and-Content", "Learn More")}\n`
|
||||
|
||||
// Render argument pills if present
|
||||
let args = [];
|
||||
if(command.argParser.args){
|
||||
for(const a of command.argParser.args){
|
||||
let argument = `-${a._name} <${a._type.replace('bool','true/false')}>`
|
||||
if (command.argParser.args) {
|
||||
for (const a of command.argParser.args) {
|
||||
let argument = `-${a._name} <${a._type.replace('bool', 'true/false')}>`
|
||||
argument = pill(argument)
|
||||
if(a.help) argument += ` ${a.help}`
|
||||
if (a.help) argument += ` ${a.help}`
|
||||
argument += `\n `
|
||||
if(a.default !== "") argument += ` ${smallPill(`default: ${a.default}`)}`
|
||||
if(!a.required) argument += ` ${smallPill('optional')}`
|
||||
if (a.default !== "") argument += ` ${smallPill(`default: ${a.default}`)}`
|
||||
if (!a.required) argument += ` ${smallPill('optional')}`
|
||||
args.push(argument)
|
||||
}
|
||||
}
|
||||
|
||||
let page = createEmbed("default", context, {
|
||||
let cPage = createEmbed("default", context, {
|
||||
description: `${icon("slash")} ${smallPill(command.name)}\n${alias}${explicit}\n${command.metadata.description}\n\n${args.join('\n\n')}`,
|
||||
fields: []
|
||||
})
|
||||
|
||||
// TODO: maybe try building a little parser that highlights things via ansi
|
||||
if(command.metadata.usage) page.fields.push({
|
||||
if (command.metadata.usage) cPage.fields.push({
|
||||
name: `${icon("settings")} Usage`,
|
||||
value: codeblock("py", [prefix + command.metadata.usage]),
|
||||
inline: true
|
||||
})
|
||||
|
||||
if(command.metadata.examples){
|
||||
if (command.metadata.examples) {
|
||||
let ex = []
|
||||
for(const e of command.metadata.examples) ex.push(prefix + e)
|
||||
page.fields.push({
|
||||
for (const e of command.metadata.examples) ex.push(prefix + e)
|
||||
cPage.fields.push({
|
||||
name: `${icon("example")} Examples`,
|
||||
value: '```' + ex.join('``````') + '```',
|
||||
inline: false
|
||||
})
|
||||
}
|
||||
return {
|
||||
embeds: [page]
|
||||
};
|
||||
return page(cPage);
|
||||
}
|
||||
|
||||
// These categories will be displayed to users, add them in the correct order
|
||||
|
@ -115,64 +109,61 @@ module.exports = {
|
|||
},
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
if(canUseLimitedTestCommands(context)) categories["limited"] = `${icon("stars")} Limited Test Commands`;
|
||||
else if(categories["limited"]) delete categories["limited"]
|
||||
if (canUseLimitedTestCommands(context)) categories["limited"] = `${icon("stars")} Limited Test Commands`;
|
||||
else if (categories["limited"]) delete categories["limited"]
|
||||
|
||||
if(args.command){
|
||||
if (args.command) {
|
||||
await context.triggerTyping()
|
||||
// Detailed command view
|
||||
|
||||
let resultScores = {}
|
||||
let resultMappings = {}
|
||||
|
||||
for(const c of context.commandClient.commands){
|
||||
if(c.name.includes(args.command.toLowerCase()) || c.aliases.filter((f)=>{return f.includes(args.command.toLowerCase())}).length >= 1){
|
||||
if(c.metadata.explicit && !context.channel.nsfw) continue;
|
||||
if(!categories[c.metadata.category] && !context.user.isClientOwner) continue;
|
||||
for (const c of context.commandClient.commands) {
|
||||
if (c.name.includes(args.command.toLowerCase()) || c.aliases.filter((f) => { return f.includes(args.command.toLowerCase()) }).length >= 1) {
|
||||
if (c.metadata.explicit && !context.channel.nsfw) continue;
|
||||
if (!categories[c.metadata.category] && !context.user.isClientOwner) continue;
|
||||
resultScores[c.name] = 1
|
||||
resultMappings[c.name] = c
|
||||
}
|
||||
// Boost exact matches to rank higher in the result list
|
||||
if(c.name == args.command.toLowerCase()) resultScores[c.name] += 1
|
||||
if(c.aliases.filter((f)=>{return f == args.command.toLowerCase()}).length >= 1) resultScores[c.name] += 1
|
||||
if (c.name == args.command.toLowerCase()) resultScores[c.name] += 1
|
||||
if (c.aliases.filter((f) => { return f == args.command.toLowerCase() }).length >= 1) resultScores[c.name] += 1
|
||||
}
|
||||
|
||||
let results = [];
|
||||
resultScores = Object.fromEntries(Object.entries(resultScores).sort(([,a],[,b]) => b-a));
|
||||
for(const k of Object.keys(resultScores)) results.push(resultMappings[k])
|
||||
resultScores = Object.fromEntries(Object.entries(resultScores).sort(([, a], [, b]) => b - a));
|
||||
for (const k of Object.keys(resultScores)) results.push(resultMappings[k])
|
||||
|
||||
let pages = []
|
||||
let prefix = DEFAULT_BOT_PREFIX
|
||||
try{
|
||||
try {
|
||||
|
||||
if(results.length == 0) return editOrReply(context, {embeds: [createEmbed("warning", context, "No commands found for the provided query.")]})
|
||||
if (results.length == 0) return editOrReply(context, createEmbed("warning", context, "No commands found for the provided query."))
|
||||
|
||||
if(results.length > 1) {
|
||||
// Command overview
|
||||
if (results.length > 1) {
|
||||
// Command overview
|
||||
|
||||
let cmds = results.map((m)=>{return m.name})
|
||||
let dscs = results.map((m)=>{return m.metadata.description_short})
|
||||
pages.push({embeds:[
|
||||
createEmbed("default", context, {
|
||||
let cmds = results.map((m) => { return m.name })
|
||||
let dscs = results.map((m) => { return m.metadata.description_short })
|
||||
pages.push(page(createEmbed("default", context, {
|
||||
description: `Check the pages for full command details.\n\n` + renderCommandList(cmds, dscs, 15) + `\n\n${icon("question")} Need help with something else? Contact us via our ${link(DISCORD_INVITES.support, "Support Server")}.`
|
||||
})
|
||||
]})
|
||||
})))
|
||||
|
||||
// Generate command detail pages
|
||||
for(const c of results){
|
||||
pages.push(createCommandPage(context, prefix, c))
|
||||
// Generate command detail pages
|
||||
for (const c of results) {
|
||||
pages.push(createCommandPage(context, prefix, c))
|
||||
}
|
||||
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
return editOrReply(context, createCommandPage(context, prefix, results[0]))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
return editOrReply(context, createCommandPage(context, prefix, results[0]))
|
||||
}
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
} else {
|
||||
|
@ -180,24 +171,23 @@ module.exports = {
|
|||
let commands = {}
|
||||
let descriptions = {}
|
||||
|
||||
for(const c of context.commandClient.commands){
|
||||
if(!categories[c.metadata.category]) continue;
|
||||
if(c.metadata.explicit && !context.channel.nsfw) continue;
|
||||
if(!commands[c.metadata.category]) commands[c.metadata.category] = []
|
||||
if(!descriptions[c.metadata.category]) descriptions[c.metadata.category] = []
|
||||
for (const c of context.commandClient.commands) {
|
||||
if (!categories[c.metadata.category]) continue;
|
||||
if (c.metadata.explicit && !context.channel.nsfw) continue;
|
||||
if (!commands[c.metadata.category]) commands[c.metadata.category] = []
|
||||
if (!descriptions[c.metadata.category]) descriptions[c.metadata.category] = []
|
||||
commands[c.metadata.category].push(`${c.name}`);
|
||||
descriptions[c.metadata.category].push(`${c.metadata.description_short}`);
|
||||
}
|
||||
|
||||
let pages = []
|
||||
for(const cat of Object.keys(categories)){
|
||||
for (const cat of Object.keys(categories)) {
|
||||
pages.push(createHelpPage(context, categories[cat], commands[cat], descriptions[cat]))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -18,10 +18,8 @@ module.exports = {
|
|||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
ping = await context.client.ping()
|
||||
editOrReply(context, {
|
||||
embeds: [createEmbed("default", context, {
|
||||
description: `${icon("latency")} **Pong!**\n` + codeblock("ansi", [`rest ${format(`${ping.rest}ms`, "m")}`, `gateway ${format(`${ping.gateway}ms`, "m")}`])
|
||||
})]
|
||||
})
|
||||
editOrReply(context, createEmbed("default", context, {
|
||||
description: `${icon("latency")} **Pong!**\n` + codeblock("ansi", [`rest ${format(`${ping.rest}ms`, "m")}`, `gateway ${format(`${ping.gateway}ms`, "m")}`])
|
||||
}))
|
||||
},
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const { highlight, iconPill, link, icon, pill, linkPill, iconLinkPill } = require('../../../labscore/utils/markdown')
|
||||
const { highlight, iconPill, iconLinkPill } = require('../../../labscore/utils/markdown')
|
||||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
|
||||
const { editOrReply } = require('../../../labscore/utils/message');
|
||||
|
@ -78,7 +78,7 @@ module.exports = {
|
|||
return;
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds: [createEmbed("error", context, "Unable to fetch bot statistics.")]})
|
||||
return editOrReply(context, createEmbed("error", context, "Unable to fetch bot statistics."))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -19,7 +19,7 @@ module.exports = {
|
|||
try{
|
||||
if(typeof(args.amount) == "string") args.amount = parseInt(args.amount)
|
||||
if(!args.amount) args.amount = 1
|
||||
if(args.amount >= 6 || args.amount <= 0) return await editOrReply(context, {embeds:[createEmbed("warning", context, "Invalid Argument (amount)")]})
|
||||
if(args.amount >= 6 || args.amount <= 0) return await editOrReply(context, createEmbed("warning", context, "Invalid Argument (amount)"))
|
||||
let cmds = [];
|
||||
let found = 0;
|
||||
for(const c of context.commandClient.replies.toArray().reverse()){
|
||||
|
|
|
@ -37,7 +37,7 @@ module.exports = {
|
|||
],
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.ATTACH_FILES, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
let response = await editOrReply(context, createEmbed("loading", context, `Generating image...`))
|
||||
await editOrReply(context, createEmbed("loading", context, `Generating image...`))
|
||||
try{
|
||||
let seed = Math.floor(Math.random() * 999999) + 100000,
|
||||
variance = Math.floor(Math.random() * 9999) + 1000,
|
||||
|
@ -112,7 +112,7 @@ module.exports = {
|
|||
})
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return await editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]})
|
||||
return await editOrReply(context, createEmbed("error", context, `Unable to generate image.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -20,18 +20,18 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
try{
|
||||
if (!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
try {
|
||||
let res = await superagent.get(`${process.env.AI_SERVER}/ask`)
|
||||
.query({
|
||||
prompt: args.text
|
||||
})
|
||||
return editOrReply(context, {embeds:[createEmbed("default", context, {
|
||||
.query({
|
||||
prompt: args.text
|
||||
})
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
description: codeblock("ansi", [format(args.text, "cyan") + res.body.text])
|
||||
})]})
|
||||
}catch(e){
|
||||
}))
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate text.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -25,7 +25,7 @@ module.exports = {
|
|||
if(!canUseLimitedTestCommands(context)) return;
|
||||
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
|
||||
let input = args.text;
|
||||
|
||||
|
@ -46,7 +46,7 @@ module.exports = {
|
|||
let description = []
|
||||
let files = [];
|
||||
|
||||
if(!res.body.output) return editOrReply(context, {embeds:[createEmbed("error", context, `Bard returned an error. Try again later.`)]})
|
||||
if(!res.body.output) return editOrReply(context, createEmbed("error", context, `Bard returned an error. Try again later.`))
|
||||
|
||||
if(res.body.output.length <= 4000) description.push(res.body.output)
|
||||
else {
|
||||
|
@ -70,10 +70,10 @@ module.exports = {
|
|||
files
|
||||
})
|
||||
}catch(e){
|
||||
if(e.response.body?.message) return editOrReply(context, {embeds:[createEmbed("warning", context, e.response.body.message)]})
|
||||
if(e.response.body?.message) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
|
||||
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate text.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -41,7 +41,7 @@ module.exports = {
|
|||
if(!canUseLimitedTestCommands(context)) return;
|
||||
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
|
||||
let input = args.text;
|
||||
|
||||
|
@ -56,13 +56,13 @@ module.exports = {
|
|||
else if(msg.embeds?.length) for(const e of msg.embeds) if(e[1].description?.length) { input = e[1].description; break; }
|
||||
|
||||
prompt = args.text
|
||||
if(args.prompt !== "") return editOrReply(context, {embeds:[createEmbed("warning", context, `Prompt parameter is unsupported for message replies.`)]})
|
||||
if(args.prompt !== "") return editOrReply(context, createEmbed("warning", context, `Prompt parameter is unsupported for message replies.`))
|
||||
}
|
||||
|
||||
let model = "CHATGPT"
|
||||
if(args.model && isLimitedTestUser(context.user)) model = args.model
|
||||
|
||||
if(!MODELS[model]) return editOrReply(context, {embeds:[createEmbed("warning", context, `Invalid or unsupported model (${model}).`)]})
|
||||
if(!MODELS[model]) return editOrReply(context, createEmbed("warning", context, `Invalid or unsupported model (${model}).`))
|
||||
|
||||
let temperature = "0.25"
|
||||
if(args.temperature !== 0.25) temperature = parseFloat(args.temperature)
|
||||
|
@ -113,7 +113,7 @@ module.exports = {
|
|||
})
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate text.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -23,7 +23,7 @@ module.exports = {
|
|||
run: async (context, args) => {
|
||||
if(!canUseLimitedTestCommands(context)) return;
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
|
||||
let prompt = 'You are a friendly chat bot designed to help people. You should always use gender neutral pronouns when possible.'
|
||||
if(args.prompt !== "") prompt = args.prompt
|
||||
|
@ -73,7 +73,7 @@ module.exports = {
|
|||
})
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate text.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -22,7 +22,7 @@ module.exports = {
|
|||
run: async (context, args) => {
|
||||
if(!canUseLimitedTestCommands(context)) return;
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
try{
|
||||
await editOrReply(context, createEmbed("ai", context, "Generating response..."))
|
||||
|
||||
|
@ -36,16 +36,16 @@ module.exports = {
|
|||
temperature: 0.6,
|
||||
model: "CHATGPT"
|
||||
})
|
||||
return editOrReply(context, {embeds:[createEmbed("default", context, {
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
description: smallIconPill("generative_ai", args.text) + '\n' + codeblock("ansi", [res.body.output.substr(0, 2020 - args.text.length)]),
|
||||
footer: {
|
||||
text: `🗣🗣📢🔥🔥🔥🔥💯 • ${context.application.name}`,
|
||||
iconUrl: STATICS.openai
|
||||
}
|
||||
})]})
|
||||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate text.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -22,19 +22,19 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
try{
|
||||
if (!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
try {
|
||||
let res = await inferkit(context, args.text)
|
||||
return editOrReply(context, {embeds:[createEmbed("default", context, {
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
description: codeblock("ansi", [format(res.response.body.input, "cyan") + res.response.body.output]),
|
||||
footer: {
|
||||
iconUrl: STATICS.inferkit,
|
||||
text: `InferKit • ${context.application.name} • Took ${res.timings}s`
|
||||
}
|
||||
})]})
|
||||
}catch(e){
|
||||
}))
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate text.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -17,21 +17,19 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.ATTACH_FILES, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context) => {
|
||||
await context.triggerTyping();
|
||||
try{
|
||||
try {
|
||||
let res = await superagent.get(`https://inspirobot.me/api?generate=true`)
|
||||
.set("User-Agent","labscore/2.0")
|
||||
.set("User-Agent", "labscore/2.0")
|
||||
|
||||
return await editOrReply(context, {
|
||||
embeds: [ createEmbed("image", context, {
|
||||
url: res.text,
|
||||
provider: {
|
||||
icon: STATICS.inspirobot,
|
||||
text: "Inspirobot"
|
||||
}
|
||||
})]
|
||||
})
|
||||
}catch(e){
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to fetch inspirational quote.`)]})
|
||||
return await editOrReply(context, createEmbed("image", context, {
|
||||
url: res.text,
|
||||
provider: {
|
||||
icon: STATICS.inspirobot,
|
||||
text: "Inspirobot"
|
||||
}
|
||||
}))
|
||||
} catch (e) {
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to fetch inspirational quote.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -27,7 +27,7 @@ module.exports = {
|
|||
files: [{ filename: `otter.${res.headers["x-file-ext"]}`, value: res.body }]
|
||||
})
|
||||
}catch(e){
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to fetch otter.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to fetch otter.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -2,10 +2,10 @@ const { createEmbed } = require('../../../labscore/utils/embed')
|
|||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const { canUseLimitedTestCommands, isLimitedTestUser } = require('../../../labscore/utils/testing')
|
||||
const { STATICS, STATIC_ICONS } = require('../../../labscore/utils/statics');
|
||||
const { STATIC_ICONS } = require('../../../labscore/utils/statics');
|
||||
|
||||
const superagent = require('superagent')
|
||||
const { iconPill, smallIconPill, icon } = require('../../../labscore/utils/markdown')
|
||||
const { iconPill } = require('../../../labscore/utils/markdown')
|
||||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
|
@ -29,7 +29,7 @@ module.exports = {
|
|||
if(!canUseLimitedTestCommands(context)) return;
|
||||
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
|
||||
let input = args.text;
|
||||
|
||||
|
@ -44,7 +44,7 @@ module.exports = {
|
|||
else if(msg.embeds?.length) for(const e of msg.embeds) if(e[1].description?.length) { input = e[1].description; break; }
|
||||
|
||||
prompt = args.text
|
||||
if(args.prompt !== "") return editOrReply(context, {embeds:[createEmbed("warning", context, `Prompt parameter is unsupported for message replies.`)]})
|
||||
if(args.prompt !== "") return editOrReply(context, createEmbed("warning", context, `Prompt parameter is unsupported for message replies.`))
|
||||
}
|
||||
|
||||
let model = "chat-bison-001"
|
||||
|
@ -73,7 +73,7 @@ module.exports = {
|
|||
let description = []
|
||||
let files = [];
|
||||
|
||||
if(!res.body.output) return editOrReply(context, {embeds:[createEmbed("error", context, `PaLM 2 returned an error. Try again later.`)]})
|
||||
if(!res.body.output) return editOrReply(context, createEmbed("error", context, `PaLM 2 returned an error. Try again later.`))
|
||||
|
||||
if(res.body.output.length <= 4000) description.push(res.body.output)
|
||||
else {
|
||||
|
@ -97,9 +97,9 @@ module.exports = {
|
|||
files
|
||||
})
|
||||
}catch(e){
|
||||
if(e.response.body?.message) return editOrReply(context, {embeds:[createEmbed("warning", context, e.response.body.message)]})
|
||||
if(e.response.body?.message) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate text.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -19,25 +19,23 @@ module.exports = {
|
|||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
let image = await getRecentImage(context, 50)
|
||||
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let label = await googleVisionLabels(context, image)
|
||||
|
||||
let labels = []
|
||||
for(const l of label.response.body.labels){
|
||||
labels.push(smallPill(`${l.score.toString().substr(2,2)}.${l.score.toString().substr(3,1)}%`) + ' ' + pill(l.name))
|
||||
for (const l of label.response.body.labels) {
|
||||
labels.push(smallPill(`${l.score.toString().substr(2, 2)}.${l.score.toString().substr(3, 1)}%`) + ' ' + pill(l.name))
|
||||
}
|
||||
return editOrReply(context, {
|
||||
embeds: [createEmbed("default", context, {
|
||||
description: labels.join('\n'),
|
||||
thumbnail: {
|
||||
url: image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud Vision • ${context.application.name}`
|
||||
}
|
||||
})]
|
||||
})
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
description: labels.join('\n'),
|
||||
thumbnail: {
|
||||
url: image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud Vision • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
},
|
||||
};
|
|
@ -2,7 +2,7 @@ const { googleVisionSafetyLabels } = require("../../../labscore/api");
|
|||
const { GOOGLE_CLOUD_SAFETY_LABELS, GOOGLE_CLOUD_SAFETY_LABELS_NAMES } = require("../../../labscore/constants");
|
||||
const { getRecentImage } = require("../../../labscore/utils/attachment");
|
||||
const { createEmbed } = require("../../../labscore/utils/embed");
|
||||
const { pill, iconPill, smallPill } = require("../../../labscore/utils/markdown");
|
||||
const { iconPill, smallPill } = require("../../../labscore/utils/markdown");
|
||||
const { editOrReply } = require("../../../labscore/utils/message");
|
||||
const { STATICS } = require("../../../labscore/utils/statics");
|
||||
|
||||
|
@ -20,29 +20,27 @@ module.exports = {
|
|||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
let image = await getRecentImage(context, 50)
|
||||
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let label = await googleVisionSafetyLabels(context, image)
|
||||
|
||||
let labels = []
|
||||
for(const l of Object.keys(label.response.body.labels)){
|
||||
for (const l of Object.keys(label.response.body.labels)) {
|
||||
let rating = GOOGLE_CLOUD_SAFETY_LABELS[label.response.body.labels[l]]
|
||||
labels.push([
|
||||
smallPill(GOOGLE_CLOUD_SAFETY_LABELS_NAMES[l]),
|
||||
iconPill(rating.icon, rating.name)
|
||||
].join(' '))
|
||||
}
|
||||
return editOrReply(context, {
|
||||
embeds: [createEmbed("default", context, {
|
||||
description: labels.join('\n'),
|
||||
thumbnail: {
|
||||
url: image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud Vision • ${context.application.name}`
|
||||
}
|
||||
})]
|
||||
})
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
description: labels.join('\n'),
|
||||
thumbnail: {
|
||||
url: image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud Vision • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
},
|
||||
};
|
|
@ -20,17 +20,17 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
if (!context.message.messageReference) return editOrReply(context, { embeds: [createEmbed("warning", context, "You need to reply to a voice message.")] })
|
||||
if (!context.message.messageReference) return editOrReply(context, createEmbed("warning", context, "You need to reply to a voice message."))
|
||||
try {
|
||||
let msg;
|
||||
try {
|
||||
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
||||
} catch (e) {
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, "Unable to fetch message.")] })
|
||||
return editOrReply(context, createEmbed("error", context, "Unable to fetch message."))
|
||||
}
|
||||
|
||||
if(!msg.attachments.first()) return editOrReply(context, { embeds: [createEmbed("warning", context, "No voice message found.")] })
|
||||
if(!msg.attachments.first().url.split('?')[0].endsWith('voice-message.ogg')) return editOrReply(context, { embeds: [createEmbed("warning", context, "No voice message found.")] })
|
||||
if(!msg.attachments.first()) return editOrReply(context, createEmbed("warning", context, "No voice message found."))
|
||||
if(!msg.attachments.first().url.split('?')[0].endsWith('voice-message.ogg')) return editOrReply(context, createEmbed("warning", context, "No voice message found."))
|
||||
|
||||
const recog = await googleSpeechRecognition(context, msg.attachments.first().url)
|
||||
|
||||
|
@ -44,8 +44,8 @@ module.exports = {
|
|||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, {embeds:[createEmbed("warning", context, e.response.body.message)]})
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, `Unable to transcribe audio.`)] })
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to transcribe audio.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -37,14 +37,14 @@ module.exports = {
|
|||
if(!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
}
|
||||
|
||||
let response = await editOrReply(context, { embeds: [createEmbed("loading", context, `Generating image...`)] })
|
||||
let response = await editOrReply(context, createEmbed("loading", context, `Generating image...`))
|
||||
|
||||
let noticeTimer = setTimeout(()=>{
|
||||
let emb = createEmbed("loading", context, `Generating image...`)
|
||||
emb.footer = {
|
||||
text: "This might take a moment to complete."
|
||||
};
|
||||
response.edit({ embeds: [ emb ] });
|
||||
editOrReply(context, { embeds: [ emb ] });
|
||||
}, 45000)
|
||||
|
||||
try{
|
||||
|
|
|
@ -23,9 +23,9 @@ module.exports = {
|
|||
},
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.ATTACH_FILES, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
if(!context.channel.nsfw) return editOrReply(context, {embeds:[createEmbed("nsfw", context)]})
|
||||
if(!context.channel.nsfw) return editOrReply(context, createEmbed("nsfw", context))
|
||||
|
||||
let response = await editOrReply(context, { embeds: [createEmbed("loading", context, `Synthesizing images...`)] })
|
||||
await editOrReply(context, createEmbed("loading", context, `Synthesizing images...`))
|
||||
|
||||
let noticeTimer = setTimeout(()=>{
|
||||
let emb = createEmbed("loading", context, `Synthesizing images...`)
|
|
@ -20,11 +20,11 @@ module.exports = {
|
|||
context.triggerTyping();
|
||||
try{
|
||||
let image = await getRecentImage(context, 50)
|
||||
if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||
if(!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
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, createEmbed("warning", context, res.response.body.errors[0]))
|
||||
|
||||
return editOrReply(context, createEmbed("image", context, {
|
||||
url: res.response.body.image,
|
||||
|
@ -32,7 +32,7 @@ module.exports = {
|
|||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Superresolution timed out.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Superresolution timed out.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -19,11 +19,11 @@ module.exports = {
|
|||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
try{
|
||||
if(!args.text) return editOrReply(context, { embeds: [createEmbed("warning", context, "Missing parameter (text).")] })
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, "Missing parameter (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, createEmbed("warning", context, res.response.body.errors[0]))
|
||||
|
||||
return editOrReply(context, createEmbed("image", context, {
|
||||
url: res.response.body.image,
|
||||
|
@ -31,7 +31,7 @@ module.exports = {
|
|||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Text2image timed out.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Text2image timed out.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -20,11 +20,11 @@ module.exports = {
|
|||
context.triggerTyping();
|
||||
try{
|
||||
let image = await getRecentImage(context, 50)
|
||||
if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||
if(!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
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, createEmbed("warning", context, res.response.body.errors[0]))
|
||||
|
||||
return editOrReply(context, createEmbed("image", context, {
|
||||
url: res.response.body.image,
|
||||
|
@ -32,7 +32,7 @@ module.exports = {
|
|||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Waifu2x timed out.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Waifu2x timed out.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -24,22 +24,22 @@ module.exports = {
|
|||
},
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.ATTACH_FILES, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
if(!args.prompt) return editOrReply(context, { embeds: [createEmbed("warning", context, "Missing prompt.")] })
|
||||
if (!args.prompt) return editOrReply(context, createEmbed("warning", context, "Missing prompt."))
|
||||
|
||||
let image = await getRecentImage(context, 50)
|
||||
if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let response = await editOrReply(context, { embeds: [createEmbed("loading", context, `Editing image...`)] })
|
||||
let response = await editOrReply(context, createEmbed("loading", context, `Editing image...`))
|
||||
|
||||
let noticeTimer = setTimeout(()=>{
|
||||
let noticeTimer = setTimeout(() => {
|
||||
let emb = createEmbed("loading", context, `Editing image...`)
|
||||
emb.footer = {
|
||||
text: "This might take several minutes to complete."
|
||||
};
|
||||
response.edit({ embeds: [ emb ] });
|
||||
response.edit({ embeds: [emb] });
|
||||
}, 45000)
|
||||
|
||||
try{
|
||||
try {
|
||||
let img = await superagent.get(`${process.env.AI_SERVER}/deepai/imageeditor`)
|
||||
.query({
|
||||
prompt: args.prompt,
|
||||
|
@ -56,10 +56,10 @@ module.exports = {
|
|||
})],
|
||||
files: [{ filename: "edited.jpg", value: imageData.body }]
|
||||
})
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
clearTimeout(noticeTimer)
|
||||
await response.edit({embeds:[createEmbed("error", context, `Image generation failed.`)]})
|
||||
await response.edit({ embeds: [createEmbed("error", context, `Image generation failed.`)] })
|
||||
}
|
||||
},
|
||||
};
|
|
@ -21,11 +21,11 @@ module.exports = {
|
|||
run: async (context, args) => {
|
||||
|
||||
let image = await getRecentImage(context, 50)
|
||||
if(!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let response = await editOrReply(context, createEmbed("loading", context, `Generating image...`))
|
||||
await editOrReply(context, createEmbed("loading", context, `Generating image...`))
|
||||
|
||||
if(!args.text) args.text = ""
|
||||
if (!args.text) args.text = ""
|
||||
try {
|
||||
const timings = Date.now();
|
||||
let mkswt = await billboardCityscape(image)
|
||||
|
@ -43,7 +43,7 @@ module.exports = {
|
|||
})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
await editOrReply(context, { embeds: [createEmbed("error", context, "Something went wrong.")] })
|
||||
await editOrReply(context, createEmbed("error", context, "Something went wrong."))
|
||||
}
|
||||
},
|
||||
}
|
|
@ -23,7 +23,7 @@ module.exports = {
|
|||
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...`))
|
||||
await editOrReply(context, createEmbed("loading", context, `Generating image...`))
|
||||
|
||||
if(!args.text) args.text = ""
|
||||
try {
|
||||
|
|
|
@ -23,7 +23,7 @@ module.exports = {
|
|||
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...`))
|
||||
await editOrReply(context, createEmbed("loading", context, `Generating image...`))
|
||||
|
||||
if(!args.text) args.text = ""
|
||||
try {
|
||||
|
|
|
@ -24,7 +24,7 @@ module.exports = {
|
|||
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...`))
|
||||
await editOrReply(context, createEmbed("loading", context, `Generating image...`))
|
||||
|
||||
if(!args.text) args.text = ""
|
||||
try {
|
||||
|
|
|
@ -23,15 +23,18 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.ATTACH_FILES, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
if(args.background > 5 || args.background < 1) return editOrReply(context, {embeds:[createEmbed("warning", context, `Invalid Parameter (background).`)]})
|
||||
if(args.style > 4 || args.style < 1) return editOrReply(context, {embeds:[createEmbed("warning", context, `Invalid Parameter (style).`)]})
|
||||
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
if(args.background > 5 || args.background < 1) return editOrReply(context, createEmbed("warning", context, `Invalid Parameter (background).`))
|
||||
if(args.style > 4 || args.style < 1) return editOrReply(context, createEmbed("warning", context, `Invalid Parameter (style).`))
|
||||
|
||||
let lines = `${args.text}| | `.split('|')
|
||||
if(args.text.includes('|')) lines = [lines[1], lines[2], lines[0]]
|
||||
|
||||
try{
|
||||
let res = await retroWave(context, args.background, args.style, lines[2], lines[0], lines[1])
|
||||
|
||||
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, createEmbed("warning", context, res.response.body.errors[0]))
|
||||
|
||||
image = res.response.body.data.images[res.response.body.data.best_quality]
|
||||
|
||||
|
@ -45,8 +48,8 @@ module.exports = {
|
|||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
if(e.response?.body?.message) return editOrReply(context, {embeds:[createEmbed("error", context, e.response.body.message)]})
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]})
|
||||
if(e.response?.body?.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate image.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -19,8 +19,10 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.ATTACH_FILES, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.text) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (text).`)]})
|
||||
if(args.text.length >= 26) return editOrReply(context, {embeds:[createEmbed("warning", context, `Parameter text too long (>25).`)]})
|
||||
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
if(args.text.length >= 26) return editOrReply(context, createEmbed("warning", context, `Parameter text too long (>25).`))
|
||||
|
||||
try{
|
||||
let res = await yacht(context, args.text)
|
||||
image = res.response.body.data.images[res.response.body.data.best_quality]
|
||||
|
@ -35,7 +37,7 @@ module.exports = {
|
|||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to generate image.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate image.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
context.triggerTyping();
|
||||
if(!args.user) args.user = context.userId;
|
||||
let u = await getUser(context, args.user)
|
||||
if(!u|| !u.user) return editOrReply(context, { embeds: [createEmbed("warning", context, "No users found.")] })
|
||||
if(!u|| !u.user) return editOrReply(context, createEmbed("warning", context, "No users found."))
|
||||
|
||||
const avatar = u.user.avatarUrl + '?size=512'
|
||||
try{
|
||||
|
@ -41,7 +41,7 @@ module.exports = {
|
|||
})
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, "Unable to generate overlay.")] })
|
||||
return editOrReply(context, createEmbed("error", context, "Unable to generate overlay."))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -22,7 +22,7 @@ module.exports = {
|
|||
context.triggerTyping();
|
||||
if(!args.user) args.user = context.userId;
|
||||
let u = await getUser(context, args.user)
|
||||
if(!u || !u.user) return editOrReply(context, { embeds: [createEmbed("warning", context, "No users found.")] })
|
||||
if(!u || !u.user) return editOrReply(context, createEmbed("warning", context, "No users found."))
|
||||
|
||||
if(u.member && u.member.avatar !== null) {
|
||||
let pages = []
|
||||
|
@ -38,7 +38,7 @@ module.exports = {
|
|||
}
|
||||
})))
|
||||
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages,
|
||||
buttons: [{
|
||||
|
|
|
@ -100,10 +100,9 @@ module.exports = {
|
|||
pages.push(page(JSON.parse(JSON.stringify(Object.assign({ ...guildCard }, { fields: sub })))))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ const { Permissions } = require("detritus-client/lib/constants");
|
|||
|
||||
module.exports = {
|
||||
name: 'servericon',
|
||||
aliases: ["guildicon","gi","si","groupicon"],
|
||||
aliases: ["guildicon", "gi", "si", "groupicon"],
|
||||
metadata: {
|
||||
description: 'Displays the server icon.',
|
||||
description_short: 'Server icon',
|
||||
|
@ -15,13 +15,11 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
if(!context.guild.iconUrl) return editOrReply(context, createEmbed("warning", context, "Server doesn't have an icon."))
|
||||
return editOrReply(context, {
|
||||
embeds: [createEmbed("default", context, {
|
||||
image: {
|
||||
url: context.guild.iconUrl + "?size=4096"
|
||||
}
|
||||
})]
|
||||
})
|
||||
if (!context.guild.iconUrl) return editOrReply(context, createEmbed("warning", context, "Server doesn't have an icon."))
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
image: {
|
||||
url: context.guild.iconUrl + "?size=4096"
|
||||
}
|
||||
}))
|
||||
},
|
||||
};
|
|
@ -3,7 +3,7 @@ const { createEmbed, formatPaginationEmbeds, page } = require("../../../labscore
|
|||
const { guildFeaturesField } = require("../../../labscore/utils/fields");
|
||||
const { icon, highlight, timestamp, link, iconPill, iconLinkPill } = require("../../../labscore/utils/markdown");
|
||||
const { editOrReply } = require("../../../labscore/utils/message");
|
||||
const { STATICS, STATIC_ASSETS } = require("../../../labscore/utils/statics");
|
||||
const { STATIC_ASSETS } = require("../../../labscore/utils/statics");
|
||||
|
||||
const { paginator } = require('../../../labscore/client');
|
||||
|
||||
|
@ -76,10 +76,9 @@ module.exports = {
|
|||
pages.push(page(JSON.parse(JSON.stringify(Object.assign({ ...inviteCard }, { fields: sub })))))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ module.exports = {
|
|||
if(!args.user) { args.user = context.user.id }
|
||||
user = await getUser(context, args.user)
|
||||
u = user.user
|
||||
if(!u) return editOrReply(context, { embeds: [createEmbed("warning", context, "No users found.")] })
|
||||
if(!u) return editOrReply(context, createEmbed("warning", context, "No users found."))
|
||||
let m = user.member
|
||||
|
||||
// User Card
|
||||
|
@ -82,7 +82,7 @@ module.exports = {
|
|||
inline: true
|
||||
})
|
||||
}
|
||||
return editOrReply(context, { embeds: [userCard] })
|
||||
return editOrReply(context, userCard)
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const { Constants } = require("detritus-client");
|
||||
const { perspective } = require("../../../labscore/api");
|
||||
const { format } = require("../../../labscore/utils/ansi");
|
||||
const { createEmbed } = require("../../../labscore/utils/embed");
|
||||
|
@ -59,17 +58,15 @@ module.exports = {
|
|||
|
||||
let perspectiveApi = await perspective(context, [args.input])
|
||||
|
||||
return await editOrReply(context, {
|
||||
embeds: [createEmbed("default", context, {
|
||||
description: `${msg}${iconPill("agreements", "Scores")} ${codeblock("ansi", formatPerspectiveScores(perspectiveApi.response.body))}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.perspectiveapi,
|
||||
text: `Perspective • ${context.application.name}`
|
||||
}
|
||||
})]
|
||||
})
|
||||
return await editOrReply(context, createEmbed("default", context, {
|
||||
description: `${msg}${iconPill("agreements", "Scores")} ${codeblock("ansi", formatPerspectiveScores(perspectiveApi.response.body))}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.perspectiveapi,
|
||||
text: `Perspective • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
} catch (e) {
|
||||
await editOrReply(context, { embeds: [createEmbed("error", context, `Something went wrong.`)] })
|
||||
await editOrReply(context, createEmbed("error", context, `Something went wrong.`))
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
if (!context.message.messageReference) return editOrReply(context, { embeds: [createEmbed("warning", context, "You need to reply to a message containing a song link.")] })
|
||||
if (!context.message.messageReference) return editOrReply(context, createEmbed("warning", context, "You need to reply to a message containing a song link."))
|
||||
try {
|
||||
let msg;
|
||||
try {
|
||||
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
||||
} catch (e) {
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, "Unable to fetch message.")] })
|
||||
return editOrReply(context, createEmbed("error", context, "Unable to fetch message."))
|
||||
}
|
||||
let urls = msg.content.match(urlr)
|
||||
if (urls) {
|
||||
|
@ -54,7 +54,7 @@ module.exports = {
|
|||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, `Unable to perform song search.`)] })
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform song search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
||||
|
@ -7,26 +7,23 @@ const { bingImages } = require('../../../labscore/api');
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createImageResultPage(context, result){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(result.url)}&sz=256`,
|
||||
name: result.title,
|
||||
url: result.url
|
||||
},
|
||||
image: {
|
||||
url: result.image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.bing,
|
||||
text: `Microsoft Bing • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
function createImageResultPage(context, result) {
|
||||
let res = page(
|
||||
createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(result.url)}&sz=256`,
|
||||
name: result.title,
|
||||
url: result.url
|
||||
},
|
||||
image: {
|
||||
url: result.image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.bing,
|
||||
text: `Microsoft Bing • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if (result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -44,28 +41,27 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
try{
|
||||
if (!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try {
|
||||
let search = await bingImages(context, args.query, context.channel.nsfw)
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||
if (search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.results){
|
||||
for (const res of search.body.results) {
|
||||
pages.push(createImageResultPage(context, res))
|
||||
}
|
||||
|
||||
if(!pages.length) return editOrReply(context, {embeds:[createEmbed("warning", context, `No results found.`)]})
|
||||
if (!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform bing search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform bing search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -108,12 +108,12 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
if(!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try{
|
||||
let search = await bing(context, args.query, context.channel.nsfw)
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||
if(search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.results){
|
||||
|
@ -121,16 +121,15 @@ module.exports = {
|
|||
if(sp) pages.push(sp)
|
||||
}
|
||||
|
||||
if(!pages.length) return editOrReply(context, {embeds:[createEmbed("warning", context, `No results found.`)]})
|
||||
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform bing search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform bing search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
||||
|
@ -7,26 +7,22 @@ const { googleImages } = require('../../../labscore/api');
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createImageResultPage(context, result){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(result.url)}&sz=256`,
|
||||
name: result.title,
|
||||
url: result.url
|
||||
},
|
||||
image: {
|
||||
url: result.image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Images • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
function createImageResultPage(context, result) {
|
||||
let res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(result.url)}&sz=256`,
|
||||
name: result.title,
|
||||
url: result.url
|
||||
},
|
||||
image: {
|
||||
url: result.image
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Images • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if (result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -44,28 +40,27 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
try{
|
||||
if (!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try {
|
||||
let search = await googleImages(context, args.query, context.channel.nsfw)
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||
if (search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.results){
|
||||
for (const res of search.body.results) {
|
||||
pages.push(createImageResultPage(context, res))
|
||||
}
|
||||
|
||||
if(!pages.length) return editOrReply(context, {embeds:[createEmbed("warning", context, `No results found.`)]})
|
||||
if (!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform google search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -67,28 +67,27 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
if(!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try{
|
||||
let search = await google(context, args.query, context.channel.nsfw)
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||
if(search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.results){
|
||||
pages.push(createSearchResultPage(context, res))
|
||||
}
|
||||
|
||||
if(!pages.length) return editOrReply(context, {embeds:[createEmbed("warning", context, `No results found.`)]})
|
||||
if(!pages.length) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform google search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
||||
|
@ -52,12 +52,12 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
if(!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try{
|
||||
let search = await lyrics(context, args.query)
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||
if(search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||
let fields = [];
|
||||
|
||||
for(const f of search.body.lyrics.split('\n\n')){
|
||||
|
@ -78,18 +78,17 @@ module.exports = {
|
|||
pageFields = pageFields.splice(0, pageFields.length - 1)
|
||||
}
|
||||
|
||||
pages.push({embeds:[createLyricsPage(context, search, pageFields)]})
|
||||
pages.push(page(createLyricsPage(context, search, pageFields)))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
if(e.response?.body?.status && e.response.body.status == 2 && e.response.body.message) return editOrReply(context, {embeds:[createEmbed("error", context, e.response.body.message)]})
|
||||
if(e.response?.body?.status && e.response.body.status == 2 && e.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
||||
console.log(JSON.stringify(e.raw))
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Something went wrong.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Something went wrong.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { link, pill } = require('../../../labscore/utils/markdown')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
@ -10,32 +10,29 @@ const { Components } = require('detritus-client/lib/utils');
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createQuoraAnswerPage(context, question, answer){
|
||||
function createQuoraAnswerPage(context, question, answer) {
|
||||
let tags = question.tags.map((t) => {
|
||||
return pill(t)
|
||||
})
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
title: question.title,
|
||||
url: answer.url,
|
||||
description: `${tags.splice(0, 3).join(' ')}\n\n${answer.content.substr(0,2000)}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.quora,
|
||||
text: `Quora • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
let res = page(
|
||||
createEmbed("default", context, {
|
||||
title: question.title,
|
||||
url: answer.url,
|
||||
description: `${tags.splice(0, 3).join(' ')}\n\n${answer.content.substr(0, 2000)}`,
|
||||
footer: {
|
||||
iconUrl: STATICS.quora,
|
||||
text: `Quora • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
|
||||
if(answer.content.length >= 2000){
|
||||
if(res.embeds[0].description.endsWith(' ')) res.embeds[0].description = res.embeds[0].description.substr(0,res.embeds[0].description.length - 1)
|
||||
if (answer.content.length >= 2000) {
|
||||
if (res.embeds[0].description.endsWith(' ')) res.embeds[0].description = res.embeds[0].description.substr(0, res.embeds[0].description.length - 1)
|
||||
res.embeds[0].description += link(answer.url, '...', 'Click to read the entire answer.')
|
||||
}
|
||||
|
||||
if(answer.author){
|
||||
if (answer.author) {
|
||||
res.embeds[0].author = {
|
||||
name: answer.author.name.substr(0,1000),
|
||||
name: answer.author.name.substr(0, 1000),
|
||||
iconUrl: answer.author.icon,
|
||||
url: answer.author.url
|
||||
}
|
||||
|
@ -43,7 +40,7 @@ function createQuoraAnswerPage(context, question, answer){
|
|||
return res;
|
||||
}
|
||||
|
||||
async function quoraPaginator(context, pages, refMappings, currentRef){
|
||||
async function quoraPaginator(context, pages, refMappings, currentRef) {
|
||||
const paging = await paginator.createPaginator({
|
||||
context,
|
||||
pages,
|
||||
|
@ -55,7 +52,7 @@ async function quoraPaginator(context, pages, refMappings, currentRef){
|
|||
});
|
||||
|
||||
paging.on("interaction", async ({ context: ctx, listener }) => {
|
||||
if(ctx.customId == "search"){
|
||||
if (ctx.customId == "search") {
|
||||
// Kill the original paginator and replace it with a select
|
||||
listener.stopWithoutUpdate()
|
||||
|
||||
|
@ -74,16 +71,16 @@ async function quoraPaginator(context, pages, refMappings, currentRef){
|
|||
// Get the page reference and fetch the results
|
||||
let ref = refMappings.filter((r) => r.ref == sctx.data.values[0])
|
||||
ref = ref[0]
|
||||
try{
|
||||
try {
|
||||
let search = await quoraResult(context, ref.link)
|
||||
search = search.response.body
|
||||
|
||||
if(search.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.message)]})
|
||||
if (search.status == 2) return editOrReply(context, createEmbed("error", context, search.message))
|
||||
|
||||
let nextPages = []
|
||||
// Create the initial page
|
||||
|
||||
for(const answer of search.answers){
|
||||
for (const answer of search.answers) {
|
||||
nextPages.push(createQuoraAnswerPage(context, search.question, answer))
|
||||
}
|
||||
|
||||
|
@ -91,9 +88,9 @@ async function quoraPaginator(context, pages, refMappings, currentRef){
|
|||
|
||||
await quoraPaginator(context, nextPages, refMappings, sctx.data.values[0])
|
||||
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform quora search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform quora search.`))
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -112,7 +109,7 @@ async function quoraPaginator(context, pages, refMappings, currentRef){
|
|||
options: selectOptions
|
||||
})
|
||||
|
||||
await ctx.editOrRespond({content: `<@${context.userId}> Select a question.`, components})
|
||||
await ctx.editOrRespond({ content: `<@${context.userId}> Select a question.`, components })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -131,17 +128,17 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
try{
|
||||
if (!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try {
|
||||
let search = await quora(context, args.query)
|
||||
search = search.response.body
|
||||
|
||||
if(search.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.message)]})
|
||||
if (search.status == 2) return editOrReply(context, createEmbed("error", context, search.message))
|
||||
|
||||
let pages = []
|
||||
|
||||
// Create the initial page
|
||||
for(const answer of search.answers){
|
||||
for (const answer of search.answers) {
|
||||
pages.push(createQuoraAnswerPage(context, search.question, answer))
|
||||
}
|
||||
|
||||
|
@ -151,9 +148,9 @@ module.exports = {
|
|||
|
||||
await quoraPaginator(context, pages, refMappings, refMappings[0].ref)
|
||||
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform quora search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform quora search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { link, icon, highlight, iconPill } = require('../../../labscore/utils/markdown')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { link, icon, iconPill } = require('../../../labscore/utils/markdown')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
||||
|
@ -8,24 +8,20 @@ const { reddit } = require('../../../labscore/api');
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createRedditPage(context, result){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: result.subreddit.icon,
|
||||
name: result.subreddit.name,
|
||||
url: result.subreddit.link
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.reddit,
|
||||
text: `Reddit • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
function createRedditPage(context, result) {
|
||||
let res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: result.subreddit.icon,
|
||||
name: result.subreddit.name,
|
||||
url: result.subreddit.link
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.reddit,
|
||||
text: `Reddit • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
|
||||
if(result.post.image) res.embeds[0].image = { url: result.post.image };
|
||||
if (result.post.image) res.embeds[0].image = { url: result.post.image };
|
||||
|
||||
let description = [`**${link(result.post.link, result.post.title)}**`]
|
||||
|
||||
|
@ -35,7 +31,7 @@ function createRedditPage(context, result){
|
|||
// awardData.push(`${icon(`reddit_${a}`)}${highlight(result.awards[a])}`)
|
||||
//}
|
||||
|
||||
if(awardData.length >= 1) description.push(`${awardData.join(' ')}`)
|
||||
if (awardData.length >= 1) description.push(`${awardData.join(' ')}`)
|
||||
|
||||
description.push(``)
|
||||
description.push(`${iconPill("upvote", result.post.score)} ${icon("user")} ${link(result.author.link, `u/${result.author.name}`)}`)
|
||||
|
@ -61,30 +57,29 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
try{
|
||||
if (!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try {
|
||||
let search = await reddit(context, args.query, context.channel.nsfw)
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||
if (search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.results){
|
||||
if(args.type == "image" && !res.post.image) continue;
|
||||
for (const res of search.body.results) {
|
||||
if (args.type == "image" && !res.post.image) continue;
|
||||
pages.push(createRedditPage(context, res))
|
||||
}
|
||||
|
||||
if(pages.length == 0) return editOrReply(context, {embeds:[createEmbed("warning", context, `No results found.`)]})
|
||||
if (pages.length == 0) return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
if(e.response && e.response.body.message) return editOrReply(context, {embeds:[createEmbed("error", context, e.response.body.message)]})
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform reddit search.`)]})
|
||||
if (e.response && e.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform reddit search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
const { getRecentImage } = require("../../../labscore/utils/attachment");
|
||||
|
@ -8,35 +8,32 @@ const { reverseImageSearch } = require('../../../labscore/api');
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createReverseImageSearchResultPage(context, result, source){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(result.url)}&sz=256`,
|
||||
name: result.name,
|
||||
url: result.url
|
||||
},
|
||||
image: {
|
||||
url: result.image
|
||||
},
|
||||
thumbnail: {
|
||||
url: source
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud Vision • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
function createReverseImageSearchResultPage(context, result, source) {
|
||||
let res = page(
|
||||
createEmbed("default", context, {
|
||||
author: {
|
||||
iconUrl: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(result.url)}&sz=256`,
|
||||
name: result.name,
|
||||
url: result.url
|
||||
},
|
||||
image: {
|
||||
url: result.image
|
||||
},
|
||||
thumbnail: {
|
||||
url: source
|
||||
},
|
||||
footer: {
|
||||
iconUrl: STATICS.google,
|
||||
text: `Google Cloud Vision • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if (result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'reverse-image',
|
||||
aliases: ['reverse','reverseimage'],
|
||||
aliases: ['reverse', 'reverseimage'],
|
||||
metadata: {
|
||||
description: 'Performs a reverse-image-search.',
|
||||
description_short: 'Reverse image search',
|
||||
|
@ -46,28 +43,27 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
try{
|
||||
try {
|
||||
let image = await getRecentImage(context, 50)
|
||||
if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let search = await reverseImageSearch(context, image)
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||
if (search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.results){
|
||||
for (const res of search.body.results) {
|
||||
pages.push(createReverseImageSearchResultPage(context, res, image))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform reverse image search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform reverse image search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { pill } = require('../../../labscore/utils/markdown')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
|
@ -7,26 +7,22 @@ const { rule34 } = require('../../../labscore/api');
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createRule34Page(context, result){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
description: '',
|
||||
image: {
|
||||
url: result.fileUrl
|
||||
},
|
||||
footer: {
|
||||
text: `Rating: ${result.rating}`
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
function createRule34Page(context, result) {
|
||||
let res = page(createEmbed("default", context, {
|
||||
description: '',
|
||||
image: {
|
||||
url: result.fileUrl
|
||||
},
|
||||
footer: {
|
||||
text: `Rating: ${result.rating}`
|
||||
}
|
||||
}))
|
||||
|
||||
// Render a few tags
|
||||
if(result.tags) {
|
||||
if (result.tags) {
|
||||
let tags = result.tags.splice(0, 5)
|
||||
let tagDisplay = ''
|
||||
for(const t of tags) tagDisplay += pill(t)
|
||||
for (const t of tags) tagDisplay += pill(t)
|
||||
res.embeds[0].description += `\n${tagDisplay}`
|
||||
}
|
||||
|
||||
|
@ -56,39 +52,38 @@ module.exports = {
|
|||
usage: 'rule34 <query> [-site <service>]'
|
||||
},
|
||||
args: [
|
||||
{name: 'site', default: 'rule34', type: 'string', help: `Site to search on \` ${Object.keys(SITES).join(', ')} \``}
|
||||
{ name: 'site', default: 'rule34', type: 'string', help: `Site to search on \` ${Object.keys(SITES).join(', ')} \`` }
|
||||
],
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
|
||||
// very important, maybe make this a command option eventually
|
||||
if(!context.channel.nsfw){
|
||||
return editOrReply(context, {embeds:[createEmbed("nsfw", context)]})
|
||||
if (!context.channel.nsfw) {
|
||||
return editOrReply(context, createEmbed("nsfw", context))
|
||||
}
|
||||
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
if(!Object.keys(SITES).includes(args.site.toLowerCase())) return editOrReply(context, {embeds:[createEmbed("warning", context, `Invalid site type.`)]})
|
||||
try{
|
||||
if (!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
if (!Object.keys(SITES).includes(args.site.toLowerCase())) return editOrReply(context, createEmbed("warning", context, `Invalid site type.`))
|
||||
try {
|
||||
let search = await rule34(context, args.query, args.site.toLowerCase())
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message )]})
|
||||
if(search.body.data.length == 0) return editOrReply(context, {embeds:[createEmbed("warning", context, `No results found on ${SITES[args.site.toLowerCase()]}.`)]})
|
||||
if (search.body.status == 2) return editOrReply(context, createEmbed("error", context, search.body.message))
|
||||
if (search.body.data.length == 0) return editOrReply(context, createEmbed("warning", context, `No results found on ${SITES[args.site.toLowerCase()]}.`))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.data){
|
||||
for (const res of search.body.data) {
|
||||
pages.push(createRule34Page(context, res))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform rule34 search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform rule34 search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { link, iconPill } = require('../../../labscore/utils/markdown')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
@ -32,8 +32,7 @@ function createUrbanPage(context, result){
|
|||
value: result.example.substr(0, 1023),
|
||||
inline: false
|
||||
})
|
||||
let res = {"embeds": [e]}
|
||||
return res;
|
||||
return page(e);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -61,14 +60,13 @@ module.exports = {
|
|||
pages.push(createUrbanPage(context, res))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform urban dictionary search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform urban dictionary search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -22,8 +22,7 @@ function createWikiHowPage(context, result){
|
|||
if(result.image) e.image = {
|
||||
url: result.image
|
||||
}
|
||||
let res = {"embeds": [e]}
|
||||
return res;
|
||||
return page(e);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -46,20 +45,19 @@ module.exports = {
|
|||
|
||||
let pages = []
|
||||
|
||||
if(search.body.data.length == 0) return editOrReply(context, {embeds:[createEmbed("error", context, `No results found.`)]})
|
||||
if(search.body.data.length == 0) return editOrReply(context, createEmbed("error", context, `No results found.`))
|
||||
|
||||
for(const res of search.body.data){
|
||||
pages.push(createWikiHowPage(context, res))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform wikihow search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform wikihow search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -8,25 +8,6 @@ const superagent = require('superagent')
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createWikiHowPage(context, result){
|
||||
let e = createEmbed("default", context, {
|
||||
author: {
|
||||
name: result.title,
|
||||
url: result.link
|
||||
},
|
||||
description: result.snippet,
|
||||
footer: {
|
||||
iconUrl: STATICS.wikihow,
|
||||
text: `WikiHow • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
if(result.image) e.image = {
|
||||
url: result.image
|
||||
}
|
||||
let res = {"embeds": [e]}
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'wikipedia',
|
||||
label: 'query',
|
||||
|
@ -51,7 +32,7 @@ module.exports = {
|
|||
|
||||
let pages = []
|
||||
|
||||
if(!search.body.pages.length) return editOrReply(context, {embeds:[createEmbed("error", context, `No results found.`)]})
|
||||
if(!search.body.pages.length) return editOrReply(context, createEmbed("error", context, `No results found.`))
|
||||
|
||||
for(const res of Object.values(search.body.pages)){
|
||||
let p = createEmbed("default", context, {
|
||||
|
@ -74,14 +55,13 @@ module.exports = {
|
|||
pages.push(page(p))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform wikipedia search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform wikipedia search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -8,38 +8,34 @@ const { citation } = require('../../../labscore/utils/markdown');
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
function createWolframPage(context, pod, query, sources){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
author: {
|
||||
name: pod.title,
|
||||
url: `https://www.wolframalpha.com/input?i=${encodeURIComponent(query)}`
|
||||
},
|
||||
description: undefined,
|
||||
footer: {
|
||||
iconUrl: STATICS.wolframalpha,
|
||||
text: `Wolfram|Alpha • ${context.application.name}`
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
if(pod.icon) res.embeds[0].author.iconUrl = pod.icon
|
||||
if(pod.value) res.embeds[0].description = pod.value.substr(0,1000)
|
||||
if(pod.value && pod.refs) {
|
||||
for(const r of pod.refs){
|
||||
let src = Object.values(sources).filter((s)=>s.ref == r)[0]
|
||||
if(!src) continue;
|
||||
function createWolframPage(context, pod, query, sources) {
|
||||
let res = page(createEmbed("default", context, {
|
||||
author: {
|
||||
name: pod.title,
|
||||
url: `https://www.wolframalpha.com/input?i=${encodeURIComponent(query)}`
|
||||
},
|
||||
description: undefined,
|
||||
footer: {
|
||||
iconUrl: STATICS.wolframalpha,
|
||||
text: `Wolfram|Alpha • ${context.application.name}`
|
||||
}
|
||||
}))
|
||||
if (pod.icon) res.embeds[0].author.iconUrl = pod.icon
|
||||
if (pod.value) res.embeds[0].description = pod.value.substr(0, 1000)
|
||||
if (pod.value && pod.refs) {
|
||||
for (const r of pod.refs) {
|
||||
let src = Object.values(sources).filter((s) => s.ref == r)[0]
|
||||
if (!src) continue;
|
||||
|
||||
// Only add a direct source if one is available
|
||||
if(src.collections){
|
||||
if (src.collections) {
|
||||
res.embeds[0].description += citation(r, src.url, src.title + ' | ' + src.collections[0].text)
|
||||
continue;
|
||||
}
|
||||
if(src.url) res.embeds[0].description += citation(r, src.url, src.title)
|
||||
if (src.url) res.embeds[0].description += citation(r, src.url, src.title)
|
||||
}
|
||||
}
|
||||
if(pod.image) res.embeds[0].image = { url: pod.image };
|
||||
if (pod.image) res.embeds[0].image = { url: pod.image };
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -57,26 +53,25 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
try{
|
||||
if (!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try {
|
||||
let search = await wolframAlpha(context, args.query)
|
||||
search = search.response
|
||||
|
||||
if(search.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, search.body.message)]})
|
||||
if (search.body.status == 1) return editOrReply(context, createEmbed("warning", context, search.body.message))
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.data){
|
||||
for (const res of search.body.data) {
|
||||
pages.push(createWolframPage(context, res, args.query, search.body.sources))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform Wolfram|Alpha search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform Wolfram|Alpha search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed')
|
||||
const { link, iconPill, timestamp, smallPill } = require('../../../labscore/utils/markdown')
|
||||
const { link, iconPill, smallPill } = require('../../../labscore/utils/markdown')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
||||
|
@ -124,11 +124,11 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
if(!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (query).`))
|
||||
try{
|
||||
if(args.type == 'all') args.type = undefined;
|
||||
else {
|
||||
if(!YOUTUBE_CATEGORIES[args.type.toLowerCase()]) return editOrReply(context, {embeds:[createEmbed("warning", context, `Invalid Parameter (type).`)]})
|
||||
if(!YOUTUBE_CATEGORIES[args.type.toLowerCase()]) return editOrReply(context, createEmbed("warning", context, `Invalid Parameter (type).`))
|
||||
args.type = YOUTUBE_CATEGORIES[args.type.toLowerCase()]
|
||||
}
|
||||
let search = await youtube(context, args.query, args.type)
|
||||
|
@ -139,14 +139,13 @@ module.exports = {
|
|||
pages.push(createYoutubePage(context, res))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform youtube search.`)]})
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform youtube search.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -86,15 +86,14 @@ module.exports = {
|
|||
i++;
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, {embeds:[createEmbed("warning", context, e.response.body.message)]})
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform dictionary lookup.`)]})
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to perform dictionary lookup.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -68,7 +68,7 @@ module.exports = {
|
|||
data = JSON.parse(data.text)
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, "Code execution failed.")] })
|
||||
return editOrReply(context, createEmbed("error", context, "Code execution failed."))
|
||||
}
|
||||
|
||||
const embed = createEmbed("default", context, {})
|
||||
|
|
|
@ -19,16 +19,16 @@ module.exports = {
|
|||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
let image = await getRecentImage(context, 50)
|
||||
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let ocr;
|
||||
try{
|
||||
ocr = await googleVisionOcr(context, image)
|
||||
}catch(e){
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, "Unable to retrieve Google Vision API response.")] })
|
||||
return editOrReply(context, createEmbed("error", context, "Unable to retrieve Google Vision API response."))
|
||||
}
|
||||
|
||||
if(ocr.response.body.status == 1) return editOrReply(context, { embeds: [createEmbed("warning", context, ocr.response.body.text)] })
|
||||
if(ocr.response.body.status == 1) return editOrReply(context, createEmbed("warning", context, ocr.response.body.text))
|
||||
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
thumbnail: {
|
||||
|
|
|
@ -36,16 +36,16 @@ module.exports = {
|
|||
args.from = getCodeFromAny(args.from)
|
||||
|
||||
let image = await getRecentImage(context, 50)
|
||||
if (!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
|
||||
if (!image) return editOrReply(context, createEmbed("warning", context, "No images found."))
|
||||
|
||||
let ocr;
|
||||
try{
|
||||
ocr = await googleVisionOcr(context, image)
|
||||
}catch(e){
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, "Unable to retrieve Google Vision API response.")] })
|
||||
return editOrReply(context, createEmbed("error", context, "Unable to retrieve Google Vision API response."))
|
||||
}
|
||||
|
||||
if(ocr.response.body.status == 1) return editOrReply(context, { embeds: [createEmbed("warning", context, ocr.response.body.text)] })
|
||||
if(ocr.response.body.status == 1) return editOrReply(context, createEmbed("warning", context, ocr.response.body.text))
|
||||
|
||||
try{
|
||||
let translate = await googleTranslate(context, ocr.response.body.text, args.to, args.from)
|
||||
|
@ -65,8 +65,8 @@ module.exports = {
|
|||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to translate text.`)]})
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Something went wrong.`)]})
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, createEmbed("error", context, `Unable to translate text.`))
|
||||
return editOrReply(context, createEmbed("error", context, `Something went wrong.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -84,7 +84,7 @@ module.exports = {
|
|||
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, { embeds: [createEmbed("error", context, `Unable to scan qr codes.`)] })
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to scan qr codes.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -6,7 +6,7 @@ const superagent = require('superagent')
|
|||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
async function processJob(jobUrl){
|
||||
async function processJob(jobUrl) {
|
||||
let job = await superagent.get(jobUrl)
|
||||
.set('User-Agent', 'labscore/1.0')
|
||||
|
||||
|
@ -26,35 +26,33 @@ module.exports = {
|
|||
},
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.ATTACH_FILES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
if(!args.url) return editOrReply(context, { embeds: [createEmbed("warning", context, "No url supplied.")] })
|
||||
if (!args.url) return editOrReply(context, createEmbed("warning", context, "No url supplied."))
|
||||
|
||||
let response = await editOrReply(context, createEmbed("loading", context, `Creating website screenshot...`))
|
||||
|
||||
try{
|
||||
try {
|
||||
const t = Date.now();
|
||||
|
||||
let ss = await screenshot(context, args.url, context.channel.nsfw)
|
||||
|
||||
if(ss.response.body.status && ss.response.body.status !== 3){
|
||||
if(ss.response.body.image) return await editOrReply(context, {
|
||||
embeds: [createEmbed("image", context, {
|
||||
if (ss.response.body.status && ss.response.body.status !== 3) {
|
||||
if (ss.response.body.image) return await editOrReply(context,
|
||||
createEmbed("image", context, {
|
||||
url: ss.response.body.image,
|
||||
time: ((Date.now() - t) / 1000).toFixed(2)
|
||||
})]
|
||||
})
|
||||
})
|
||||
)
|
||||
return await editOrReply(context, createEmbed("error", context, "Unable to create screenshot."))
|
||||
}
|
||||
|
||||
let job = await processJob(ss.response.body.job)
|
||||
|
||||
if(job.status){
|
||||
if(!job.image) job = await processJob(ss.response.body.job)
|
||||
if(job.image) return await editOrReply(context, {
|
||||
embeds: [createEmbed("image", context, {
|
||||
url: job.image,
|
||||
time: ((Date.now() - t) / 1000).toFixed(2)
|
||||
})]
|
||||
})
|
||||
if (job.status) {
|
||||
if (!job.image) job = await processJob(ss.response.body.job)
|
||||
if (job.image) return await editOrReply(context, createEmbed("image", context, {
|
||||
url: job.image,
|
||||
time: ((Date.now() - t) / 1000).toFixed(2)
|
||||
}))
|
||||
return await editOrReply(context, createEmbed("error", context, "Unable to create screenshot."))
|
||||
}
|
||||
|
||||
|
@ -65,7 +63,7 @@ module.exports = {
|
|||
})],
|
||||
files: [{ filename: "screenshot.png", value: job }]
|
||||
})
|
||||
} catch(e){
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return await editOrReply(context, createEmbed("image", context, {
|
||||
url: "https://bignutty.gitlab.io/webstorage4/v2/assets/screenshot/screenshot_error.png"
|
||||
|
|
|
@ -65,8 +65,8 @@ module.exports = {
|
|||
}))
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to translate text.`)]})
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Something went wrong.`)]})
|
||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, createEmbed("error", context, `Unable to translate text.`))
|
||||
return editOrReply(context, createEmbed("error", context, `Something went wrong.`))
|
||||
}
|
||||
}
|
||||
};
|
|
@ -2,7 +2,7 @@ const { createEmbed } = require('../../../labscore/utils/embed')
|
|||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const { darksky } = require('../../../labscore/api');
|
||||
const { pill, iconPill, smallIconPill, smallPill, icon, weatherIcon, timestamp } = require('../../../labscore/utils/markdown');
|
||||
const { pill, iconPill, smallPill, weatherIcon, timestamp } = require('../../../labscore/utils/markdown');
|
||||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
const { STATICS } = require('../../../labscore/utils/statics');
|
||||
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (location).`)]})
|
||||
if(!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (location).`))
|
||||
try{
|
||||
let data = await darksky(context, args.query)
|
||||
|
||||
|
@ -60,10 +60,10 @@ module.exports = {
|
|||
if(data.result.current.icon) e.thumbnail = { url: data.result.current.icon }
|
||||
if(data.result.current.image) e.image = { url: data.result.current.image }
|
||||
|
||||
return editOrReply(context, {embeds: [e]})
|
||||
return editOrReply(context, e)
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("warning", context, `No weather data available for given location.`)]})
|
||||
return editOrReply(context, createEmbed("warning", context, `No weather data available for given location.`))
|
||||
}
|
||||
},
|
||||
};
|
|
@ -118,15 +118,15 @@ const Statics = Object.freeze({
|
|||
icons: {
|
||||
adult: {
|
||||
file: "icons/core/ico_notice_nsfw.png",
|
||||
revision: 0
|
||||
revision: 1
|
||||
},
|
||||
error: {
|
||||
file: "icons/core/ico_notice_error.png",
|
||||
revision: 0
|
||||
revision: 1
|
||||
},
|
||||
loading: {
|
||||
file: "icons/core/ico_notice_loading.gif",
|
||||
revision: 0
|
||||
revision: 1
|
||||
},
|
||||
ai: {
|
||||
file: "icons/core/ico_notice_ai_spark.gif",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue