diff --git a/XiaoBot.js b/XiaoBot.js index 8e10f515..e07db4b4 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -18,7 +18,6 @@ client.registry .registerDefaultTypes() .registerGroups([ ['util', 'Utility'], - ['user-info', 'User Info'], ['guild-info', 'Server Info'], ['moderation', 'Moderation'], ['random-res', 'Random Response'], @@ -38,7 +37,8 @@ client.registry prefix: false, commandState: false }) - .registerCommandsIn(path.join(__dirname, 'commands')); + .registerCommandsIn(path.join(__dirname, 'commands')) + .registerTypesIn(path.join(__dirname, 'types')); client.on('ready', () => { console.log(`[READY] Shard ${client.shard.id} logged in as ${client.user.tag}! (${client.user.id})`); diff --git a/commands/guild-info/emoji-image.js b/commands/guild-info/emoji-image.js new file mode 100644 index 00000000..f5044f10 --- /dev/null +++ b/commands/guild-info/emoji-image.js @@ -0,0 +1,26 @@ +const { Command } = require('discord.js-commando'); + +module.exports = class EmojiImageCommand extends Command { + constructor(client) { + super(client, { + name: 'emoji-image', + aliases: ['bigify-emoji', 'emoji-url', 'big-emoji'], + group: 'guild-info', + memberName: 'emoji-image', + description: 'Responds with an emoji\'s full-scale image.', + guildOnly: true, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'emoji', + prompt: 'Which emoji would you like to get the image of?', + type: 'emoji' + } + ] + }); + } + + run(msg, { emoji }) { + return msg.say({ files: [emoji.url] }); + } +}; diff --git a/commands/guild-info/emoji-info.js b/commands/guild-info/emoji-info.js new file mode 100644 index 00000000..f7f2a722 --- /dev/null +++ b/commands/guild-info/emoji-info.js @@ -0,0 +1,38 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); + +module.exports = class EmojiInfoCommand extends Command { + constructor(client) { + super(client, { + name: 'emoji-info', + aliases: ['emoji'], + group: 'guild-info', + memberName: 'emoji-info', + description: 'Responds with detailed information on an emoji.', + guildOnly: true, + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'emoji', + prompt: 'Which emoji would you like to get information on?', + type: 'emoji' + } + ] + }); + } + + run(msg, { emoji }) { + const embed = new MessageEmbed() + .setColor(0x00AE86) + .setThumbnail(emoji.url) + .addField('❯ Name', + emoji.name, true) + .addField('❯ ID', + emoji.id, true) + .addField('❯ Creation Date', + emoji.createdAt.toDateString(), true) + .addField('❯ External', + emoji.managed ? 'Yes' : 'No', true); + return msg.embed(embed); + } +}; diff --git a/commands/guild-info/emoji.js b/commands/guild-info/emoji-list.js similarity index 79% rename from commands/guild-info/emoji.js rename to commands/guild-info/emoji-list.js index 44006814..ad03afea 100644 --- a/commands/guild-info/emoji.js +++ b/commands/guild-info/emoji-list.js @@ -1,10 +1,10 @@ const { Command } = require('discord.js-commando'); -module.exports = class EmojiCommand extends Command { +module.exports = class EmojiListCommand extends Command { constructor(client) { super(client, { - name: 'emoji', - aliases: ['emojis', 'emoji-list'], + name: 'emoji-list', + aliases: ['emojis'], group: 'guild-info', memberName: 'emoji', description: 'Responds with a list of the server\'s custom emoji.', diff --git a/commands/user-info/user-info.js b/commands/guild-info/user-info.js similarity index 98% rename from commands/user-info/user-info.js rename to commands/guild-info/user-info.js index f69487b1..5bb15b36 100644 --- a/commands/user-info/user-info.js +++ b/commands/guild-info/user-info.js @@ -6,7 +6,7 @@ module.exports = class UserInfoCommand extends Command { super(client, { name: 'user-info', aliases: ['user', 'member', 'member-info'], - group: 'user-info', + group: 'guild-info', memberName: 'user-info', description: 'Responds with detailed information on a user.', guildOnly: true, diff --git a/commands/user-info/avatar.js b/commands/random/avatar.js similarity index 96% rename from commands/user-info/avatar.js rename to commands/random/avatar.js index e02350d1..8fdb5f31 100644 --- a/commands/user-info/avatar.js +++ b/commands/random/avatar.js @@ -5,7 +5,7 @@ module.exports = class AvatarCommand extends Command { super(client, { name: 'avatar', aliases: ['profile-picture', 'profile-pic'], - group: 'user-info', + group: 'random', memberName: 'avatar', description: 'Responds with a link to a user\'s avatar.', args: [ diff --git a/package.json b/package.json index a1e64ffd..e744407c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "44.5.0", + "version": "45.0.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/types/emoji.js b/types/emoji.js new file mode 100644 index 00000000..e118812c --- /dev/null +++ b/types/emoji.js @@ -0,0 +1,37 @@ +const { ArgumentType, util } = require('discord.js-commando'); +const { escapeMarkdown } = require('discord.js'); + +class EmojiArgumentType extends ArgumentType { + constructor(client) { + super(client, 'emoji'); + } + + validate(value, msg) { + const matches = value.match(/<:([a-zA-Z0-9_]+):(\d+)>/); + if (matches) { + const emoji = msg.client.emojis.get(matches[2]); + if (emoji) return true; + } + if (!msg.guild) return false; + const search = value.toLowerCase(); + const emojis = msg.guild.emojis.filter(emoji => emoji.name.toLowerCase() === search || emoji.id === search); + if (!emojis.length) return false; + if (emojis.length === 1) return true; + return emojis.length <= 15 + ? `${util.disambiguation(emojis.map(emoji => escapeMarkdown(emoji.name)), 'emojis', null)}\n` + : 'Multiple emojis found. Please be more specific.'; + } + + parse(value, msg) { + const matches = value.match(/<:([a-zA-Z0-9_]+):(\d+)>/); + if (matches) return msg.client.emojis.get(matches[2]); + if (!msg.guild) return null; + const search = value.toLowerCase(); + const emojis = msg.guild.emojis.filter(emoji => emoji.name.toLowerCase() === search || emoji.id === search); + if (!emojis.length) return null; + if (emojis.length === 1) return emojis[0]; + return null; + } +} + +module.exports = EmojiArgumentType;