Added warn
This commit is contained in:
parent
a839b3b9c8
commit
903130dce1
4 changed files with 80 additions and 6 deletions
68
commands/warn.js
Normal file
68
commands/warn.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
const database = require("../utils/database.js");
|
||||
const client = require("../utils/client.js");
|
||||
const paginator = require("../utils/pagination/pagination.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
if (!message.member.permission.has("manageMessages")) return `${message.author.mention}, you need to have the \`Manage Messages\` permission on this server to warn people!`;
|
||||
const memberCheck = message.mentions.length >= 1 ? message.mentions[0] : client.users.get(args[0]);
|
||||
const member = memberCheck ? memberCheck : client.users.get(args[0].replace(/\D/g, ""));
|
||||
if (member) {
|
||||
const guild = (await database.guilds.find({
|
||||
id: message.channel.guild.id
|
||||
}).exec())[0];
|
||||
const array = guild.warns.get(member.id) ? guild.warns.get(member.id).warns : [];
|
||||
if (args[1].toLowerCase() !== "list") {
|
||||
args.shift();
|
||||
array.push({
|
||||
message: args.join(" "),
|
||||
time: new Date(),
|
||||
creator: message.author.id
|
||||
});
|
||||
guild.warns.set(member.id, {
|
||||
count: (guild.warns.get(member.id) ? guild.warns.get(member.id).count : 0) + 1,
|
||||
warns: array
|
||||
});
|
||||
await guild.save();
|
||||
//await message.channel.guild.banMember(member.id, 0, `ban command used by @${message.author.username}#${message.author.discriminator}`);
|
||||
return `Successfully warned ${member.mention} for \`${args.join(" ")}\`.`;
|
||||
} else {
|
||||
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 warnArray = [];
|
||||
for (const [i, value] of array.entries()) {
|
||||
warnArray.push(`**${i + 1}: Added by ${message.channel.guild.members.get(value.creator).username}#${message.channel.guild.members.get(value.creator).discriminator}**: ${value.message} (${value.time.toUTCString()})`);
|
||||
}
|
||||
const pageSize = 15;
|
||||
const embeds = [];
|
||||
const groups = warnArray.map((item, index) => {
|
||||
return index % pageSize === 0 ? warnArray.slice(index, index + pageSize) : null;
|
||||
}).filter((item) => {
|
||||
return item;
|
||||
});
|
||||
for (const [i, value] of groups.entries()) {
|
||||
embeds.push({
|
||||
"embed": {
|
||||
"title": "Warn List",
|
||||
"color": 16711680,
|
||||
"footer": {
|
||||
"text": `Page ${i + 1} of ${groups.length}`
|
||||
},
|
||||
"description": value.join("\n"),
|
||||
"author": {
|
||||
"name": member.username,
|
||||
"icon_url": member.avatarURL
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (embeds.length === 0) return `${message.author.mention}, I couldn't find any warns for this user!`;
|
||||
return paginator(message, embeds);
|
||||
}
|
||||
} else {
|
||||
return `${message.author.mention}, you need to provide a member to warn!`;
|
||||
}
|
||||
};
|
||||
|
||||
exports.category = 2;
|
||||
exports.help = "Warns a server member";
|
||||
exports.params = "[mention] {reason/list}";
|
|
@ -9,7 +9,8 @@ module.exports = async (guild) => {
|
|||
const guildDB = new db.guilds({
|
||||
id: guild.id,
|
||||
tags: misc.tagDefaults,
|
||||
prefix: "&"
|
||||
prefix: "&",
|
||||
warns: {}
|
||||
});
|
||||
await guildDB.save();
|
||||
};
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
const gm = require("gm");
|
||||
const {
|
||||
promisify
|
||||
} = require("util");
|
||||
const { promisify } = require("util");
|
||||
const client = require("../utils/client.js");
|
||||
const database = require("../utils/database.js");
|
||||
const logger = require("../utils/logger.js");
|
||||
|
@ -22,10 +20,16 @@ module.exports = async () => {
|
|||
const newGuild = new database.guilds({
|
||||
id: id,
|
||||
tags: misc.tagDefaults,
|
||||
prefix: "&"
|
||||
prefix: "&",
|
||||
warns: {}
|
||||
});
|
||||
await newGuild.save();
|
||||
}
|
||||
if (!guildDB.warns) {
|
||||
logger.log(`Creating warn object for guild ${id}...`);
|
||||
guildDB.set("warns", {});
|
||||
await guildDB.save();
|
||||
}
|
||||
}
|
||||
|
||||
// generate docs
|
||||
|
|
|
@ -4,7 +4,8 @@ mongoose.connect(process.env.MONGO);
|
|||
const guildSchema = new mongoose.Schema({
|
||||
id: String,
|
||||
tags: Map,
|
||||
prefix: String
|
||||
prefix: String,
|
||||
warns: Map
|
||||
});
|
||||
const Guild = mongoose.model("Guild", guildSchema);
|
||||
|
||||
|
|
Loading…
Reference in a new issue