mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 21:53:07 -04:00
dictionary
This commit is contained in:
parent
c051946d89
commit
8e489318e5
4 changed files with 74 additions and 1 deletions
|
@ -62,7 +62,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform urban dictionary search.`)]})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
66
commands/message/utils/define.js
Normal file
66
commands/message/utils/define.js
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { link } = require('../../../labscore/utils/markdown')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
const { dictionary } = require('../../../labscore/api');
|
||||||
|
|
||||||
|
function createDictionaryPage(context, result){
|
||||||
|
let phon = ''
|
||||||
|
if(result.phonetic) phon = `\n*${result.phonetic}*`
|
||||||
|
|
||||||
|
let e = createEmbed("default", context, {
|
||||||
|
description: `**${link(result.source, result.word)}**${phon}`,
|
||||||
|
fields: [],
|
||||||
|
thumbnail: {
|
||||||
|
url: `https://cdn.discordapp.com/emojis/925891616986791936.png?size=4096`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
for(const d of result.definitions){
|
||||||
|
let v = d.definition
|
||||||
|
if(d.example) v = v + `\n\n**Example**\n${d.example}`
|
||||||
|
if(d.synonyms.length >= 1) v = v + `\n\n**Synonyms**\n*${d.synonyms.join(', ')}*`
|
||||||
|
e.fields.push({
|
||||||
|
name: d.type,
|
||||||
|
value: v,
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = {"embeds": [e]}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'define',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['dictionary'],
|
||||||
|
metadata: {
|
||||||
|
description: 'dictionary lookup',
|
||||||
|
examples: ['dictionary Flask'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'define <query>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
try{
|
||||||
|
let search = await dictionary(context, args.query)
|
||||||
|
search = search.response
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
for(const res of search.body.results){
|
||||||
|
pages.push(createDictionaryPage(context, res))
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const paging = await paginator.createPaginator({
|
||||||
|
context,
|
||||||
|
pages
|
||||||
|
});
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform dictionary lookup.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -28,6 +28,7 @@ const Api = Object.freeze({
|
||||||
SEARCH_AUDIO: '/search/audio',
|
SEARCH_AUDIO: '/search/audio',
|
||||||
SEARCH_BING: '/search/bing',
|
SEARCH_BING: '/search/bing',
|
||||||
SEARCH_BING_IMAGES: '/search/bing-images',
|
SEARCH_BING_IMAGES: '/search/bing-images',
|
||||||
|
SEARCH_DICTIONARY: '/search/dictionary',
|
||||||
SEARCH_GOOGLE: '/search/google',
|
SEARCH_GOOGLE: '/search/google',
|
||||||
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
||||||
SEARCH_LYRICS: '/search/lyrics',
|
SEARCH_LYRICS: '/search/lyrics',
|
||||||
|
|
|
@ -135,6 +135,12 @@ module.exports.bingImages = async function(context, query){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.dictionary = async function(context, query){
|
||||||
|
return await request(Api.SEARCH_DICTIONARY, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.tineye = async function(context, url){
|
module.exports.tineye = async function(context, url){
|
||||||
return await request(Api.SEARCH_TINEYE, "GET", {}, {
|
return await request(Api.SEARCH_TINEYE, "GET", {}, {
|
||||||
url: url
|
url: url
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue