Added ability to disable tags for a server, added way to remove warnings

This commit is contained in:
TheEssem 2020-09-03 14:26:39 -05:00
parent 8b346240e9
commit e0d7ea7a57
5 changed files with 52 additions and 24 deletions

View file

@ -5,8 +5,9 @@ const { random } = require("../utils/misc.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (args.length === 0) return `${message.author.mention}, you need to specify the name of the tag you want to view!`;
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
if (guild.tagsDisabled && args[0].toLowerCase() !== ("enable" || "disable")) return;
if (args.length === 0) return `${message.author.mention}, you need to specify the name of the tag you want to view!`;
const tags = guild.tags;
const blacklist = ["add", "edit", "remove", "delete", "list", "random"];
switch (args[0].toLowerCase()) {
@ -21,14 +22,14 @@ exports.run = async (message, args) => {
case "remove":
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to delete!`;
if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
if (tags.get(args[1].toLowerCase()).author !== message.author.id && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
if (tags.get(args[1].toLowerCase()).author !== message.author.id && !message.member.permission.has("manageMessages") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
tags.set(args[1].toLowerCase(), undefined);
await guild.save();
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`;
case "edit":
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to edit!`;
if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
if (tags.get(args[1].toLowerCase()).author !== message.author.id && tags.get(args[1].toLowerCase()).author !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
if (tags.get(args[1].toLowerCase()).author !== message.author.id && !message.member.permission.has("manageMessages") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been edited!`;
case "own":
@ -67,6 +68,18 @@ exports.run = async (message, args) => {
return paginator(message, embeds);
case "random":
return random([...tags])[1].content;
case "enable":
case "disable":
if (!message.member.permission.has("manageMessages") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't have permission to disable tags!`;
var status;
if (guild.tagsDisabled) {
status = false;
} else {
status = true;
}
guild.set("tagsDisabled", status);
await guild.save();
return `${message.author.mention}, tags for this guild have been ${status ? "disabled" : "enabled"}. To ${status ? "enable" : "disable"} them again, run ${guild.prefix}tags ${status ? "enable" : "disable"}.`;
default:
if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
return tags.get(args[0].toLowerCase()).content;
@ -96,11 +109,14 @@ exports.help = {
delete: "Deletes a tag",
edit: "Edits a tag",
list: "Lists all tags in the server",
random: "Gets a random tag"
random: "Gets a random tag",
owner: "Gets the owner of a tag",
disable: "Disables/Enables the tag system"
};
exports.params = {
default: "[name]",
add: "[name] [content]",
delete: "[name]",
edit: "[name] [content]"
edit: "[name] [content]",
owner: "[name]"
};

View file

@ -5,26 +5,13 @@ const paginator = require("../utils/pagination/pagination.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("manageMessages")) return `${message.author.mention}, you need to have the \`Manage Messages\` permission on this server to warn people!`;
if (!args[0]) return `${message.author.mention}, you need to provide a member to warn!`;
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.findOne({ id: message.channel.guild.id });
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 (args[1].toLowerCase() === "list") {
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 = [];
@ -56,6 +43,28 @@ exports.run = async (message, args) => {
}
if (embeds.length === 0) return `${message.author.mention}, I couldn't find any warns for this user!`;
return paginator(message, embeds);
} else if (args[1].toLowerCase() === "remove") {
if (args[2] < 1 || !array[args[2] - 1]) return `${message.author.mention}, there aren't any warns with that ID!`;
array.splice(args[2] - 1, 1);
guild.warns.set(member.id, {
count: guild.warns.get(member.id).count - 1,
warns: array
});
await guild.save();
return `Successfully removed the warning for ${member.mention}.`;
} else {
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();
return `Successfully warned ${member.mention} for \`${args.join(" ")}\`.`;
}
} else {
return `${message.author.mention}, you need to provide a member to warn!`;
@ -64,4 +73,4 @@ exports.run = async (message, args) => {
exports.category = 2;
exports.help = "Warns a server member";
exports.params = "[mention] {reason/list}";
exports.params = "[mention] {reason/list/remove} {number}";

View file

@ -11,7 +11,8 @@ module.exports = async (guild) => {
tags: misc.tagDefaults,
prefix: "&",
warns: {},
disabledChannels: []
disabledChannels: [],
tagsDisabled: false
});
await guildDB.save();
};

View file

@ -26,7 +26,8 @@ module.exports = async () => {
tags: misc.tagDefaults,
prefix: "&",
warns: {},
disabledChannels: []
disabledChannels: [],
tagsDisabled: false
});
await newGuild.save();
} else if (guildDB) {

View file

@ -6,7 +6,8 @@ const guildSchema = new mongoose.Schema({
tags: Map,
prefix: String,
warns: Map,
disabledChannels: [String]
disabledChannels: [String],
tagsDisabled: Boolean
});
const Guild = mongoose.model("Guild", guildSchema);