From b23cbfa10fc960a157a5a209cf80b3086930d0a9 Mon Sep 17 00:00:00 2001 From: dragonfire535 Date: Wed, 15 Mar 2017 22:57:27 -0400 Subject: [PATCH] Discrim Command and Change in Roll Regex --- commands/response/roll.js | 2 +- commands/search/discrim.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 commands/search/discrim.js diff --git a/commands/response/roll.js b/commands/response/roll.js index 350bf98f..bbaba010 100644 --- a/commands/response/roll.js +++ b/commands/response/roll.js @@ -21,7 +21,7 @@ class RollChooseCommand extends commando.Command { if(value === undefined) { let roll = Math.floor(Math.random() * 6) + 1; message.channel.send("You rolled a " + roll) - } else if(value.match("^[0-9]+$")) { + } else if(value.match(/^[0-9]+$/)) { let roll = Math.floor(Math.random() * value) + 1; message.channel.send("You rolled a " + roll); } else { diff --git a/commands/search/discrim.js b/commands/search/discrim.js new file mode 100644 index 00000000..f7dcf872 --- /dev/null +++ b/commands/search/discrim.js @@ -0,0 +1,35 @@ +const commando = require('discord.js-commando'); +const Discord = require('discord.js'); + +class DiscrimCommand extends commando.Command { + constructor(Client){ + super(Client, { + name: 'discrim', + group: 'search', + memberName: 'discrim', + description: 'Searches the server for a certain discriminator. (;discrim 8081)', + examples: [';discrim 8081'] + }); + } + + async run(message, args) { + if(message.channel.type !== 'dm') { + if(!message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) return; + if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return; + if(!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return; + } + console.log("[Command] " + message.content); + let userToSearch = message.content.split(" ").slice(1).join(" "); + if(userToSearch.match(/^[0-9]+$/) && userToSearch.split("").length === 4) { + let users = this.client.users.filter(u => u.discriminator === userToSearch).map(u => u.username).sort(); + const embed = new Discord.RichEmbed() + .setTitle(users.length + ' Users with the discriminator: ' + userToSearch) + .setDescription(users.join(', ')); + message.channel.sendEmbed(embed).catch(console.error); + } else { + message.channel.send(':x: Error! This discriminator is invalid!'); + } + } +} + +module.exports = DiscrimCommand; \ No newline at end of file