VNDB Command

This commit is contained in:
Dragon Fire
2018-07-26 19:36:37 -04:00
parent 763cb71bb6
commit 392cffec1c
3 changed files with 74 additions and 2 deletions
+2 -1
View File
@@ -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.
+71
View File
@@ -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(/<a href="\/v([0-9]+)" title=/);
if (!id) return null;
const url = `https://vndb.org/v${id[1]}`;
const details = await request.get(url);
const detailsText = details.text;
const dev = detailsText.match(/<a href="\/p([0-9]+)"/);
const devURL = `https://vndb.org/p${dev[1]}`;
const devReq = await request.get(devURL);
const devText = devReq.text;
const description = detailsText.match(/<h2>Description<\/h2><p>(.+)<\/p><\/td>/)[1]
.replace(/<br>/g, '\n')
.replace(/<a href="(.+)" rel="nofollow">(.+)<\/a>/g, '[$2]($1)');
return {
id: id[1],
url,
title: detailsText.match(/<title>(.+)<\/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]
};
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "85.3.0",
"version": "85.4.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {