mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 06:33:05 -04:00
dictionary v2
This commit is contained in:
parent
c2c8241080
commit
6a3fb1dde3
4 changed files with 40 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
||||||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
const { link, pill, iconPill } = require('../../../labscore/utils/markdown')
|
const { link, pill, iconPill, smallPill, citation, icon } = require('../../../labscore/utils/markdown')
|
||||||
const { editOrReply } = require('../../../labscore/utils/message')
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
|
||||||
const { paginator } = require('../../../labscore/client');
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
@ -7,29 +7,39 @@ const { dictionary } = require('../../../labscore/api');
|
||||||
|
|
||||||
const { Permissions } = require("detritus-client/lib/constants");
|
const { Permissions } = require("detritus-client/lib/constants");
|
||||||
|
|
||||||
function createDictionaryPage(context, result){
|
function createDictionaryPage(context, result, word){
|
||||||
let phon = ''
|
let phon = ''
|
||||||
if(result.phonetic) phon = `\n*${result.phonetic}*`
|
if(result.phonetic) phon = `\n*${result.phonetic}*`
|
||||||
|
|
||||||
let e = createEmbed("default", context, {
|
let e = createEmbed("default", context, {
|
||||||
description: `**${link(result.source, result.word)}**${phon}`,
|
description: `${icon("book")} **${link(`https://en.wiktionary.org/wiki/${encodeURIComponent(word.word)}`, word.word, "Definition on Wiktionary")}**`,
|
||||||
fields: [],
|
fields: []
|
||||||
thumbnail: {
|
|
||||||
url: `https://cdn.discordapp.com/emojis/925891616986791936.png?size=4096`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for(const d of result.definitions){
|
if(word.phonetics) e.description += smallPill(word.phonetics)
|
||||||
let v = d.definition
|
|
||||||
if(d.example) v = v + `\n\n${iconPill("pencil", "Example")}\n> ${d.example}`
|
let def = word.definitions[result]
|
||||||
if(d.synonyms.length >= 1) v = v + `\n\n${iconPill("message", "Synonyms")}\n> *${d.synonyms.join(', ')}*`
|
|
||||||
e.fields.push({
|
let ref = 1;
|
||||||
name: d.type,
|
let defDesc = []
|
||||||
value: v,
|
|
||||||
inline: true
|
for(const d of def){
|
||||||
})
|
let defItms = [`**${ref}.** `]
|
||||||
|
defItms.push(d.definition, citation(ref, d.src))
|
||||||
|
if(d.examples) defItms.push(`\n ${icon("message")} *${d.examples.join(`*\n ${icon("message")} *`)}*`)
|
||||||
|
// Synonyms are limited to 5 to prevent overflow
|
||||||
|
if(d.synonyms) defItms.push(`\n ${iconPill("book", "Synonyms")} ${d.synonyms.splice(0, 5).map((s)=>smallPill(s)).join(' ')}`)
|
||||||
|
|
||||||
|
ref++;
|
||||||
|
if([...defDesc, defItms.join(' ')].join('\n\n').length >= 1024) continue;
|
||||||
|
defDesc.push(defItms.join(''))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.fields.push({
|
||||||
|
name: result,
|
||||||
|
value: defDesc.join('\n\n')
|
||||||
|
})
|
||||||
|
|
||||||
let res = {"embeds": [e]}
|
let res = {"embeds": [e]}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +52,7 @@ module.exports = {
|
||||||
description: 'Returns dictionary definitions for words.',
|
description: 'Returns dictionary definitions for words.',
|
||||||
description_short: 'Dictionary word definitions.',
|
description_short: 'Dictionary word definitions.',
|
||||||
examples: ['dictionary Walking'],
|
examples: ['dictionary Walking'],
|
||||||
category: 'search',
|
category: 'utils',
|
||||||
usage: 'define <query>'
|
usage: 'define <query>'
|
||||||
},
|
},
|
||||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS],
|
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS],
|
||||||
|
@ -55,8 +65,8 @@ module.exports = {
|
||||||
if(search.body.status == 1) return editOrReply(context, createEmbed("warning", context, search.body.message))
|
if(search.body.status == 1) return editOrReply(context, createEmbed("warning", context, search.body.message))
|
||||||
|
|
||||||
let pages = []
|
let pages = []
|
||||||
for(const res of search.body.results){
|
for(const res of Object.keys(search.body.result.definitions)){
|
||||||
pages.push(createDictionaryPage(context, res))
|
pages.push(createDictionaryPage(context, res, search.body.result))
|
||||||
}
|
}
|
||||||
|
|
||||||
pages = formatPaginationEmbeds(pages)
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
@ -66,6 +76,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(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.`)]})
|
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform dictionary lookup.`)]})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,7 +28,6 @@ const Api = Object.freeze({
|
||||||
|
|
||||||
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',
|
||||||
|
@ -50,6 +49,7 @@ const Api = Object.freeze({
|
||||||
TTS_SAPI4: '/tts/sapi4',
|
TTS_SAPI4: '/tts/sapi4',
|
||||||
TTS_TIKTOK: '/tts/tiktok',
|
TTS_TIKTOK: '/tts/tiktok',
|
||||||
|
|
||||||
|
UTILS_DICTIONARY: '/utils/dictionary',
|
||||||
UTILS_EMOJIPEDIA: '/utils/emojipedia',
|
UTILS_EMOJIPEDIA: '/utils/emojipedia',
|
||||||
UTILS_GARFIELD: '/utils/garfield',
|
UTILS_GARFIELD: '/utils/garfield',
|
||||||
UTILS_INFERKIT: '/utils/inferkit',
|
UTILS_INFERKIT: '/utils/inferkit',
|
||||||
|
|
|
@ -158,12 +158,6 @@ module.exports.bingImages = async function(context, query, nsfw){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.dictionary = async function(context, query){
|
|
||||||
return await request(Api.SEARCH_DICTIONARY, "GET", {}, {
|
|
||||||
q: query
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.reverseImageSearch = async function(context, url){
|
module.exports.reverseImageSearch = async function(context, url){
|
||||||
return await request(Api.SEARCH_REVERSE_IMAGE, "GET", {}, {
|
return await request(Api.SEARCH_REVERSE_IMAGE, "GET", {}, {
|
||||||
url: url
|
url: url
|
||||||
|
@ -290,6 +284,12 @@ module.exports.tiktok = async function(context, text, voice){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.dictionary = async function(context, query){
|
||||||
|
return await request(Api.UTILS_DICTIONARY, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.emojipedia = async function(context, emoji){
|
module.exports.emojipedia = async function(context, emoji){
|
||||||
return await request(Api.UTILS_EMOJIPEDIA, "GET", {}, {
|
return await request(Api.UTILS_EMOJIPEDIA, "GET", {}, {
|
||||||
emoji: emoji
|
emoji: emoji
|
||||||
|
|
|
@ -94,7 +94,9 @@ module.exports.ICONS = Object.freeze({
|
||||||
"arrow_left": "<:ico_arrowleft:1086628775644647464>",
|
"arrow_left": "<:ico_arrowleft:1086628775644647464>",
|
||||||
"arrow_right": "<:ico_arrowright:1086628777880191016>",
|
"arrow_right": "<:ico_arrowright:1086628777880191016>",
|
||||||
"sticker": "<:ico_sticker:1096937131793985546> ",
|
"sticker": "<:ico_sticker:1096937131793985546> ",
|
||||||
"emoji": "<:ico_emoji:1096936794731315251>"
|
"emoji": "<:ico_emoji:1096936794731315251>",
|
||||||
|
"empty": "<:e:749601069298090034>",
|
||||||
|
"book": "<:ico_book:1127622851265048576>"
|
||||||
})
|
})
|
||||||
|
|
||||||
const GUILD_FEATURE_ICONS = Object.freeze({
|
const GUILD_FEATURE_ICONS = Object.freeze({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue