Added ability to disable tags for a server, added way to remove warnings
This commit is contained in:
parent
8b346240e9
commit
e0d7ea7a57
5 changed files with 52 additions and 24 deletions
|
@ -5,8 +5,9 @@ const { random } = require("../utils/misc.js");
|
||||||
|
|
||||||
exports.run = async (message, args) => {
|
exports.run = async (message, args) => {
|
||||||
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
|
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 });
|
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 tags = guild.tags;
|
||||||
const blacklist = ["add", "edit", "remove", "delete", "list", "random"];
|
const blacklist = ["add", "edit", "remove", "delete", "list", "random"];
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
|
@ -21,14 +22,14 @@ exports.run = async (message, args) => {
|
||||||
case "remove":
|
case "remove":
|
||||||
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to delete!`;
|
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.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);
|
tags.set(args[1].toLowerCase(), undefined);
|
||||||
await guild.save();
|
await guild.save();
|
||||||
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`;
|
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`;
|
||||||
case "edit":
|
case "edit":
|
||||||
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to 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.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);
|
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
|
||||||
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been edited!`;
|
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been edited!`;
|
||||||
case "own":
|
case "own":
|
||||||
|
@ -67,6 +68,18 @@ exports.run = async (message, args) => {
|
||||||
return paginator(message, embeds);
|
return paginator(message, embeds);
|
||||||
case "random":
|
case "random":
|
||||||
return random([...tags])[1].content;
|
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:
|
default:
|
||||||
if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||||
return tags.get(args[0].toLowerCase()).content;
|
return tags.get(args[0].toLowerCase()).content;
|
||||||
|
@ -96,11 +109,14 @@ exports.help = {
|
||||||
delete: "Deletes a tag",
|
delete: "Deletes a tag",
|
||||||
edit: "Edits a tag",
|
edit: "Edits a tag",
|
||||||
list: "Lists all tags in the server",
|
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 = {
|
exports.params = {
|
||||||
default: "[name]",
|
default: "[name]",
|
||||||
add: "[name] [content]",
|
add: "[name] [content]",
|
||||||
delete: "[name]",
|
delete: "[name]",
|
||||||
edit: "[name] [content]"
|
edit: "[name] [content]",
|
||||||
|
owner: "[name]"
|
||||||
};
|
};
|
|
@ -5,26 +5,13 @@ const paginator = require("../utils/pagination/pagination.js");
|
||||||
exports.run = async (message, args) => {
|
exports.run = async (message, args) => {
|
||||||
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
|
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 (!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 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, ""));
|
const member = memberCheck ? memberCheck : client.users.get(args[0].replace(/\D/g, ""));
|
||||||
if (member) {
|
if (member) {
|
||||||
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
|
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
|
||||||
const array = guild.warns.get(member.id) ? guild.warns.get(member.id).warns : [];
|
const array = guild.warns.get(member.id) ? guild.warns.get(member.id).warns : [];
|
||||||
if (args[1].toLowerCase() !== "list") {
|
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("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!`;
|
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 = [];
|
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!`;
|
if (embeds.length === 0) return `${message.author.mention}, I couldn't find any warns for this user!`;
|
||||||
return paginator(message, embeds);
|
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 {
|
} else {
|
||||||
return `${message.author.mention}, you need to provide a member to warn!`;
|
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.category = 2;
|
||||||
exports.help = "Warns a server member";
|
exports.help = "Warns a server member";
|
||||||
exports.params = "[mention] {reason/list}";
|
exports.params = "[mention] {reason/list/remove} {number}";
|
|
@ -11,7 +11,8 @@ module.exports = async (guild) => {
|
||||||
tags: misc.tagDefaults,
|
tags: misc.tagDefaults,
|
||||||
prefix: "&",
|
prefix: "&",
|
||||||
warns: {},
|
warns: {},
|
||||||
disabledChannels: []
|
disabledChannels: [],
|
||||||
|
tagsDisabled: false
|
||||||
});
|
});
|
||||||
await guildDB.save();
|
await guildDB.save();
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,8 @@ module.exports = async () => {
|
||||||
tags: misc.tagDefaults,
|
tags: misc.tagDefaults,
|
||||||
prefix: "&",
|
prefix: "&",
|
||||||
warns: {},
|
warns: {},
|
||||||
disabledChannels: []
|
disabledChannels: [],
|
||||||
|
tagsDisabled: false
|
||||||
});
|
});
|
||||||
await newGuild.save();
|
await newGuild.save();
|
||||||
} else if (guildDB) {
|
} else if (guildDB) {
|
||||||
|
|
|
@ -6,7 +6,8 @@ const guildSchema = new mongoose.Schema({
|
||||||
tags: Map,
|
tags: Map,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
warns: Map,
|
warns: Map,
|
||||||
disabledChannels: [String]
|
disabledChannels: [String],
|
||||||
|
tagsDisabled: Boolean
|
||||||
});
|
});
|
||||||
const Guild = mongoose.model("Guild", guildSchema);
|
const Guild = mongoose.model("Guild", guildSchema);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue