Allow server admins to delete tags, don't run ready functions more than needed

This commit is contained in:
TheEssem 2020-07-16 09:28:09 -05:00
parent bf14371b52
commit 617cf01090
3 changed files with 21 additions and 17 deletions

View file

@ -21,7 +21,7 @@ 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[args[1].toLowerCase()]) return `${message.author.mention}, this tag doesn't exist!`;
if (tags[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[args[1].toLowerCase()].author !== message.author.id && !message.member.permission.has("administrator") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
delete tags[args[1].toLowerCase()];
await database.query("UPDATE guilds SET tags = $1 WHERE guild_id = $2", [tags, message.channel.guild.id]);
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`;

View file

@ -12,6 +12,7 @@ const helpGenerator =
process.env.OUTPUT !== "" ? require("../utils/help.js") : null;
const twitter =
process.env.TWITTER === "true" ? require("../utils/twitter.js") : null;
let run = false;
// run when ready
module.exports = async () => {
@ -53,7 +54,7 @@ module.exports = async () => {
};
// connect to lavalink
if (!soundPlayer.status) await soundPlayer.connect();
if (!soundPlayer.status && !soundPlayer.connected) await soundPlayer.connect();
// make sure settings/tags exist
for (const [id] of client.guilds) {
@ -64,6 +65,7 @@ module.exports = async () => {
}
}
if (!run) {
const job = new cron.CronJob("0 0 * * 0", async () => {
logger.log("Deleting stale guild entries in database...");
const guildDB = await database.query("SELECT * FROM guilds");
@ -76,6 +78,7 @@ module.exports = async () => {
logger.log("Finished deleting stale entries.");
});
job.start();
}
let counts;
try {
@ -155,8 +158,6 @@ module.exports = async () => {
}
}
logger.log(
"info",
`Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`
);
logger.log(`Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
run = true;
};

View file

@ -17,6 +17,8 @@ exports.manager;
exports.status = false;
exports.connected = false;
exports.checkStatus = async () => {
const statuses = [];
for (const node of nodes) {
@ -38,6 +40,7 @@ exports.connect = async () => {
});
const { length } = await this.manager.connect();
logger.log(`Successfully connected to ${length} Lavalink node(s).`);
exports.connected = true;
this.manager.on("error", (error, node) => {
logger.error(`An error occurred on Lavalink node ${node}: ${error}`);
});