Revenge of the Sith

This commit is contained in:
Daniel Odendahl Jr
2017-10-18 22:45:01 +00:00
parent 1d902fa1f6
commit badca78816
5 changed files with 133 additions and 2 deletions
+45
View File
@@ -0,0 +1,45 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
module.exports = class DanbooruCommand extends Command {
constructor(client) {
super(client, {
name: 'danbooru',
aliases: ['danbooru-image'],
group: 'search',
memberName: 'danbooru',
description: 'Searches Danbooru for your query.',
args: [
{
key: 'query',
prompt: 'What image would you like to search for?',
type: 'string',
validate: query => {
if (!query.includes(' ')) return true;
return 'Invalid query, please only search for one tag at a time.';
}
}
]
});
}
async run(msg, { query }) {
if (!msg.channel.nsfw) return msg.say('This command can only be used in NSFW channels.');
try {
const { body } = await snekfetch
.get('https://danbooru.donmai.us/posts.json')
.query({
tags: `${query} order:random`,
limit: 1
});
if (!body.length || !body[0].file_url) return msg.say('Could not find any results.');
return msg.say(stripIndents`
Result for ${query}:
https://danbooru.donmai.us${body[0].file_url}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+45
View File
@@ -0,0 +1,45 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { xml2js } = require('xml-js');
const { stripIndents } = require('common-tags');
module.exports = class GelbooruCommand extends Command {
constructor(client) {
super(client, {
name: 'gelbooru',
aliases: ['gelbooru-image'],
group: 'search',
memberName: 'gelbooru',
description: 'Searches Gelbooru for your query.',
args: [
{
key: 'query',
prompt: 'What image would you like to search for?',
type: 'string'
}
]
});
}
async run(msg, { query }) {
if (!msg.channel.nsfw) return msg.say('This command can only be used in NSFW channels.');
try {
const { text } = await snekfetch
.get('https://gelbooru.com/index.php')
.query({
page: 'dapi',
s: 'post',
q: 'index',
tags: query
});
const parsed = xml2js(text, { compact: true }).posts;
if (!parsed.post || !parsed.post.length) return msg.say('Could not find any results.');
return msg.say(stripIndents`
Result for ${query}:
https:${parsed.post[Math.floor(Math.random() * parsed.post.length)]._attributes.file_url}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+41
View File
@@ -0,0 +1,41 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
module.exports = class KonachanCommand extends Command {
constructor(client) {
super(client, {
name: 'konachan',
aliases: ['konachan-image'],
group: 'search',
memberName: 'konachan',
description: 'Searches Konachan for your query.',
args: [
{
key: 'query',
prompt: 'What image would you like to search for?',
type: 'string'
}
]
});
}
async run(msg, { query }) {
if (!msg.channel.nsfw) return msg.say('This command can only be used in NSFW channels.');
try {
const { body } = await snekfetch
.get('https://konachan.net/post.json')
.query({
tags: `${query} order:random`,
limit: 1
});
if (!body.length || !body[0].file_url) return msg.say('Could not find any results.');
return msg.say(stripIndents`
Result for ${query}:
https:${body[0].file_url}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -35,7 +35,7 @@ module.exports = class SafebooruCommand extends Command {
if (!parsed.post || !parsed.post.length) return msg.say('Could not find any results.');
return msg.say(stripIndents`
Result for ${query}:
http:${parsed.post[Math.floor(Math.random() * parsed.post.length)]._attributes.file_url}
https:${parsed.post[Math.floor(Math.random() * parsed.post.length)]._attributes.file_url}
`);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "47.7.0",
"version": "47.8.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {