diff --git a/commands/message/search/youtube.js b/commands/message/search/youtube.js index 0857b0c..a99c652 100644 --- a/commands/message/search/youtube.js +++ b/commands/message/search/youtube.js @@ -1,5 +1,5 @@ const { createEmbed, formatPaginationEmbeds, page } = require('../../../labscore/utils/embed') -const { link, iconPill, timestamp } = require('../../../labscore/utils/markdown') +const { link, iconPill, timestamp, smallPill } = require('../../../labscore/utils/markdown') const { editOrReply } = require('../../../labscore/utils/message') const { STATICS } = require('../../../labscore/utils/statics') @@ -7,6 +7,7 @@ const { paginator } = require('../../../labscore/client'); const { youtube } = require('../../../labscore/api'); const { Permissions } = require("detritus-client/lib/constants"); +const { YOUTUBE_CATEGORIES } = require('../../../labscore/constants'); // https://www.html-code-generator.com/javascript/shorten-long-numbers const intToString = num => { @@ -111,18 +112,26 @@ module.exports = { label: 'query', aliases: ['yt'], metadata: { - description: 'Returns search results from YouTube.', - description_short: 'Search YouTube videos, channels and playlists', + description: `Search YouTube videos, channels and playlists.\n\nAvailable categories are ${Object.keys(YOUTUBE_CATEGORIES).map((c)=>smallPill(c)).join(' ')}\n\nNote that category search is limited to videos.`, + description_short: `Search YouTube videos, channels and playlists.`, examples: ['youtube otter live cam'], category: 'search', - usage: 'youtube ' + usage: 'youtube [-type ]' }, + args: [ + {name: 'type', default: 'all', type: 'string', help: `Video Category`} + ], permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY], run: async (context, args) => { context.triggerTyping(); if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]}) try{ - let search = await youtube(context, args.query) + if(args.type == 'all') args.type = undefined; + else { + if(!YOUTUBE_CATEGORIES[args.type.toLowerCase()]) return editOrReply(context, {embeds:[createEmbed("warning", context, `Invalid Parameter (type).`)]}) + args.type = YOUTUBE_CATEGORIES[args.type.toLowerCase()] + } + let search = await youtube(context, args.query, args.type) search = search.response let pages = [] diff --git a/labscore/api/index.js b/labscore/api/index.js index 1d4db74..f537cfc 100644 --- a/labscore/api/index.js +++ b/labscore/api/index.js @@ -188,9 +188,10 @@ module.exports.wolframAlpha = async function(context, query){ }) } -module.exports.youtube = async function(context, query){ +module.exports.youtube = async function(context, query, category){ return await request(Api.SEARCH_YOUTUBE, "GET", {}, { - q: query + q: query, + category }) } diff --git a/labscore/constants.js b/labscore/constants.js index 88dcaf8..b1a19f6 100644 --- a/labscore/constants.js +++ b/labscore/constants.js @@ -724,7 +724,6 @@ module.exports.YOUTUBE_CATEGORIES = { "travel": "19", "gaming": "20", "comedy": "34", - "entertainment": "24", "news": "25", "howto": "26", "education": "27",