From 47e16b1fcbe55f988eef7e1ea6d1e25f14b8c0b4 Mon Sep 17 00:00:00 2001 From: void Date: Thu, 30 Jan 2020 22:15:05 +0100 Subject: [PATCH] preparing commands structure for sonarr / radarr implementation --- src/bots/DiscordBot.js | 10 +- src/bots/commands/ombi/movie.js | 140 ---------- src/bots/commands/ombi/tv.js | 142 ----------- src/bots/commands/searchrequest/movie.js | 35 +++ .../commands/searchrequest/services/ombi.js | 241 ++++++++++++++++++ .../commands/searchrequest/services/radarr.js | 1 + .../commands/searchrequest/services/sonarr.js | 1 + src/bots/commands/searchrequest/tv.js | 35 +++ 8 files changed, 316 insertions(+), 289 deletions(-) delete mode 100644 src/bots/commands/ombi/movie.js delete mode 100644 src/bots/commands/ombi/tv.js create mode 100644 src/bots/commands/searchrequest/movie.js create mode 100644 src/bots/commands/searchrequest/services/ombi.js create mode 100644 src/bots/commands/searchrequest/services/radarr.js create mode 100644 src/bots/commands/searchrequest/services/sonarr.js create mode 100644 src/bots/commands/searchrequest/tv.js diff --git a/src/bots/DiscordBot.js b/src/bots/DiscordBot.js index 9210821..934163f 100644 --- a/src/bots/DiscordBot.js +++ b/src/bots/DiscordBot.js @@ -39,9 +39,7 @@ module.exports = class BotClient extends Commando.Client { this.registry .registerDefaultGroups() .registerGroups([ - ['ombi', 'Ombi'], - ['sonarr', 'Sonarr'], - ['radarr', 'Radarr'], + ['searchrequest', 'Search & Request'], ['tautulli', 'Tautulli'] ]) .registerDefaultTypes() @@ -59,15 +57,13 @@ module.exports = class BotClient extends Commando.Client { if(checkGroups.indexOf(group.name.toLowerCase()) > -1) { const groupConfig = this.webDatabase.webConfig[group.name.toLowerCase()]; if (groupConfig.host === "" || groupConfig.apikey === "") - group.commands.forEach((command) => { - this.registry.unregisterCommand(command); - }); + group.commands.forEach((command) => this.registry.unregisterCommand(command)); } }); this.dispatcher.addInhibitor((message) => { // Older versions of the DB may not have channelName defined - const bot = this.webDatabase.getConfig()['bot']; + const bot = this.webDatabase.webConfig['bot']; if (!bot.channelname || bot.channelname.length == 0) { return false; } diff --git a/src/bots/commands/ombi/movie.js b/src/bots/commands/ombi/movie.js deleted file mode 100644 index fba8dcf..0000000 --- a/src/bots/commands/ombi/movie.js +++ /dev/null @@ -1,140 +0,0 @@ -const Discord = require('discord.js'); -const commando = require('discord.js-commando'); -const path = require('path'); - -module.exports = class searchMovieCommand extends commando.Command { - constructor (client) { - super(client, { - 'name': 'movie', - 'memberName': 'movie', - 'group': 'ombi', - 'description': 'Search and Request Movies in Ombi', - 'examples': ['movie The Matrix', 'movie tmdb:603'], - 'guildOnly': true, - 'argsPromptLimit': 0, - 'args': [ - { - 'key': 'name', - 'prompt': 'Name of the Movie', - 'type': 'string' - } - ] - }); - } - - outputMovie(msg, movie) { - let movieEmbed = new Discord.MessageEmbed() - .setTitle(`${movie.title} ${(movie.releaseDate) ? `(${movie.releaseDate.split('T')[0].substring(0,4)})` : ''}`) - .setDescription(movie.overview.substr(0, 255) + '(...)') - .setFooter(msg.author.username, `https://cdn.discordapp.com/avatars/${msg.author.id}/${msg.author.avatar}.png`) - .setTimestamp(new Date()) - .setImage('https://image.tmdb.org/t/p/w500' + movie.posterPath) - .setURL('https://www.themoviedb.org/movie/' + movie.theMovieDbId) - .attachFiles(path.join(__dirname, '..', '..', '..', 'resources', 'tmdb.png')) - .setThumbnail('attachment://tmdb.png'); - - if (movie.available) movieEmbed.addField('__Available__', '✅', true); - if (movie.quality) movieEmbed.addField('__Quality__', `${movie.qualityp}p` , true); - if (movie.requested) movieEmbed.addField('__Requested__', '✅', true); - if (movie.approved) movieEmbed.addField('__Approved__', '✅', true); - if (movie.plexUrl) movieEmbed.addField('__Plex__', `[Watch now](${movie.plexUrl})`, true); - if (movie.embyUrl) movieEmbed.addField('__Emby__', `[Watch now](${movie.embyUrl})`, true); - - return msg.embed(movieEmbed); - } - - getTMDbID(msg, name) { - return new Promise((resolve) => { - this.client.API.ombi.searchMovie(name).then((data) => { - if (data.length > 1) { - let fieldContent = ''; - data.forEach((movie, i) => { - fieldContent += `${i+1}) ${movie.title} ` - if (movie.releaseDate) fieldContent += `(${movie.releaseDate.substring(0,4)}) ` - fieldContent += `[[TheMovieDb](https://www.themoviedb.org/movie/${movie.theMovieDbId})]\n` - }) - - let showEmbed = new Discord.MessageEmbed(); - showEmbed.setTitle('Ombi Movie Search') - .setDescription('Please select one of the search results. To abort answer **cancel**') - .addField('__Search Results__', fieldContent); - - const aMsg = msg.embed(showEmbed); - msg.channel.awaitMessages(m => (!isNaN(parseInt(m.content)) || m.content.startsWith('cancel')) && m.author.id == msg.author.id, { max: 1, time: 120000, errors: ['time'] }) - .then((collected) => { - let message = collected.first().content; - let selection = parseInt(message); - - aMsg.then((m) => m.delete()); - if (collected.first().deletable) collected.first().delete(); - if (message.startsWith('cancel')) { - msg.reply('Cancelled command.'); - } else if (selection > 0 && selection <= data.length) { - resolve(data[selection - 1].id); - } else { - msg.reply('Please enter a valid selection!'); - } - }).catch(() => { - msg.reply('Cancelled command.'); - }); - } else if (!data.length) { - msg.reply('Couldn\'t find the movie you were looking for. Is the name correct?'); - } else { - resolve(data[0].id); - } - }).catch(() => { - msg.reply('Something went wrong! Couldn\'t find any movie.'); - }); - }); - } - - requestMovie(msg, movieMsg, movie) { - const ombi = this.client.webDatabase.getConfig()['ombi']; - if ((!ombi.requestmovie || msg.member.roles.some(role => role.name.toLowerCase() === ombi.requestmovie.toLowerCase())) && (!movie.available && !movie.requested && !movie.approved)) { - msg.reply('If you want to request this movie please click on the ⬇ reaction.'); - movieMsg.react('⬇'); - - movieMsg.awaitReactions((reaction, user) => reaction.emoji.name === '⬇' && user.id === msg.author.id, { max: 1, time: 120000 }).then(collected => { - if (collected.first()) { - this.client.API.ombi.requestMovie(movie.theMovieDbId, `${encodeURI(msg.author.username.toLowerCase())}#${msg.author.discriminator}`).then(() => { - return msg.reply(`Requested ${movie.title} in Ombi.`); - }).catch(() => { - return msg.reply('Something went wrong! Couldn\'t request movie.'); - }); - } - }).catch(() => { - return msg.reply('Something went wrong! Couldn\'t register your emoji.'); - }); - } - return movieMsg; - } - - async run (msg, args) { - this.client.deleteCommandMessages(msg); - if (!args.name) { - return msg.reply('Please enter a valid movie name.'); - } - - let tmdbid = undefined; - if (args.name.startsWith("tmdb:")) { - const matches = /^tmdb:(\d+)$/.exec(args.name); - if (matches) { - tmdbid = matches[1]; - } else { - return msg.reply('Please enter a valid TMDb ID!'); - } - } else { - tmdbid = await this.getTMDbID(msg, args.name); - } - - if (tmdbid) { - this.client.API.ombi.getMovieInformation(tmdbid).then((data) => { - this.outputMovie(msg, data).then((dataMsg) => { - this.requestMovie(msg, dataMsg, data); - }); - }).catch(() => { - return msg.reply('Something went wrong! Couldn\'t get movie information.'); - }); - } - } -}; diff --git a/src/bots/commands/ombi/tv.js b/src/bots/commands/ombi/tv.js deleted file mode 100644 index 6468073..0000000 --- a/src/bots/commands/ombi/tv.js +++ /dev/null @@ -1,142 +0,0 @@ -const Discord = require('discord.js'); -const commando = require('discord.js-commando'); -const path = require('path'); - -module.exports = class searchTVShowCommand extends commando.Command { - constructor (client) { - super(client, { - 'name': 'tv', - 'memberName': 'tv', - 'group': 'ombi', - 'description': 'Search and Request TV Shows in Ombi', - 'examples': ['tv The Big Bang Theory', 'tv tvdb:80379'], - 'guildOnly': true, - 'argsPromptLimit': 0, - 'args': [ - { - 'key': 'name', - 'prompt': 'Name of the TV Show', - 'type': 'string' - } - ] - }); - } - - outputTVShow(msg, show) { - let tvEmbed = new Discord.MessageEmbed() - .setTitle(`${show.title} ${(show.firstAired) ? `(${show.firstAired.substring(0,4)})` : ''}`) - .setDescription(show.overview.substr(0, 255) + '(...)') - .setFooter(msg.author.username, `https://cdn.discordapp.com/avatars/${msg.author.id}/${msg.author.avatar}.png`) - .setTimestamp(new Date()) - .setImage(show.banner) - .setURL(`https://www.thetvdb.com/?id=${show.id}&tab=series`) - .attachFiles(path.join(__dirname, '..', '..', '..', 'resources', 'tvdb.png')) - .setThumbnail('attachment://tvdb.png') - .addField('__Network__', show.network, true) - .addField('__Status__', show.status, true); - - if (show.available) tvEmbed.addField('__Available__', '✅', true); - if (show.quality) tvEmbed.addField('__Quality__', show.quality, true); - if (show.requested) tvEmbed.addField('__Requested__', '✅', true); - if (show.approved) tvEmbed.addField('__Approved__', '✅', true); - if (show.plexUrl) tvEmbed.addField('__Plex__', `[Watch now](${show.plexUrl})`, true); - if (show.embyUrl) tvEmbed.addField('__Emby__', `[Watch now](${show.embyUrl})`, true); - - return msg.embed(tvEmbed); - } - - getTVDbID(msg, name) { - return new Promise((resolve) => { - this.client.API.ombi.searchTVShow(name).then((data) => { - if (data.length > 1) { - let fieldContent = ''; - data.forEach((show, i) => { - fieldContent += `${i+1}) ${show.title} ` - if (show.firstAired) fieldContent += `(${show.firstAired.substring(0,4)}) ` - fieldContent += `[[TheTVDb](https://www.thetvdb.com/?id=${show.id}&tab=series)]\n` - }) - - let showEmbed = new Discord.MessageEmbed(); - showEmbed.setTitle('Ombi TV Show Search') - .setDescription('Please select one of the search results. To abort answer **cancel**') - .addField('__Search Results__', fieldContent); - - const aMsg = msg.embed(showEmbed); - msg.channel.awaitMessages(m => (!isNaN(parseInt(m.content)) || m.content.startsWith('cancel')) && m.author.id == msg.author.id, { max: 1, time: 120000, errors: ['time'] }) - .then((collected) => { - let message = collected.first().content; - let selection = parseInt(message); - - aMsg.then((m) => m.delete()); - if (collected.first().deletable) collected.first().delete(); - if (message.startsWith('cancel')) { - msg.reply('Cancelled command.'); - } else if (selection > 0 && selection <= data.length) { - resolve(data[selection - 1].id); - } else { - msg.reply('Please enter a valid selection!'); - } - }).catch(() => { - msg.reply('Cancelled command.'); - }); - } else if (!data.length) { - msg.reply('Couldn\'t find the tv show you were looking for. Is the name correct?'); - } else { - resolve(data[0].id); - } - }).catch(() => { - msg.reply('Something went wrong! Couldn\'t find any tv show.'); - }); - }); - } - - requestTVShow(msg, showMsg, show) { - const ombi = this.client.webDatabase.getConfig()['ombi']; - if ((!ombi.requesttv || msg.member.roles.some(role => role.name.toLowerCase() === ombi.requesttv.toLowerCase())) && (!show.available && !show.requested && !show.approved)) { - msg.reply('If you want to request this tv show please click on the ⬇ reaction.'); - showMsg.react('⬇'); - - showMsg.awaitReactions((reaction, user) => reaction.emoji.name === '⬇' && user.id === msg.author.id, { max: 1, time: 120000 }).then(collected => { - if (collected.first()) { - this.client.API.ombi.requestTVShow(show.id, `${encodeURI(msg.author.username.toLowerCase())}#${msg.author.discriminator}`).then(() => { - return msg.reply(`Requested ${show.title} in Ombi.`); - }).catch(() => { - return msg.reply('Something went wrong! Couldn\'t request tv show.'); - }); - } - }).catch(() => { - return msg.reply('Something went wrong! Couldn\'t register your emoji.'); - }); - } - return showMsg; - } - - async run (msg, args) { - this.client.deleteCommandMessages(msg); - if (!args.name) { - return msg.reply('Please enter a valid tv show name.'); - } - - let tvdbid = undefined; - if (args.name.startsWith("tvdb:")) { - const matches = /^tvdb:(\d+)$/.exec(args.name); - if (matches) { - tvdbid = matches[1]; - } else { - return msg.reply('Please enter a valid TVDb ID!'); - } - } else { - tvdbid = await this.getTVDbID(msg, args.name); - } - - if (tvdbid) { - this.client.API.ombi.getTVShowInformation(tvdbid).then((data) => { - this.outputTVShow(msg, data).then((dataMsg) => { - this.requestTVShow(msg, dataMsg, data); - }); - }).catch(() => { - return msg.reply('Something went wrong! Couldn\'t get tv show information.'); - }); - } - } -}; diff --git a/src/bots/commands/searchrequest/movie.js b/src/bots/commands/searchrequest/movie.js new file mode 100644 index 0000000..ddabc78 --- /dev/null +++ b/src/bots/commands/searchrequest/movie.js @@ -0,0 +1,35 @@ +const commando = require('discord.js-commando'); +const { executeMovie } = require('./services/ombi.js'); + +module.exports = class searchMovieCommand extends commando.Command { + constructor (client) { + super(client, { + 'name': 'movie', + 'memberName': 'movie', + 'group': 'searchrequest', + 'description': 'Search and Request Movies in Ombi or Radarr', + 'examples': ['movie The Matrix', 'movie tmdb:603'], + 'guildOnly': true, + 'argsPromptLimit': 0, + 'args': [ + { + 'key': 'name', + 'prompt': 'Name of the Movie', + 'type': 'string' + } + ] + }); + } + + async run (msg, args) { + const config = this.client.webDatabase.webConfig; + + // check which service is set to default and available and then use that + // only use ombi until radarr is implemented completely + if (config.bot.defaultservice === 'ombi') + if (config.ombi.host !== '' && config.ombi.apikey !== '') + return await executeMovie(this.client, msg, args); + else + return msg.reply('Please configure ombi first!'); + } +}; diff --git a/src/bots/commands/searchrequest/services/ombi.js b/src/bots/commands/searchrequest/services/ombi.js new file mode 100644 index 0000000..483efca --- /dev/null +++ b/src/bots/commands/searchrequest/services/ombi.js @@ -0,0 +1,241 @@ +const Discord = require('discord.js'); +const path = require('path'); + +const outputMovie = (msg, movie) => { + let movieEmbed = new Discord.MessageEmbed() + .setTitle(`${movie.title} ${(movie.releaseDate) ? `(${movie.releaseDate.split('T')[0].substring(0,4)})` : ''}`) + .setDescription(movie.overview.substr(0, 255) + '(...)') + .setFooter(msg.author.username, `https://cdn.discordapp.com/avatars/${msg.author.id}/${msg.author.avatar}.png`) + .setTimestamp(new Date()) + .setImage('https://image.tmdb.org/t/p/w500' + movie.posterPath) + .setURL('https://www.themoviedb.org/movie/' + movie.theMovieDbId) + .attachFiles(path.join(__dirname, '../../../..', 'resources', 'tmdb.png')) + .setThumbnail('attachment://tmdb.png'); + + if (movie.available) movieEmbed.addField('__Available__', '✅', true); + if (movie.quality) movieEmbed.addField('__Quality__', `${movie.qualityp}p` , true); + if (movie.requested) movieEmbed.addField('__Requested__', '✅', true); + if (movie.approved) movieEmbed.addField('__Approved__', '✅', true); + if (movie.plexUrl) movieEmbed.addField('__Plex__', `[Watch now](${movie.plexUrl})`, true); + if (movie.embyUrl) movieEmbed.addField('__Emby__', `[Watch now](${movie.embyUrl})`, true); + + return msg.embed(movieEmbed); +} + +const outputTVShow = (msg, show) => { + let tvEmbed = new Discord.MessageEmbed() + .setTitle(`${show.title} ${(show.firstAired) ? `(${show.firstAired.substring(0,4)})` : ''}`) + .setDescription(show.overview.substr(0, 255) + '(...)') + .setFooter(msg.author.username, `https://cdn.discordapp.com/avatars/${msg.author.id}/${msg.author.avatar}.png`) + .setTimestamp(new Date()) + .setImage(show.banner) + .setURL(`https://www.thetvdb.com/?id=${show.id}&tab=series`) + .attachFiles(path.join(__dirname, '../../../..', 'resources', 'tvdb.png')) + .setThumbnail('attachment://tvdb.png') + .addField('__Network__', show.network, true) + .addField('__Status__', show.status, true); + + if (show.available) tvEmbed.addField('__Available__', '✅', true); + if (show.quality) tvEmbed.addField('__Quality__', show.quality, true); + if (show.requested) tvEmbed.addField('__Requested__', '✅', true); + if (show.approved) tvEmbed.addField('__Approved__', '✅', true); + if (show.plexUrl) tvEmbed.addField('__Plex__', `[Watch now](${show.plexUrl})`, true); + if (show.embyUrl) tvEmbed.addField('__Emby__', `[Watch now](${show.embyUrl})`, true); + + return msg.embed(tvEmbed); +} + +const getTMDbID = (client, msg, name) => { + return new Promise((resolve) => { + client.API.ombi.searchMovie(name).then((data) => { + if (data.length > 1) { + let fieldContent = ''; + data.forEach((movie, i) => { + fieldContent += `${i+1}) ${movie.title} ` + if (movie.releaseDate) fieldContent += `(${movie.releaseDate.substring(0,4)}) ` + fieldContent += `[[TheMovieDb](https://www.themoviedb.org/movie/${movie.theMovieDbId})]\n` + }) + + let showEmbed = new Discord.MessageEmbed(); + showEmbed.setTitle('Ombi Movie Search') + .setDescription('Please select one of the search results. To abort answer **cancel**') + .addField('__Search Results__', fieldContent); + + const aMsg = msg.embed(showEmbed); + msg.channel.awaitMessages(m => (!isNaN(parseInt(m.content)) || m.content.startsWith('cancel')) && m.author.id == msg.author.id, { max: 1, time: 120000, errors: ['time'] }) + .then((collected) => { + let message = collected.first().content; + let selection = parseInt(message); + + aMsg.then((m) => m.delete()); + if (collected.first().deletable) collected.first().delete(); + if (message.startsWith('cancel')) { + msg.reply('Cancelled command.'); + } else if (selection > 0 && selection <= data.length) { + resolve(data[selection - 1].id); + } else { + msg.reply('Please enter a valid selection!'); + } + }).catch(() => { + msg.reply('Cancelled command.'); + }); + } else if (!data.length) { + msg.reply('Couldn\'t find the movie you were looking for. Is the name correct?'); + } else { + resolve(data[0].id); + } + }).catch(() => { + msg.reply('Something went wrong! Couldn\'t find any movie.'); + }); + }); +} + +const getTVDbID = (client, msg, name) => { + return new Promise((resolve) => { + client.API.ombi.searchTVShow(name).then((data) => { + if (data.length > 1) { + let fieldContent = ''; + data.forEach((show, i) => { + fieldContent += `${i+1}) ${show.title} ` + if (show.firstAired) fieldContent += `(${show.firstAired.substring(0,4)}) ` + fieldContent += `[[TheTVDb](https://www.thetvdb.com/?id=${show.id}&tab=series)]\n` + }) + + let showEmbed = new Discord.MessageEmbed(); + showEmbed.setTitle('Ombi TV Show Search') + .setDescription('Please select one of the search results. To abort answer **cancel**') + .addField('__Search Results__', fieldContent); + + const aMsg = msg.embed(showEmbed); + msg.channel.awaitMessages(m => (!isNaN(parseInt(m.content)) || m.content.startsWith('cancel')) && m.author.id == msg.author.id, { max: 1, time: 120000, errors: ['time'] }) + .then((collected) => { + let message = collected.first().content; + let selection = parseInt(message); + + aMsg.then((m) => m.delete()); + if (collected.first().deletable) collected.first().delete(); + if (message.startsWith('cancel')) { + msg.reply('Cancelled command.'); + } else if (selection > 0 && selection <= data.length) { + resolve(data[selection - 1].id); + } else { + msg.reply('Please enter a valid selection!'); + } + }).catch(() => { + msg.reply('Cancelled command.'); + }); + } else if (!data.length) { + msg.reply('Couldn\'t find the tv show you were looking for. Is the name correct?'); + } else { + resolve(data[0].id); + } + }).catch(() => { + msg.reply('Something went wrong! Couldn\'t find any tv show.'); + }); + }); +} + +const requestMovie = (client, msg, movieMsg, movie) => { + const ombi = client.webDatabase.webConfig['ombi']; + if ((!ombi.requestmovie || msg.member.roles.some(role => role.name.toLowerCase() === ombi.requestmovie.toLowerCase())) && (!movie.available && !movie.requested && !movie.approved)) { + msg.reply('If you want to request this movie please click on the ⬇ reaction.'); + movieMsg.react('⬇'); + + movieMsg.awaitReactions((reaction, user) => reaction.emoji.name === '⬇' && user.id === msg.author.id, { max: 1, time: 120000 }).then(collected => { + if (collected.first()) { + client.API.ombi.requestMovie(movie.theMovieDbId, `${encodeURI(msg.author.username.toLowerCase())}#${msg.author.discriminator}`).then(() => { + return msg.reply(`Requested ${movie.title} in Ombi.`); + }).catch(() => { + return msg.reply('Something went wrong! Couldn\'t request movie.'); + }); + } + }).catch(() => { + return msg.reply('Something went wrong! Couldn\'t register your emoji.'); + }); + } + return movieMsg; +} + +const requestTVShow = (client, msg, showMsg, show) => { + const ombi = client.webDatabase.webConfig['ombi']; + if ((!ombi.requesttv || msg.member.roles.some(role => role.name.toLowerCase() === ombi.requesttv.toLowerCase())) && (!show.available && !show.requested && !show.approved)) { + msg.reply('If you want to request this tv show please click on the ⬇ reaction.'); + showMsg.react('⬇'); + + showMsg.awaitReactions((reaction, user) => reaction.emoji.name === '⬇' && user.id === msg.author.id, { max: 1, time: 120000 }).then(collected => { + if (collected.first()) { + client.API.ombi.requestTVShow(show.id, `${encodeURI(msg.author.username.toLowerCase())}#${msg.author.discriminator}`).then(() => { + return msg.reply(`Requested ${show.title} in Ombi.`); + }).catch(() => { + return msg.reply('Something went wrong! Couldn\'t request tv show.'); + }); + } + }).catch(() => { + return msg.reply('Something went wrong! Couldn\'t register your emoji.'); + }); + } + return showMsg; +} + +const executeMovie = async (client, msg, args) => { + client.deleteCommandMessages(msg); + if (!args.name) { + return msg.reply('Please enter a valid movie name.'); + } + + let tmdbid = undefined; + if (args.name.startsWith("tmdb:")) { + const matches = /^tmdb:(\d+)$/.exec(args.name); + if (matches) { + tmdbid = matches[1]; + } else { + return msg.reply('Please enter a valid TMDb ID!'); + } + } else { + tmdbid = await getTMDbID(client, msg, args.name); + } + + if (tmdbid) { + client.API.ombi.getMovieInformation(tmdbid).then((data) => { + outputMovie(msg, data).then((dataMsg) => { + requestMovie(clien, msg, dataMsg, data); + }); + }).catch(() => { + return msg.reply('Something went wrong! Couldn\'t get movie information.'); + }); + } +} + +const executeTV = async (client, msg, args) => { + client.deleteCommandMessages(msg); + if (!args.name) { + return msg.reply('Please enter a valid tv show name.'); + } + + let tvdbid = undefined; + if (args.name.startsWith("tvdb:")) { + const matches = /^tvdb:(\d+)$/.exec(args.name); + if (matches) { + tvdbid = matches[1]; + } else { + return msg.reply('Please enter a valid TVDb ID!'); + } + } else { + tvdbid = await getTVDbID(client, msg, args.name); + } + + if (tvdbid) { + client.API.ombi.getTVShowInformation(tvdbid).then((data) => { + outputTVShow(msg, data).then((dataMsg) => { + requestTVShow(client, msg, dataMsg, data); + }); + }).catch(() => { + return msg.reply('Something went wrong! Couldn\'t get tv show information.'); + }); + } +} + +module.exports = { + executeMovie, + executeTV +} diff --git a/src/bots/commands/searchrequest/services/radarr.js b/src/bots/commands/searchrequest/services/radarr.js new file mode 100644 index 0000000..c65c045 --- /dev/null +++ b/src/bots/commands/searchrequest/services/radarr.js @@ -0,0 +1 @@ +// TODO: implement radarr command functionality for discord \ No newline at end of file diff --git a/src/bots/commands/searchrequest/services/sonarr.js b/src/bots/commands/searchrequest/services/sonarr.js new file mode 100644 index 0000000..c65c045 --- /dev/null +++ b/src/bots/commands/searchrequest/services/sonarr.js @@ -0,0 +1 @@ +// TODO: implement radarr command functionality for discord \ No newline at end of file diff --git a/src/bots/commands/searchrequest/tv.js b/src/bots/commands/searchrequest/tv.js new file mode 100644 index 0000000..d8a2395 --- /dev/null +++ b/src/bots/commands/searchrequest/tv.js @@ -0,0 +1,35 @@ +const commando = require('discord.js-commando'); +const { executeTV } = require('./services/ombi.js'); + +module.exports = class searchTVShowCommand extends commando.Command { + constructor (client) { + super(client, { + 'name': 'tv', + 'memberName': 'tv', + 'group': 'searchrequest', + 'description': 'Search and Request TV Shows in Ombi or Sonarr', + 'examples': ['tv The Big Bang Theory', 'tv tvdb:80379'], + 'guildOnly': true, + 'argsPromptLimit': 0, + 'args': [ + { + 'key': 'name', + 'prompt': 'Name of the TV Show', + 'type': 'string' + } + ] + }); + } + + async run (msg, args) { + const config = this.client.webDatabase.webConfig; + + // check which service is set to default and available and then use that + // only use ombi until sonarr is implemented completely + if (config.bot.defaultservice === 'ombi') + if (config.ombi.host !== '' && config.ombi.apikey !== '') + return await executeTV(this.client, msg, args); + else + return msg.reply('Please configure ombi first!'); + } +};