mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 21:53:07 -04:00
[cmd] urbandictionary
This commit is contained in:
parent
1aba83b2ed
commit
07bb620cd1
4 changed files with 124 additions and 1 deletions
67
commands/message/search/urbandictionary.js
Normal file
67
commands/message/search/urbandictionary.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { link, icon, highlight } = require('../../../labscore/utils/markdown')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
const { urbandictionary } = require('../../../labscore/api');
|
||||||
|
|
||||||
|
function createUrbanPage(context, result){
|
||||||
|
let e = createEmbed("default", context, {
|
||||||
|
description: `**${link(result.link, result.title)}**`,
|
||||||
|
fields: []
|
||||||
|
})
|
||||||
|
if(result.description) e.fields.push({
|
||||||
|
name: "Description",
|
||||||
|
value: result.description.substr(0, 1023),
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
e.fields.push({
|
||||||
|
name: "Stats",
|
||||||
|
value: `${icon("upvote")}${highlight(result.score.likes)} ${icon("downvote")}${highlight(result.score.dislikes)}\n**Author:** ${link(`https://www.urbandictionary.com/author.php?author=${result.author}`, result.author)}`,
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
if(result.example) e.fields.push({
|
||||||
|
name: "Example",
|
||||||
|
value: result.example.substr(0, 1023),
|
||||||
|
inline: false
|
||||||
|
})
|
||||||
|
console.log(JSON.stringify(e))
|
||||||
|
let res = {"embeds": [e]}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'urbandictionary',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['urban', 'ud'],
|
||||||
|
metadata: {
|
||||||
|
description: 'urban dictionary definitions (might be nsfw)',
|
||||||
|
examples: ['ud Flask'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'urbandictionary <query>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||||
|
try{
|
||||||
|
let search = await urbandictionary(context, args.query)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(createUrbanPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const paging = await paginator.createPaginator({
|
||||||
|
context,
|
||||||
|
pages
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
console.log(JSON.stringify(e.errors, null, 2))
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -32,6 +32,7 @@ const Api = Object.freeze({
|
||||||
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
||||||
SEARCH_LYRICS: '/search/lyrics',
|
SEARCH_LYRICS: '/search/lyrics',
|
||||||
SEARCH_RULE34: '/search/booru',
|
SEARCH_RULE34: '/search/booru',
|
||||||
|
SEARCH_URBANDICTIONARY: '/search/urbandictionary',
|
||||||
SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha',
|
SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha',
|
||||||
SEARCH_YOUTUBE: '/search/youtube',
|
SEARCH_YOUTUBE: '/search/youtube',
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,12 @@ module.exports.bingImages = async function(context, query){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.urbandictionary = async function(context, query){
|
||||||
|
return await request(Api.SEARCH_URBANDICTIONARY, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.wolframAlpha = async function(context, query){
|
module.exports.wolframAlpha = async function(context, query){
|
||||||
return await request(Api.SEARCH_WOLFRAM_ALPHA, "GET", {}, {
|
return await request(Api.SEARCH_WOLFRAM_ALPHA, "GET", {}, {
|
||||||
q: query
|
q: query
|
||||||
|
|
|
@ -50,7 +50,9 @@ module.exports.ICONS = Object.freeze({
|
||||||
"timer": "<:ico_timer:915271575274680350>",
|
"timer": "<:ico_timer:915271575274680350>",
|
||||||
"util": "<:ico_util:903259395381690379>",
|
"util": "<:ico_util:903259395381690379>",
|
||||||
"locale": "<:ico_locale:925891616986791936>",
|
"locale": "<:ico_locale:925891616986791936>",
|
||||||
"question": "<:ico_question:949420315677691934>"
|
"question": "<:ico_question:949420315677691934>",
|
||||||
|
"upvote": "<:ico_upvote:980238682353205259>",
|
||||||
|
"downvote": "<:ico_downvote:980238681971494963>"
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports.WEB_ASSETS = Object.freeze({
|
module.exports.WEB_ASSETS = Object.freeze({
|
||||||
|
@ -210,4 +212,51 @@ module.exports.TIKTOK_VOICES = [
|
||||||
"name": "Korean - Female",
|
"name": "Korean - Female",
|
||||||
"value": "kr_003"
|
"value": "kr_003"
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
module.exports.IMTRANSLATOR_VOICES = [
|
||||||
|
{
|
||||||
|
"name": "English (Male)",
|
||||||
|
"value": "en"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "English (Female)",
|
||||||
|
"value": "enf"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Chinese (Female)",
|
||||||
|
"value": "zh"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Spanish (Carlos)",
|
||||||
|
"value": "es"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Russian (Female)",
|
||||||
|
"value": "ru"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "French (Female)",
|
||||||
|
"value": "fr"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "German (Male)",
|
||||||
|
"value": "de"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Italian (Male)",
|
||||||
|
"value": "it"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Portugese (Female)",
|
||||||
|
"value": "pt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Japanese (Female)",
|
||||||
|
"value": "ja"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Korean (Female)",
|
||||||
|
"value": "ko"
|
||||||
|
}
|
||||||
]
|
]
|
Loading…
Add table
Add a link
Reference in a new issue