Added count, added some new playing lines, fixed security issue with hackban

This commit is contained in:
TheEssem 2020-04-26 16:55:33 -05:00
parent e9f4109f43
commit c65a8115aa
6 changed files with 94 additions and 4 deletions

43
commands/count.js Normal file
View file

@ -0,0 +1,43 @@
const client = require("../utils/client.js");
const paginator = require("../utils/pagination/pagination.js");
const database = require("../utils/database.js");
exports.run = async (message) => {
if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
const counts = (await database.global.findOne({}).lean().exec()).cmdCounts;
const countArray = [];
const sortedValues = Object.entries(counts).sort((a, b) => {
return b[1] - a[1];
});
console.log(sortedValues);
for (const [key, value] of sortedValues) {
countArray.push(`**${key}**: ${value}`);
}
const embeds = [];
const groups = countArray.map((item, index) => {
return index % 15 === 0 ? countArray.slice(index, index + 15) : null;
}).filter((item) => {
return item;
});
for (const [i, value] of groups.entries()) {
embeds.push({
"embed": {
"title": "Command Usage Counts",
"color": 16711680,
"footer": {
"text": `Page ${i + 1} of ${groups.length}`
},
"description": value.join("\n"),
"author": {
"name": message.author.username,
"icon_url": message.author.avatarURL
}
}
});
}
return paginator(message, embeds);
};
exports.category = 1;
exports.help = "Gets how many times every command was used";

View file

@ -1,4 +1,8 @@
const client = require("../utils/client.js");
exports.run = async (message, args) => {
if (!message.member.permission.has("banMembers")) return `${message.author.mention}, you need to have the \`Ban Members\` permission on this server to ban people!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("banMembers") && !message.channel.permissionsOf(client.user.id).has("banMembers")) return `${message.author.mention}, I don't have the \`Ban Members\` permission!`;
if (!args[0].match(/^<?[@#]?[&!]?\d+>?$/) && args[0] < 21154535154122752) return `${message.author.mention}, that's not a valid snowflake!`;
try {
const id = args[0].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", "");

View file

@ -39,6 +39,9 @@ module.exports = async (message) => {
// actually run the command
logger.log("info", `${message.author.username} (${message.author.id}) ran command ${command}`);
try {
const global = (await database.global.findOne({}).exec());
global.cmdCounts.set(collections.aliases.has(command) ? collections.aliases.get(command) : command, global.cmdCounts.get(command) + 1);
await global.save();
const result = await cmd(message, args, content.replace(command, "").trim()); // we also provide the message content as a parameter for cases where we need more accuracy
if (typeof result === "string" || (typeof result === "object" && result.embed)) {
await client.createMessage(message.channel.id, result);

View file

@ -2,6 +2,7 @@ const gm = require("gm");
const { promisify } = require("util");
const client = require("../utils/client.js");
const database = require("../utils/database.js");
const collections = require("../utils/collections.js");
const logger = require("../utils/logger.js");
const messages = require("../messages.json");
const misc = require("../utils/misc.js");
@ -16,11 +17,11 @@ module.exports = async () => {
for (const [id] of client.guilds) {
const guildDB = (
await database.guilds
.find({
.findOne({
id: id,
})
.exec()
)[0];
);
if (!guildDB) {
logger.log(`Registering guild database entry for guild ${id}...`);
const newGuild = new database.guilds({
@ -44,6 +45,25 @@ module.exports = async () => {
}
}
const global = (await database.global.findOne({}).exec());
if (!global) {
const countObject = {};
for (const command of collections.commands.keys()) {
countObject[command] = 0;
}
const newGlobal = new database.global({
cmdCounts: countObject
});
await newGlobal.save();
} else {
for (const command of collections.commands.keys()) {
if (!global.cmdCounts.has(command)) {
global.cmdCounts.set(command, 0);
await global.save();
}
}
}
// generate docs
if (helpGenerator) {
await helpGenerator(process.env.OUTPUT);

View file

@ -88,5 +88,19 @@
"XMPlay",
"OpenMPT",
"follow @esmBot_ on Twitter",
"with GIFs"
"with GIFs",
"check out more stuff at projectlounge.pw",
"the",
"sissy hypnosis",
"Yandere Simulator",
"PogChamp",
"yourself",
"sentience",
"with Brody Foxx",
"AOL Instant Messenger",
"beep boop",
"Animal Crossing: New Horizons",
"Hello, Gordon!",
"the j",
"Want esmBot to play some new games? Send suggestions!"
]

View file

@ -22,5 +22,11 @@ const tweetSchema = new mongoose.Schema({
});
const TweetCollection = mongoose.model("TweetCollection", tweetSchema);
const globalSchema = new mongoose.Schema({
cmdCounts: Map
});
const Global = mongoose.model("Global", globalSchema);
exports.guilds = Guild;
exports.tweets = TweetCollection;
exports.global = Global;