NSFW Commands

This commit is contained in:
Daniel Odendahl Jr
2017-05-17 21:02:21 +00:00
parent 447b910c7f
commit d98e050509
9 changed files with 182 additions and 7 deletions
+42
View File
@@ -0,0 +1,42 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
module.exports = class DanbooruCommand extends Command {
constructor(client) {
super(client, {
name: 'danbooru',
group: 'nsfw',
memberName: 'danbooru',
description: 'Sends an image from Danbooru, with optional query.',
guildOnly: true,
args: [
{
key: 'query',
prompt: 'What would you like to search for?',
type: 'string',
default: ''
}
]
});
}
async run(msg, args) {
if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.');
if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES'))
return msg.say('This Command requires the `Attach Files` Permission.');
const { query } = args;
try {
const { body } = await snekfetch
.get('https://danbooru.donmai.us/posts.json')
.query({
tags: `${query ? `${query} ` : ''}order:random`,
limit: 1
});
if (!body.length) throw new Error('No Results.');
return msg.say(query ? `Result for ${query}:` : 'Random Image:', { files: [`https://danbooru.domai.us${body[0].file_url}`] })
.catch(err => msg.say(`${err.name}: ${err.message}`));
} catch (err) {
return msg.say(`${err.name}: ${err.message}`);
}
}
};
+46
View File
@@ -0,0 +1,46 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { promisify } = require('tsubaki');
const xml = promisify(require('xml2js').parseString);
module.exports = class GelbooruCommand extends Command {
constructor(client) {
super(client, {
name: 'gelbooru',
group: 'nsfw',
memberName: 'gelbooru',
description: 'Sends an image from Gelbooru, with query.',
guildOnly: true,
args: [
{
key: 'query',
prompt: 'What would you like to search for?',
type: 'string'
}
]
});
}
async run(msg, args) {
if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.');
if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES'))
return msg.say('This Command requires the `Attach Files` Permission.');
const { query } = args;
try {
const { text } = await snekfetch
.get('https://gelbooru.com/index.php')
.query({
page: 'dapi',
s: 'post',
q: 'index',
tags: query,
limit: 1
});
const { posts } = await xml(text);
return msg.say(`Result for ${query}:`, { files: [`https:${posts.post[0].$.file_url}`] })
.catch(err => msg.say(`${err.name}: ${err.message}`));
} catch (err) {
return msg.say(`${err.name}: ${err.message}`);
}
}
};
@@ -5,9 +5,9 @@ module.exports = class KonachanCommand extends Command {
constructor(client) {
super(client, {
name: 'konachan',
group: 'search',
group: 'nsfw',
memberName: 'konachan',
description: 'Sends a random (Possibly NSFW!) anime image from Konachan, with optional query.',
description: 'Sends an image from Konachan, with optional query.',
guildOnly: true,
args: [
{
+42
View File
@@ -0,0 +1,42 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
module.exports = class LolibooruCommand extends Command {
constructor(client) {
super(client, {
name: 'lolibooru',
group: 'nsfw',
memberName: 'lolibooru',
description: 'Sends an image from Lolibooru, with optional query.',
guildOnly: true,
args: [
{
key: 'query',
prompt: 'What would you like to search for?',
type: 'string',
default: ''
}
]
});
}
async run(msg, args) {
if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.');
if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES'))
return msg.say('This Command requires the `Attach Files` Permission.');
const { query } = args;
try {
const { body } = await snekfetch
.get('https://lolibooru.moe/post/index.json')
.query({
tags: `${query ? `${query} ` : ''}order:random`,
limit: 1
});
if (!body.length) throw new Error('No Results.');
return msg.say(query ? `Result for ${query}:` : 'Random Image:', { files: [body[0].file_url] })
.catch(err => msg.say(`${err.name}: ${err.message}`));
} catch (err) {
return msg.say(`${err.name}: ${err.message}`);
}
}
};
+46
View File
@@ -0,0 +1,46 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { promisify } = require('tsubaki');
const xml = promisify(require('xml2js').parseString);
module.exports = class Rule34Command extends Command {
constructor(client) {
super(client, {
name: 'rule34',
group: 'nsfw',
memberName: 'rule34',
description: 'Sends an image from Rule34, with query.',
guildOnly: true,
args: [
{
key: 'query',
prompt: 'What would you like to search for?',
type: 'string'
}
]
});
}
async run(msg, args) {
if (!msg.channel.nsfw) return msg.say('This Command can only be used in NSFW Channels.');
if (!msg.channel.permissionsFor(this.client.user).has('ATTACH_FILES'))
return msg.say('This Command requires the `Attach Files` Permission.');
const { query } = args;
try {
const { text } = await snekfetch
.get('https://rule34.xxx/index.php')
.query({
page: 'dapi',
s: 'post',
q: 'index',
tags: query,
limit: 1
});
const { posts } = await xml(text);
return msg.say(`Result for ${query}:`, { files: [`https:${posts.post[0].$.file_url}`] })
.catch(err => msg.say(`${err.name}: ${err.message}`));
} catch (err) {
return msg.say(`${err.name}: ${err.message}`);
}
}
};
+1 -2
View File
@@ -35,7 +35,7 @@
<li>Random Roasts, Fortunes, and Compliments!</li>
<li>Random Fact Core Quotes!</li>
<li>Random Name Generation!</li>
<li>Random Anime Images (with NSFW)!</li>
<li>NSFW Commands!</li>
<li>Random XKCD Comics!</li>
<li>Roleplay Commands!</li>
<li>Search Various sites including:</li>
@@ -53,7 +53,6 @@
<li>Wikipedia</li>
<li>YouTube</li>
<li>YuGiOh! Card Data</li>
<li>Konachan</li>
<li>My Anime List</li>
</ol>
<li>LMGTFY Link Generation!</li>
+1 -2
View File
@@ -30,7 +30,7 @@
<li>Random Roasts, Fortunes, and Compliments!</li>
<li>Random Fact Core Quotes!</li>
<li>Random Name Generation!</li>
<li>Random Anime Images (with NSFW)!</li>
<li>NSFW Commands!</li>
<li>Random XKCD Comics!</li>
<li>Roleplay Commands!</li>
<li>Search Various sites including:</li>
@@ -48,7 +48,6 @@
<li>Wikipedia</li>
<li>YouTube</li>
<li>YuGiOh! Card Data</li>
<li>Konachan</li>
<li>My Anime List</li>
</ul>
<li>LMGTFY Link Generation!</li>
+1
View File
@@ -36,6 +36,7 @@ client.registry
['numedit', 'Number Manipulation'],
['search', 'Search'],
['games', 'Games'],
['nsfw', 'NSFW'],
['random', 'Random/Other'],
['roleplay', 'Roleplay']
])
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "19.7.1",
"version": "19.8.0",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"scripts": {