Convert database handler into service, fix skip issue with sound player
This commit is contained in:
parent
9a1fd3b6f3
commit
b2c7a43baa
13 changed files with 58 additions and 25 deletions
|
@ -1,3 +1,5 @@
|
|||
// wrapper for the database drivers in ./database/
|
||||
// wrapper for the database service
|
||||
|
||||
module.exports = require(`./database/${process.env.DB ? process.env.DB.split("://")[0] : "dummy"}.js`);
|
||||
module.exports = async (ipc, name, ...args) => {
|
||||
return ipc.command("database", { name, args }, true);
|
||||
};
|
||||
|
|
29
utils/services/database.js
Normal file
29
utils/services/database.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
// service wrapper for the database drivers in ../database/
|
||||
const { BaseServiceWorker } = require("eris-fleet");
|
||||
|
||||
const database = require(`../database/${process.env.DB ? process.env.DB.split("://")[0] : "dummy"}.js`);
|
||||
|
||||
class DatabaseWorker extends BaseServiceWorker {
|
||||
constructor(setup) {
|
||||
super(setup);
|
||||
this.serviceReady();
|
||||
}
|
||||
|
||||
async handleCommand(data) {
|
||||
try {
|
||||
if (database[data.name]) {
|
||||
return await database[data.name](...data.args);
|
||||
} else {
|
||||
throw "Unknown query";
|
||||
}
|
||||
} catch (err) {
|
||||
return { err: typeof err === "string" ? err : err.message };
|
||||
}
|
||||
}
|
||||
|
||||
shutdown(done) {
|
||||
database.stop().then(() => done);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DatabaseWorker;
|
|
@ -34,7 +34,7 @@ esmbot_connected_workers ${servers.length}
|
|||
res.write(`esmbot_max_jobs{worker="${i}"} ${w.max}\n`);
|
||||
}
|
||||
}
|
||||
const counts = await database.getCounts();
|
||||
const counts = await database(this.ipc, "getCounts");
|
||||
for (const [i, w] of Object.entries(counts)) {
|
||||
res.write(`esmbot_command_count{command="${i}"} ${w}\n`);
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ exports.play = async (client, sound, message, music = false) => {
|
|||
};
|
||||
|
||||
exports.nextSong = async (client, message, connection, track, info, music, voiceChannel, loop = false, inQueue = false, lastTrack = null) => {
|
||||
this.skipVotes.set(this.message.channel.guild.id, { count: 0, ids: [] });
|
||||
const parts = Math.floor((0 / info.length) * 10);
|
||||
let playingMessage;
|
||||
if (!music && this.players.get(voiceChannel.guild.id)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue