diff --git a/commands/nsfw/danbooru.js b/commands/nsfw/danbooru.js new file mode 100644 index 00000000..56d5b702 --- /dev/null +++ b/commands/nsfw/danbooru.js @@ -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}`); + } + } +}; diff --git a/commands/nsfw/gelbooru.js b/commands/nsfw/gelbooru.js new file mode 100644 index 00000000..fa4917fa --- /dev/null +++ b/commands/nsfw/gelbooru.js @@ -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}`); + } + } +}; diff --git a/commands/search/konachan.js b/commands/nsfw/konachan.js similarity index 91% rename from commands/search/konachan.js rename to commands/nsfw/konachan.js index 3aa3ddb1..018d184f 100644 --- a/commands/search/konachan.js +++ b/commands/nsfw/konachan.js @@ -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: [ { diff --git a/commands/nsfw/lolibooru.js b/commands/nsfw/lolibooru.js new file mode 100644 index 00000000..ea85a736 --- /dev/null +++ b/commands/nsfw/lolibooru.js @@ -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}`); + } + } +}; diff --git a/commands/nsfw/rule34.js b/commands/nsfw/rule34.js new file mode 100644 index 00000000..f329183c --- /dev/null +++ b/commands/nsfw/rule34.js @@ -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}`); + } + } +}; diff --git a/html/carbonfeat.html b/html/carbonfeat.html index 7871cae6..f47359a6 100644 --- a/html/carbonfeat.html +++ b/html/carbonfeat.html @@ -35,7 +35,7 @@
  • Random Roasts, Fortunes, and Compliments!
  • Random Fact Core Quotes!
  • Random Name Generation!
  • -
  • Random Anime Images (with NSFW)!
  • +
  • NSFW Commands!
  • Random XKCD Comics!
  • Roleplay Commands!
  • Search Various sites including:
  • @@ -53,7 +53,6 @@
  • Wikipedia
  • YouTube
  • YuGiOh! Card Data
  • -
  • Konachan
  • My Anime List
  • LMGTFY Link Generation!
  • diff --git a/html/discordbots.html b/html/discordbots.html index a902e59e..f0e92a81 100644 --- a/html/discordbots.html +++ b/html/discordbots.html @@ -30,7 +30,7 @@
  • Random Roasts, Fortunes, and Compliments!
  • Random Fact Core Quotes!
  • Random Name Generation!
  • -
  • Random Anime Images (with NSFW)!
  • +
  • NSFW Commands!
  • Random XKCD Comics!
  • Roleplay Commands!
  • Search Various sites including:
  • @@ -48,7 +48,6 @@
  • Wikipedia
  • YouTube
  • YuGiOh! Card Data
  • -
  • Konachan
  • My Anime List
  • LMGTFY Link Generation!
  • diff --git a/index.js b/index.js index 82d299d3..a6103b57 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,7 @@ client.registry ['numedit', 'Number Manipulation'], ['search', 'Search'], ['games', 'Games'], + ['nsfw', 'NSFW'], ['random', 'Random/Other'], ['roleplay', 'Roleplay'] ]) diff --git a/package.json b/package.json index ccb2f451..6678bfec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "19.7.1", + "version": "19.8.0", "description": "A Discord Bot", "main": "shardingmanager.js", "scripts": {