From 48c3e545afd4c7f5125171004e526c85813baac4 Mon Sep 17 00:00:00 2001 From: Matthew Ray Date: Sat, 15 Sep 2018 16:22:12 -0400 Subject: [PATCH] QoL Improvements -Prohibit some commands from being used in DMs w/ the bot -Added a rate limiting system to commands that may be abused -Only allow the invite command to be used in Development channels --- commands/info.js | 2 +- commands/invite.js | 3 ++- commands/math.js | 14 +++++++++++++- commands/ping.js | 13 ++++++++++++- commands/shiba.js | 13 ++++++++++++- commands/stats.js | 11 +++++++++++ commands/uptime.js | 12 ++++++++++++ commands/whois.js | 11 +++++++++++ 8 files changed, 74 insertions(+), 5 deletions(-) diff --git a/commands/info.js b/commands/info.js index 732d3f1..34a7bd7 100644 --- a/commands/info.js +++ b/commands/info.js @@ -18,7 +18,7 @@ exports.run = async (client, message, args, level) => { exports.conf = { enabled: true, - guildOnly: true, + guildOnly: false, aliases: ["about"], permLevel: "Standard User" }; diff --git a/commands/invite.js b/commands/invite.js index ea02b50..4b6a766 100644 --- a/commands/invite.js +++ b/commands/invite.js @@ -1,5 +1,6 @@ const Discord = require("discord.js"); -exports.run = async (client, message, args, level) => { +exports.run = async (client, message) => { + if(message.channel.id != "488762614156099585" || "489234703229124608") return; const embed = new Discord.RichEmbed() .setAuthor(`${client.user.username}`, `${client.user.avatarURL}`) .setColor(message.member.displayColor) diff --git a/commands/math.js b/commands/math.js index a079d44..9efbcca 100644 --- a/commands/math.js +++ b/commands/math.js @@ -1,10 +1,15 @@ const superagent = require('superagent'); const math = require('mathjs'); +const talkedRecently = new Set(); async function request(i) { return await superagent.get(`http://numbersapi.com/${i}?json`); } -exports.run = async (client, message, args, level) => { +exports.run = async (message, args) => { + if (talkedRecently.has(message.author.id) && !message.member.roles.has("490364533550874644")) { + + message.channel.send("You are being rate limited!" + message.author); + } else { const input = args.join(' '); const errmsg = { exp: 'Couldn\'t evaluate the given expression, please try again later.', @@ -70,7 +75,14 @@ exports.run = async (client, message, args, level) => { } return message.channel.send(result); + } +talkedRecently.add(message.author.id); +setTimeout(() => { + // Removes the user from the set after a minute + talkedRecently.delete(message.author.id); +}, 2000); + } exports.conf = { enabled: true, diff --git a/commands/ping.js b/commands/ping.js index 3cc68e0..6083ffb 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -1,5 +1,10 @@ const Discord = require("discord.js"); -exports.run = async (client, message, args, level) => { // eslint-disable-line no-unused-vars +const talkedRecently = new Set(); +exports.run = async (client, message, args, level) => { + if (talkedRecently.has(message.author.id) && !message.member.roles.has("490364533550874644")) { + + message.channel.send("You are being rate limited!" + message.author); + } else { // eslint-disable-line no-unused-vars const msg = await message.channel.send("Ping?"); const embed = new Discord.RichEmbed() .setAuthor(`${client.user.username}`, `${client.user.avatarURL}`) @@ -8,7 +13,13 @@ exports.run = async (client, message, args, level) => { // eslint-disable-line n .addField("• API Latency", `${Math.round(client.ping)}ms`, true) .setFooter(`${client.user.username} | Beta - Master`); msg.edit(embed); + talkedRecently.add(message.author.id); + setTimeout(() => { + // Removes the user from the set after a minute + talkedRecently.delete(message.author.id); + }, 2000); }; +} exports.conf = { enabled: true, diff --git a/commands/shiba.js b/commands/shiba.js index a42258e..8b15988 100644 --- a/commands/shiba.js +++ b/commands/shiba.js @@ -1,7 +1,12 @@ const Discord = require("discord.js"); const superagent = require ("superagent"); +const talkedRecently = new Set(); exports.run = async (client, message, args) => { + if (talkedRecently.has(message.author.id) && !message.member.roles.has("490364533550874644")) { + + message.channel.send("You are being rate limited!" + message.author); + } else { const {body} = await superagent .get ('http://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true'); @@ -10,7 +15,13 @@ exports.run = async (client, message, args) => { .setTitle(":dog: Woof!") .setImage(body[0]); message.channel.send(shibaembed); -}; + talkedRecently.add(message.author.id); + setTimeout(() => { + // Removes the user from the set after a minute + talkedRecently.delete(message.author.id); + }, 7500); +}; +} exports.conf = { enabled: true, guildOnly: false, diff --git a/commands/stats.js b/commands/stats.js index 23826ed..375d94f 100644 --- a/commands/stats.js +++ b/commands/stats.js @@ -1,9 +1,14 @@ const { version } = require("discord.js"); const Discord = require("discord.js"); +const talkedRecently = new Set(); const moment = require("moment"); require("moment-duration-format"); exports.run = (client, message, args, level) => { // eslint-disable-line no-unused-vars + if (talkedRecently.has(message.author.id) && !message.member.roles.has("490364533550874644")) { + + message.channel.send("You are being rate limited!" + message.author); + } else { const duration = moment.duration(client.uptime).format(" D [days], H [hrs], m [mins], s [secs]"); const embed = new Discord.RichEmbed() .setAuthor(`${client.user.username}`, `${client.user.avatarURL}`) @@ -20,6 +25,12 @@ exports.run = (client, message, args, level) => { // eslint-disable-line no-unus .setFooter(`${client.user.username} | Beta - Master`); message.channel.send(embed); }; +talkedRecently.add(message.author.id); +setTimeout(() => { + // Removes the user from the set after a minute + talkedRecently.delete(message.author.id); +}, 2000); +} exports.conf = { enabled: true, diff --git a/commands/uptime.js b/commands/uptime.js index 0c1f745..9cf7fa0 100644 --- a/commands/uptime.js +++ b/commands/uptime.js @@ -1,8 +1,14 @@ const Discord = require("discord.js"); +const talkedRecently = new Set(); const moment = require("moment"); require("moment-duration-format"); + exports.run = (client, message, args, level) => { // eslint-disable-line no-unused-vars + if (talkedRecently.has(message.author.id) && !message.member.roles.has("490364533550874644")) { + + message.channel.send("You are being rate limited!" + message.author); +} else { const duration = moment.duration(client.uptime).format(" D [days], H [hrs], m [mins], s [secs]"); const embed = new Discord.RichEmbed() .setAuthor(`${client.user.username}`, `${client.user.avatarURL}`) @@ -14,6 +20,12 @@ exports.run = (client, message, args, level) => { // eslint-disable-line no-unus message.channel.send(embed); + talkedRecently.add(message.author.id); + setTimeout(() => { + // Removes the user from the set after a minute + talkedRecently.delete(message.author.id); + }, 2000); +} }; exports.conf = { diff --git a/commands/whois.js b/commands/whois.js index f60f4a5..db41d93 100644 --- a/commands/whois.js +++ b/commands/whois.js @@ -1,4 +1,5 @@ const Discord = require("discord.js"); +const talkedRecently = new Set(); const status = { online: "Online", idle: "Idle", @@ -6,6 +7,10 @@ const status = { offline: "Offline/Invisible" }; exports.run = async (client, message, args, level) => { + if (talkedRecently.has(message.author.id) && !message.member.roles.has("490364533550874644")) { + + message.channel.send("You are being rate limited!" + message.author); + } else { if (message.mentions.users.first()) try { level = client.permlevel(message.mentions.users.first().lastMessage); @@ -48,7 +53,13 @@ exports.run = async (client, message, args, level) => { msg.edit("EXCPT*- " + err); } + talkedRecently.add(message.author.id); + setTimeout(() => { + // Removes the user from the set after a minute + talkedRecently.delete(message.author.id); + }, 2000); }; +} exports.conf = { enabled: true, guildOnly: true,