From c44ecf0052b039c9c6db76ff37ce0b1e14e02f43 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 19 Dec 2017 01:14:11 +0000 Subject: [PATCH] Remove some stuff, fix up role commands --- Xiao.js | 8 ++-- assets/json/roles.json | 13 ------- commands/role-manage/role-list.js | 11 +++--- commands/role-manage/subscribe.js | 7 ++-- commands/role-manage/unsubscribe.js | 7 ++-- commands/search/danbooru.js | 42 -------------------- commands/search/derpibooru.js | 37 ------------------ commands/search/gelbooru.js | 42 -------------------- commands/search/igdb.js | 60 ----------------------------- commands/search/konachan.js | 38 ------------------ package.json | 2 +- 11 files changed, 19 insertions(+), 248 deletions(-) delete mode 100644 assets/json/roles.json delete mode 100644 commands/search/danbooru.js delete mode 100644 commands/search/derpibooru.js delete mode 100644 commands/search/gelbooru.js delete mode 100644 commands/search/igdb.js delete mode 100644 commands/search/konachan.js diff --git a/Xiao.js b/Xiao.js index fc5aa9d7..81f1003a 100644 --- a/Xiao.js +++ b/Xiao.js @@ -22,15 +22,15 @@ client.registry ['random', 'Random Response'], ['single', 'Single Response'], ['events', 'Daily Events'], + ['search', 'Search'], + ['games', 'Games'], ['image-edit', 'Image Manipulation'], ['avatar-edit', 'Avatar Manipulation'], ['text-edit', 'Text Manipulation'], ['number-edit', 'Number Manipulation'], - ['search', 'Search'], - ['games', 'Games'], - ['role-manage', 'Role Management'], ['other', 'Other'], - ['roleplay', 'Roleplay'] + ['roleplay', 'Roleplay'], + ['role-manage', 'Home Server Role Management'] ]) .registerDefaultCommands({ help: false, diff --git a/assets/json/roles.json b/assets/json/roles.json deleted file mode 100644 index b0212c56..00000000 --- a/assets/json/roles.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "252317073814978561": [ - "345655085486964748", - "345655164621029379", - "345655222888300555" - ], - "346450651326185475": [ - "346781913358401537", - "346782031017017348", - "346782170846593028", - "346782235304919040" - ] -} diff --git a/commands/role-manage/role-list.js b/commands/role-manage/role-list.js index 3050de90..18d92ed0 100644 --- a/commands/role-manage/role-list.js +++ b/commands/role-manage/role-list.js @@ -1,24 +1,25 @@ const { Command } = require('discord.js-commando'); const { stripIndents } = require('common-tags'); -const roles = require('../../assets/json/roles'); +const { HOME_GUILD_ID, HOME_GUILD_ROLES } = process.env; -module.exports = class RolelistCommand extends Command { +module.exports = class RoleListCommand extends Command { constructor(client) { super(client, { name: 'role-list', aliases: ['roles'], group: 'role-manage', memberName: 'role-list', - description: 'Responds with all available roles in this server.', + description: 'Responds with all available roles to join in the home server.', + details: 'This command only works in the home server.', guildOnly: true }); } run(msg) { - if (!roles[msg.guild.id]) return msg.say('This server has no roles open...'); + if (msg.guild.id !== HOME_GUILD_ID) return msg.reply('This command only works in the home server.'); return msg.say(stripIndents` **Roles available in ${msg.guild.name}**: - ${msg.guild.roles.filter(role => roles[msg.guild.id].includes(role.id)).map(role => role.name).join('\n')} + ${msg.guild.roles.filter(role => HOME_GUILD_ROLES.split(',').includes(role.id)).map(role => role.name).join('\n')} `); } }; diff --git a/commands/role-manage/subscribe.js b/commands/role-manage/subscribe.js index 2e6d8faf..2ec1fbdb 100644 --- a/commands/role-manage/subscribe.js +++ b/commands/role-manage/subscribe.js @@ -1,5 +1,5 @@ const { Command } = require('discord.js-commando'); -const roles = require('../../assets/json/roles'); +const { HOME_GUILD_ID, HOME_GUILD_ROLES } = process.env; module.exports = class SubscribeCommand extends Command { constructor(client) { @@ -9,6 +9,7 @@ module.exports = class SubscribeCommand extends Command { group: 'role-manage', memberName: 'subscribe', description: 'Subscribes you to the specified role.', + details: 'This command only works in the home server.', guildOnly: true, clientPermissions: ['MANAGE_ROLES'], args: [ @@ -22,8 +23,8 @@ module.exports = class SubscribeCommand extends Command { } async run(msg, { role }) { - if (!roles[msg.guild.id]) return msg.say('This server has no roles open...'); - if (!roles[msg.guild.id].includes(role.id)) return msg.reply('This role is not open!'); + if (msg.guild.id !== HOME_GUILD_ID) return msg.reply('This command only works in the home server.'); + if (!HOME_GUILD_ROLES.split(',').includes(role.id)) return msg.reply('This role is not open!'); if (!role.editable) return msg.reply('I do not have permission to manage this role!'); if (msg.member.roles.has(role.id)) return msg.reply('You are already a member of this role!'); await msg.member.addRole(role); diff --git a/commands/role-manage/unsubscribe.js b/commands/role-manage/unsubscribe.js index 0a2801bd..242b9ec5 100644 --- a/commands/role-manage/unsubscribe.js +++ b/commands/role-manage/unsubscribe.js @@ -1,5 +1,5 @@ const { Command } = require('discord.js-commando'); -const roles = require('../../assets/json/roles'); +const { HOME_GUILD_ID, HOME_GUILD_ROLES } = process.env; module.exports = class UnsubscribeCommand extends Command { constructor(client) { @@ -9,6 +9,7 @@ module.exports = class UnsubscribeCommand extends Command { group: 'role-manage', memberName: 'unsubscribe', description: 'Unsubscribes you from the specified role.', + details: 'This command only works in the home server.', guildOnly: true, clientPermissions: ['MANAGE_ROLES'], args: [ @@ -22,8 +23,8 @@ module.exports = class UnsubscribeCommand extends Command { } async run(msg, { role }) { - if (!roles[msg.guild.id]) return msg.say('This server has no roles open...'); - if (!roles[msg.guild.id].includes(role.id)) return msg.reply('This role is not open!'); + if (msg.guild.id !== HOME_GUILD_ID) return msg.reply('This command only works in the home server.'); + if (!HOME_GUILD_ROLES.split(',').includes(role.id)) return msg.reply('This role is not open!'); if (!role.editable) return msg.reply('I do not have permission to manage this role!'); if (!msg.member.roles.has(role.id)) return msg.reply('You are not a member of this role!'); await msg.member.removeRole(role); diff --git a/commands/search/danbooru.js b/commands/search/danbooru.js deleted file mode 100644 index 7027003d..00000000 --- a/commands/search/danbooru.js +++ /dev/null @@ -1,42 +0,0 @@ -const { Command } = require('discord.js-commando'); -const snekfetch = require('snekfetch'); - -module.exports = class DanbooruCommand extends Command { - constructor(client) { - super(client, { - name: 'danbooru', - aliases: ['danbooru-image'], - group: 'search', - memberName: 'danbooru', - description: 'Responds with an image from Danbooru, with optional query.', - nsfw: true, - args: [ - { - key: 'query', - prompt: 'What image would you like to search for?', - type: 'string', - default: '', - validate: query => { - if (!query.includes(' ')) return true; - return 'Invalid query, please only search for one tag at a time.'; - } - } - ] - }); - } - - async run(msg, { query }) { - 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(`https://danbooru.donmai.us${body[0].file_url}`); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/search/derpibooru.js b/commands/search/derpibooru.js deleted file mode 100644 index aab7b046..00000000 --- a/commands/search/derpibooru.js +++ /dev/null @@ -1,37 +0,0 @@ -const { Command } = require('discord.js-commando'); -const snekfetch = require('snekfetch'); - -module.exports = class DerpibooruCommand extends Command { - constructor(client) { - super(client, { - name: 'derpibooru', - aliases: ['my-little-pony-image', 'mlp-image', 'derpibooru-image'], - group: 'search', - memberName: 'derpibooru', - description: 'Searches Derpibooru for your query.', - args: [ - { - key: 'query', - prompt: 'What image would you like to search for?', - type: 'string' - } - ] - }); - } - - async run(msg, { query }) { - try { - const search = await snekfetch - .get('https://derpibooru.org/search.json') - .query({ - q: query, - random_image: 1 - }); - if (!search.body) return msg.say('Could not find any results.'); - const { body } = await snekfetch.get(`https://derpibooru.org/images/${search.body.id}.json`); - return msg.say(`https:${body.representations.medium}`); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/search/gelbooru.js b/commands/search/gelbooru.js deleted file mode 100644 index 2db5c8f7..00000000 --- a/commands/search/gelbooru.js +++ /dev/null @@ -1,42 +0,0 @@ -const { Command } = require('discord.js-commando'); -const snekfetch = require('snekfetch'); - -module.exports = class GelbooruCommand extends Command { - constructor(client) { - super(client, { - name: 'gelbooru', - aliases: ['gelbooru-image'], - group: 'search', - memberName: 'gelbooru', - description: 'Responds with an image from Gelbooru, with optional query.', - nsfw: true, - args: [ - { - key: 'query', - prompt: 'What image would you like to search for?', - type: 'string', - default: '' - } - ] - }); - } - - async run(msg, { query }) { - try { - const { body } = await snekfetch - .get('https://gelbooru.com/index.php') - .query({ - page: 'dapi', - s: 'post', - q: 'index', - json: 1, - tags: query, - limit: 200 - }); - if (!body) return msg.say('Could not find any results.'); - return msg.say(body[Math.floor(Math.random() * body.length)].file_url); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/search/igdb.js b/commands/search/igdb.js deleted file mode 100644 index cdc7ed96..00000000 --- a/commands/search/igdb.js +++ /dev/null @@ -1,60 +0,0 @@ -const { Command } = require('discord.js-commando'); -const { MessageEmbed } = require('discord.js'); -const snekfetch = require('snekfetch'); -const { shorten } = require('../../util/Util'); -const { IGDB_KEY } = process.env; -const esrb = ['RP', 'EC', 'E', 'E10+', 'T', 'M', 'AO']; -const statuses = ['Released', '???', 'Alpha', 'Beta', 'Early Access', 'Offline', 'Cancelled']; - -module.exports = class IGDBCommand extends Command { - constructor(client) { - super(client, { - name: 'igdb', - aliases: ['igdb-video-game', 'game', 'video-game', 'game'], - group: 'search', - memberName: 'igdb', - description: 'Searches IGDB for your query.', - clientPermissions: ['EMBED_LINKS'], - args: [ - { - key: 'query', - prompt: 'What video game would you like to search for?', - type: 'string' - } - ] - }); - } - - async run(msg, { query }) { - try { - const { body } = await snekfetch - .get('https://api-2445582011268.apicast.io/games/') - .query({ - search: query, - limit: 1, - fields: '*', - 'filter[version_parent][not_exists]': 1 - }) - .set({ 'user-key': IGDB_KEY }); - const data = body[0]; - const embed = new MessageEmbed() - .setColor(0x01DF6B) - .setTitle(data.name) - .setURL(data.url) - .setAuthor('IGDB', 'https://i.imgur.com/LHLQEns.png') - .setDescription(data.summary ? shorten(data.summary) : 'No description available.') - .setThumbnail(data.cover ? data.cover.url : null) - .addField('❯ ESRB Rating', - data.esrb ? esrb[data.esrb.rating - 1] : '???', true) - .addField('❯ Release Date', - data.first_release_date ? new Date(data.first_release_date).toDateString() : '???', true) - .addField('❯ Status', - data.status ? statuses[data.status] : '???', true) - .addField('❯ Score', - data.total_rating || '???', true); - return msg.embed(embed); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/search/konachan.js b/commands/search/konachan.js deleted file mode 100644 index a56532d0..00000000 --- a/commands/search/konachan.js +++ /dev/null @@ -1,38 +0,0 @@ -const { Command } = require('discord.js-commando'); -const snekfetch = require('snekfetch'); - -module.exports = class KonachanCommand extends Command { - constructor(client) { - super(client, { - name: 'konachan', - aliases: ['konachan-image'], - group: 'search', - memberName: 'konachan', - description: 'Responds with an image from Konachan, with optional query.', - nsfw: true, - args: [ - { - key: 'query', - prompt: 'What image would you like to search for?', - type: 'string', - default: '' - } - ] - }); - } - - async run(msg, { query }) { - 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(`https:${body[0].file_url}`); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/package.json b/package.json index a82b8901..cedbf1b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "58.4.0", + "version": "59.0.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {