From 392cffec1c433c6b66341f01161ae6554e18bbc2 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 26 Jul 2018 19:36:37 -0400 Subject: [PATCH] VNDB Command --- README.md | 3 +- commands/search/vndb.js | 71 +++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 commands/search/vndb.js diff --git a/README.md b/README.md index 286a5723..f0992f76 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (292) +## Commands (293) ### Utility: * **eval**: Executes JavaScript code. @@ -158,6 +158,7 @@ on the [home server](https://discord.gg/sbMe32W). * **tumblr**: Responds with information on a Tumblr blog. * **twitter**: Responds with information on a Twitter user. * **urban-dictionary**: Defines a word, but with Urban Dictionary. +* **vndb**: Responds with information on a Visual Novel. * **vocaloid**: Searches VocaDB for your query. * **wattpad**: Searches Wattpad for your query. * **weather**: Responds with weather information for a specific location. diff --git a/commands/search/vndb.js b/commands/search/vndb.js new file mode 100644 index 00000000..eceb899e --- /dev/null +++ b/commands/search/vndb.js @@ -0,0 +1,71 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { MessageEmbed } = require('discord.js'); +const { shorten } = require('../../util/Util'); + +module.exports = class VNDBCommand extends Command { + constructor(client) { + super(client, { + name: 'vndb', + aliases: ['visual-novel', 'vn'], + group: 'search', + memberName: 'vndb', + description: 'Responds with information on a Visual Novel.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What visual novel would you like to get information on?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const data = await this.fetchVN(query); + if (!data) return msg.say('Could not find any results.'); + const embed = new MessageEmbed() + .setColor(0x000407) + .setAuthor('VNDB', 'https://i.imgur.com/BIxjIby.png', 'https://vndb.org/') + .setTitle(data.title) + .setDescription(shorten(data.description || 'No description available.')) + .setURL(data.url) + .setThumbnail(data.image) + .addField('❯ Developer', `[${data.developer.name}](${data.developer.url})`); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + async fetchVN(query) { + const { text } = await request + .get('https://vndb.org/v/all') + .query({ q: query }); + const id = text.match(/Description<\/h2>

(.+)<\/p><\/td>/)[1] + .replace(/
/g, '\n') + .replace(/
(.+)<\/a>/g, '[$2]($1)'); + return { + id: id[1], + url, + title: detailsText.match(/(.+)<\/title>/)[1], + developer: { + name: devText.match(/<title>(.+)<\/title>/)[1], + url: devURL + }, + description: description === '-' ? null : description, + image: detailsText.match(/https:\/\/s.vndb.org\/cv\/[0-9]+\/[0-9]+\.jpg/)[0] + }; + } +}; diff --git a/package.json b/package.json index d2d028fd..a46cb354 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "85.3.0", + "version": "85.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {