mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 14:43:05 -04:00
expose urbandictionary via slash
This commit is contained in:
parent
e928d013c9
commit
4c10686064
1 changed files with 89 additions and 0 deletions
89
commands/interaction/slash/search/urbandictionary.js
Normal file
89
commands/interaction/slash/search/urbandictionary.js
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
const { urbandictionary } = require('#api');
|
||||||
|
const { paginator } = require('#client');
|
||||||
|
|
||||||
|
const { createEmbed, formatPaginationEmbeds, page } = require('#utils/embed');
|
||||||
|
const { acknowledge } = require('#utils/interactions');
|
||||||
|
const { link, iconPill } = require('#utils/markdown')
|
||||||
|
const { editOrReply } = require('#utils/message')
|
||||||
|
const { STATICS } = require('#utils/statics')
|
||||||
|
|
||||||
|
// TODO: Turn this into a general purpose permissions constant
|
||||||
|
const { Permissions, ApplicationCommandOptionTypes } = require("detritus-client/lib/constants");
|
||||||
|
|
||||||
|
function createUrbanPage(context, result){
|
||||||
|
let e = createEmbed("default", context, {
|
||||||
|
description: `**${link(result.link, result.title)}**`,
|
||||||
|
fields: [],
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.urbandictionary,
|
||||||
|
text: `UrbanDictionary • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if(result.description) e.fields.push({
|
||||||
|
name: "Description",
|
||||||
|
value: result.description.substr(0, 1023),
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
e.fields.push({
|
||||||
|
name: "Stats",
|
||||||
|
value: `${iconPill("upvote", result.score.likes)} ${iconPill("downvote", result.score.dislikes)}\n**Author:** ${link(`https://www.urbandictionary.com/author.php?author=${encodeURIComponent(result.author)}`, result.author)}`,
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
if(result.example) e.fields.push({
|
||||||
|
name: "Example",
|
||||||
|
value: result.example.substr(0, 1023),
|
||||||
|
inline: false
|
||||||
|
})
|
||||||
|
return page(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'urbandictionary',
|
||||||
|
description: 'Define a word on urban dictionary.',
|
||||||
|
contexts: [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
integrationTypes: [
|
||||||
|
1
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'term',
|
||||||
|
description: 'Term to look up.',
|
||||||
|
type: ApplicationCommandOptionTypes.TEXT,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'incognito',
|
||||||
|
description: 'Makes the response only visible to you.',
|
||||||
|
type: ApplicationCommandOptionTypes.BOOLEAN,
|
||||||
|
required: false,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
run: async (context, args) => {
|
||||||
|
await acknowledge(context, args.incognito);
|
||||||
|
|
||||||
|
try{
|
||||||
|
let search = await urbandictionary(context, args.term)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
if(search.body.status == 1) return editOrReply(context, createEmbed("warning", context, search.body.message))
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(createUrbanPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
await paginator.createPaginator({
|
||||||
|
context,
|
||||||
|
pages: formatPaginationEmbeds(pages)
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, createEmbed("error", context, `Unable to perform urban dictionary search.`))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue