From ed9621c4089e6b1ae74544322d1977dddce08c82 Mon Sep 17 00:00:00 2001 From: Matthew Ray Date: Sun, 16 Sep 2018 01:29:53 -0400 Subject: [PATCH] Add cooldowns and optional Sharding --- commands/invite.js | 24 ++++++++++++----- commands/math.js | 15 ++--------- commands/ping.js | 6 ++--- commands/serverinfo.js | 58 ++++++++++++++++++++++++++++++++++++++++++ commands/whois.js | 1 + index.js | 6 +++-- shard.js | 3 +++ 7 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 commands/serverinfo.js create mode 100644 shard.js diff --git a/commands/invite.js b/commands/invite.js index 4b6a766..813bdcb 100644 --- a/commands/invite.js +++ b/commands/invite.js @@ -1,17 +1,29 @@ const Discord = require("discord.js"); 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) .addField("Invite Link", "https://discordapp.com/api/oauth2/authorize?client_id=460639060851949569&permissions=8&scope=bot", true) - .setFooter("client.user.username | Beta - Master"); - message.channel.send(embed); - }; + .setFooter(`${client.user.username} | Beta - Master`); + message.member.user.createDM().then(channel => channel.send(embed)) + + const em1 = new Discord.RichEmbed() + .setAuthor(`${client.user.username}`, `${client.user.avatarURL}`) + .setColor(message.member.displayColor) + .setDescription("Invite link sent, check your DMs.") + .setFooter(`${client.user.username} | Beta - Master`); + message.channel.send(em1) +}; + + + + exports.conf = { enabled: true, - guildOnly: true, + guildOnly: false, aliases: ["get", "join"], permLevel: "Systems Alpha/Dev Tester" }; @@ -19,6 +31,6 @@ const embed = new Discord.RichEmbed() exports.help = { name: "invite", category: "Bot Information", - description: "Provides the invite link.", + description: "Provides the bot's invite link.", usage: "invite" }; diff --git a/commands/math.js b/commands/math.js index 9efbcca..5ee7bfe 100644 --- a/commands/math.js +++ b/commands/math.js @@ -1,15 +1,10 @@ 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 (message, args) => { - if (talkedRecently.has(message.author.id) && !message.member.roles.has("490364533550874644")) { - - message.channel.send("You are being rate limited!" + message.author); - } else { +exports.run = async (client, message, args, level) => { const input = args.join(' '); const errmsg = { exp: 'Couldn\'t evaluate the given expression, please try again later.', @@ -75,14 +70,8 @@ exports.run = async (message, args) => { } 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 6083ffb..ed0abe9 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -1,13 +1,13 @@ const Discord = require("discord.js"); const talkedRecently = new Set(); -exports.run = async (client, message, args, level) => { +exports.run = async (client, message) => { 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}`) + .setAuthor(`${client.user.username}`, `${client.user.avatarURL}`) .setColor(message.member.displayColor) .addField("• Ping Latency", `${msg.createdTimestamp - message.createdTimestamp}ms`, true) .addField("• API Latency", `${Math.round(client.ping)}ms`, true) @@ -31,6 +31,6 @@ exports.conf = { exports.help = { name: "ping", category: "Misc", - description: "Pings the bot, responses with API and regular latencies.", + description: "Pings the bot, responds with API and regular latencies.", usage: "ping" }; diff --git a/commands/serverinfo.js b/commands/serverinfo.js new file mode 100644 index 0000000..94623e6 --- /dev/null +++ b/commands/serverinfo.js @@ -0,0 +1,58 @@ +const Discord = require("discord.js"); +const talkedRecently = new Set(); +exports.run = async (client, message) => { + 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("Loading... *If you are seeing this message longer than 5 seconds, an error may have occurred.*"); + function checkBots(guild) { + let botCount = 0; + guild.members.forEach(member => { + if(member.user.bot) botCount++; + }); + return botCount; + } + function checkMembers(guild) { + let memberCount = 0; + guild.members.forEach(member => { + if(!member.user.bot) memberCount++; + }); + return memberCount; + } + const embed = new Discord.RichEmbed() + .setAuthor(`${client.user.username}`, `${client.user.avatarURL}`) + .setTitle("Server Information") + .setThumbnail(message.guild.iconURL) + .setColor(message.member.displayColor) + .addField('Server Owner', message.guild.owner, true) + .addField('Server Region', message.guild.region, true) + .addField('Channels', message.guild.channels.size, false) + .addField("Created", `${message.guild.createdAt}`, false) + .addField('Members', message.guild.memberCount, true) + .addField('Humans', checkMembers(message.guild), true) + .addField('Bots', checkBots(message.guild), true) + .addField('Verification Level', message.guild.verificationLevel, 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, + guildOnly: true, + aliases: [], + permLevel: "Standard User" +}; + +exports.help = { + name: "serverinfo", + category: "Misc", + description: "Provides information about the current guild.", + usage: "serverinfo" +}; diff --git a/commands/whois.js b/commands/whois.js index db41d93..86e9de8 100644 --- a/commands/whois.js +++ b/commands/whois.js @@ -36,6 +36,7 @@ exports.run = async (client, message, args, level) => { const embed = new Discord.RichEmbed() .setAuthor(botuser.displayName, botuser.user.avatarURL) + .setThumbnail(message.author.avatarURL) .setColor(botuser.displayColor) .addField("Joined Server At", `${botuser.joinedAt}`, true) .addField("Created Account At", `${botuser.user.createdAt}`, true) diff --git a/index.js b/index.js index cfebd48..39bab9a 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,14 @@ if (Number(process.version.slice(1).split(".")[0]) < 8) throw new Error("Node 8.0.0 or higher is required. Update Node on your system."); -const Discord = require("discord.js"); +const Discord = require("discord.js") const { promisify } = require("util"); const readdir = promisify(require("fs").readdir); const Enmap = require("enmap"); const EnmapLevel = require("enmap-sqlite"); -const client = new Discord.Client(); +const client = new Discord.Client({ + fetchAllMembers: true}) + client.config = require("./config.js"); // client.config.token contains the bot's token diff --git a/shard.js b/shard.js new file mode 100644 index 0000000..8e3e121 --- /dev/null +++ b/shard.js @@ -0,0 +1,3 @@ +const Discord = require('discord.js'); +const Manager = new Discord.ShardingManager('./index.js'); +Manager.spawn(2); // This example will spawn 2 shards (5,000 guilds); \ No newline at end of file