Allow server admins to delete tags, don't run ready functions more than needed
This commit is contained in:
parent
bf14371b52
commit
617cf01090
3 changed files with 21 additions and 17 deletions
|
@ -21,7 +21,7 @@ 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[args[1].toLowerCase()]) return `${message.author.mention}, this tag doesn't exist!`;
|
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()];
|
delete tags[args[1].toLowerCase()];
|
||||||
await database.query("UPDATE guilds SET tags = $1 WHERE guild_id = $2", [tags, message.channel.guild.id]);
|
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!`;
|
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`;
|
||||||
|
|
|
@ -12,6 +12,7 @@ const helpGenerator =
|
||||||
process.env.OUTPUT !== "" ? require("../utils/help.js") : null;
|
process.env.OUTPUT !== "" ? require("../utils/help.js") : null;
|
||||||
const twitter =
|
const twitter =
|
||||||
process.env.TWITTER === "true" ? require("../utils/twitter.js") : null;
|
process.env.TWITTER === "true" ? require("../utils/twitter.js") : null;
|
||||||
|
let run = false;
|
||||||
|
|
||||||
// run when ready
|
// run when ready
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
|
@ -53,7 +54,7 @@ module.exports = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// connect to lavalink
|
// connect to lavalink
|
||||||
if (!soundPlayer.status) await soundPlayer.connect();
|
if (!soundPlayer.status && !soundPlayer.connected) await soundPlayer.connect();
|
||||||
|
|
||||||
// make sure settings/tags exist
|
// make sure settings/tags exist
|
||||||
for (const [id] of client.guilds) {
|
for (const [id] of client.guilds) {
|
||||||
|
@ -64,18 +65,20 @@ module.exports = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const job = new cron.CronJob("0 0 * * 0", async () => {
|
if (!run) {
|
||||||
logger.log("Deleting stale guild entries in database...");
|
const job = new cron.CronJob("0 0 * * 0", async () => {
|
||||||
const guildDB = await database.query("SELECT * FROM guilds");
|
logger.log("Deleting stale guild entries in database...");
|
||||||
for (const { guild_id } of guildDB.rows) {
|
const guildDB = await database.query("SELECT * FROM guilds");
|
||||||
if (!client.guilds.get(guild_id)) {
|
for (const { guild_id } of guildDB.rows) {
|
||||||
await database.query("DELETE FROM guilds WHERE guild_id = $1", [guild_id]);
|
if (!client.guilds.get(guild_id)) {
|
||||||
logger.log(`Deleted entry for guild ID ${guild_id}.`);
|
await database.query("DELETE FROM guilds WHERE guild_id = $1", [guild_id]);
|
||||||
|
logger.log(`Deleted entry for guild ID ${guild_id}.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
logger.log("Finished deleting stale entries.");
|
||||||
logger.log("Finished deleting stale entries.");
|
});
|
||||||
});
|
job.start();
|
||||||
job.start();
|
}
|
||||||
|
|
||||||
let counts;
|
let counts;
|
||||||
try {
|
try {
|
||||||
|
@ -155,8 +158,6 @@ module.exports = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log(
|
logger.log(`Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
|
||||||
"info",
|
run = true;
|
||||||
`Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,8 @@ exports.manager;
|
||||||
|
|
||||||
exports.status = false;
|
exports.status = false;
|
||||||
|
|
||||||
|
exports.connected = false;
|
||||||
|
|
||||||
exports.checkStatus = async () => {
|
exports.checkStatus = async () => {
|
||||||
const statuses = [];
|
const statuses = [];
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
|
@ -38,6 +40,7 @@ exports.connect = async () => {
|
||||||
});
|
});
|
||||||
const { length } = await this.manager.connect();
|
const { length } = await this.manager.connect();
|
||||||
logger.log(`Successfully connected to ${length} Lavalink node(s).`);
|
logger.log(`Successfully connected to ${length} Lavalink node(s).`);
|
||||||
|
exports.connected = true;
|
||||||
this.manager.on("error", (error, node) => {
|
this.manager.on("error", (error, node) => {
|
||||||
logger.error(`An error occurred on Lavalink node ${node}: ${error}`);
|
logger.error(`An error occurred on Lavalink node ${node}: ${error}`);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue