mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 21:53:07 -04:00
quora search
This commit is contained in:
parent
03f88d10cc
commit
c1c63e3fc2
4 changed files with 85 additions and 0 deletions
73
commands/message/search/quora.js
Normal file
73
commands/message/search/quora.js
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||||
|
const { link, pill } = require('../../../labscore/utils/markdown')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
const { STATICS } = require('../../../labscore/utils/statics')
|
||||||
|
|
||||||
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
const { bing, quora } = require('../../../labscore/api');
|
||||||
|
|
||||||
|
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, 4).join(' ')}\n\n${answer.content.substr(0,1000)}`,
|
||||||
|
footer: {
|
||||||
|
iconUrl: STATICS.quora,
|
||||||
|
text: `Quora • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
if(answer.author){
|
||||||
|
res.embeds[0].author = {
|
||||||
|
name: answer.author.name.substr(0,1000),
|
||||||
|
iconUrl: answer.author.icon,
|
||||||
|
url: answer.author.url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'quora',
|
||||||
|
label: 'query',
|
||||||
|
aliases: ['q'],
|
||||||
|
metadata: {
|
||||||
|
description: 'Searches for questions on Quora.',
|
||||||
|
description_short: 'Quora Search',
|
||||||
|
examples: ['quora How does Quora work?'],
|
||||||
|
category: 'search',
|
||||||
|
usage: 'quora <query>'
|
||||||
|
},
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.query) return editOrReply(context, {embeds:[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)]})
|
||||||
|
|
||||||
|
let pages = []
|
||||||
|
// Create the initial page
|
||||||
|
|
||||||
|
for(const answer of search.answers){
|
||||||
|
pages.push(createQuoraAnswerPage(context, search.question, answer))
|
||||||
|
}
|
||||||
|
|
||||||
|
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 quora search.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -31,6 +31,7 @@ const Api = Object.freeze({
|
||||||
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',
|
||||||
|
SEARCH_QUORA: '/search/quora',
|
||||||
SEARCH_REDDIT: '/search/reddit',
|
SEARCH_REDDIT: '/search/reddit',
|
||||||
SEARCH_REVERSE_IMAGE: '/search/reverse-image',
|
SEARCH_REVERSE_IMAGE: '/search/reverse-image',
|
||||||
SEARCH_RULE34: '/search/booru',
|
SEARCH_RULE34: '/search/booru',
|
||||||
|
|
|
@ -118,6 +118,12 @@ module.exports.googleImages = async function(context, query, nsfw){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.quora = async function(context, query){
|
||||||
|
return await request(Api.SEARCH_QUORA, "GET", {}, {
|
||||||
|
q: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.reddit = async function(context, query, nsfw = false){
|
module.exports.reddit = async function(context, query, nsfw = false){
|
||||||
return await request(Api.SEARCH_REDDIT, "GET", {}, {
|
return await request(Api.SEARCH_REDDIT, "GET", {}, {
|
||||||
q: query,
|
q: query,
|
||||||
|
|
|
@ -36,6 +36,10 @@ const Statics = Object.freeze({
|
||||||
file: "brands/photofunia.png",
|
file: "brands/photofunia.png",
|
||||||
revision: 1
|
revision: 1
|
||||||
},
|
},
|
||||||
|
quora: {
|
||||||
|
file: "brands/quora.png",
|
||||||
|
revision: 1
|
||||||
|
},
|
||||||
reddit: {
|
reddit: {
|
||||||
file: "brands/reddit.png",
|
file: "brands/reddit.png",
|
||||||
revision: 0
|
revision: 0
|
||||||
|
@ -94,6 +98,7 @@ module.exports.STATICS = Object.freeze({
|
||||||
makesweet: staticAsset(Statics.brands.makesweet),
|
makesweet: staticAsset(Statics.brands.makesweet),
|
||||||
openweathermap: staticAsset(Statics.brands.openweathermap),
|
openweathermap: staticAsset(Statics.brands.openweathermap),
|
||||||
photofunia: staticAsset(Statics.brands.photofunia),
|
photofunia: staticAsset(Statics.brands.photofunia),
|
||||||
|
quora: staticAsset(Statics.brands.quora),
|
||||||
reddit: staticAsset(Statics.brands.reddit),
|
reddit: staticAsset(Statics.brands.reddit),
|
||||||
tineye: staticAsset(Statics.brands.tineye),
|
tineye: staticAsset(Statics.brands.tineye),
|
||||||
urbandictionary: staticAsset(Statics.brands.urbandictionary),
|
urbandictionary: staticAsset(Statics.brands.urbandictionary),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue