mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-16 15:57:54 +02:00
VNDB Command
This commit is contained in:
@@ -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
|
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).
|
on the [home server](https://discord.gg/sbMe32W).
|
||||||
|
|
||||||
## Commands (292)
|
## Commands (293)
|
||||||
### Utility:
|
### Utility:
|
||||||
|
|
||||||
* **eval**: Executes JavaScript code.
|
* **eval**: Executes JavaScript code.
|
||||||
@@ -158,6 +158,7 @@ on the [home server](https://discord.gg/sbMe32W).
|
|||||||
* **tumblr**: Responds with information on a Tumblr blog.
|
* **tumblr**: Responds with information on a Tumblr blog.
|
||||||
* **twitter**: Responds with information on a Twitter user.
|
* **twitter**: Responds with information on a Twitter user.
|
||||||
* **urban-dictionary**: Defines a word, but with Urban Dictionary.
|
* **urban-dictionary**: Defines a word, but with Urban Dictionary.
|
||||||
|
* **vndb**: Responds with information on a Visual Novel.
|
||||||
* **vocaloid**: Searches VocaDB for your query.
|
* **vocaloid**: Searches VocaDB for your query.
|
||||||
* **wattpad**: Searches Wattpad for your query.
|
* **wattpad**: Searches Wattpad for your query.
|
||||||
* **weather**: Responds with weather information for a specific location.
|
* **weather**: Responds with weather information for a specific location.
|
||||||
|
|||||||
@@ -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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "85.3.0",
|
"version": "85.4.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user