Convert database handler into service, fix skip issue with sound player

This commit is contained in:
Essem 2021-08-10 16:34:29 -05:00
parent 9a1fd3b6f3
commit b2c7a43baa
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
13 changed files with 58 additions and 25 deletions

View file

@ -4,5 +4,5 @@ const logger = require("../utils/logger.js");
// run when the bot is added to a guild
module.exports = async (client, cluster, worker, ipc, guild) => {
logger.log(`[GUILD JOIN] ${guild.name} (${guild.id}) added the bot.`);
await db.addGuild(guild);
await db(ipc, "addGuild", guild);
};

View file

@ -20,9 +20,9 @@ module.exports = async (client, cluster, worker, ipc, message) => {
if (cachedPrefix) {
prefixCandidate = cachedPrefix;
} else {
let guildDB = await database.getGuild(message.channel.guild.id);
let guildDB = await database(ipc, "getGuild", message.channel.guild.id);
if (!guildDB) {
guildDB = await database.fixGuild(message.channel.guild);
guildDB = await database(ipc, "fixGuild", message.channel.guild);
}
prefixCandidate = guildDB.prefix;
collections.prefixCache.set(message.channel.guild.id, guildDB.prefix);
@ -64,7 +64,7 @@ module.exports = async (client, cluster, worker, ipc, message) => {
const disabled = collections.disabledCache.get(message.channel.guild.id);
if (disabled.includes(message.channel.id) && command != "channel") return;
} else if (message.channel.guild) {
const guildDB = await database.getGuild(message.channel.guild.id);
const guildDB = await database(ipc, "getGuild", message.channel.guild.id);
collections.disabledCache.set(message.channel.guild.id, guildDB.disabled);
if (guildDB.disabled.includes(message.channel.id) && command !== "channel") return;
}
@ -88,7 +88,7 @@ module.exports = async (client, cluster, worker, ipc, message) => {
}
};
try {
await database.addCount(collections.aliases.has(command) ? collections.aliases.get(command) : command);
await database(ipc, "addCount", collections.aliases.has(command) ? collections.aliases.get(command) : command);
const startTime = new Date();
// eslint-disable-next-line no-unused-vars
const commandClass = new cmd(client, cluster, worker, ipc, message, parsed._, message.content.substring(prefix.length).trim().replace(command, "").trim(), (({ _, ...o }) => o)(parsed)); // we also provide the message content as a parameter for cases where we need more accuracy