Port to eris-fleet

This commit is contained in:
Essem 2021-07-04 23:15:27 -05:00
parent 0af6533276
commit 299663adf8
No known key found for this signature in database
GPG Key ID: 2502A99EDC3F6FB9
17 changed files with 115 additions and 231 deletions

36
app.js
View File

@ -6,14 +6,23 @@ The bot will continue to run past this message, but keep in mind that it could b
require("dotenv").config();
// main sharding manager
const { Master } = require("eris-sharder");
const { Fleet } = require("eris-fleet");
const { isMaster } = require("cluster");
const path = require("path");
const { inspect } = require("util");
// dbl posting
const TopGG = require("@top-gg/sdk");
const dbl = process.env.NODE_ENV === "production" && process.env.DBL !== "" ? new TopGG.Api(process.env.DBL) : null;
const master = new Master(`Bot ${process.env.TOKEN}`, "/shard.js", {
name: "esmBot",
stats: true,
const Admiral = new Fleet({
path: path.join(__dirname, "./shard.js"),
token: `Bot ${process.env.TOKEN}`,
startingStatus: {
status: "idle",
game: {
name: "Starting esmBot..."
}
},
clientOptions: {
disableEvents: {
CHANNEL_DELETE: true,
@ -48,13 +57,18 @@ const master = new Master(`Bot ${process.env.TOKEN}`, "/shard.js", {
}
});
master.on("stats", async (stats) => {
master.broadcast(0, Object.assign(stats, { _eventName: "stat" }));
// dbl posting
if (isMaster) {
Admiral.on("log", (m) => console.log(m));
Admiral.on("debug", (m) => console.debug(m));
Admiral.on("warn", (m) => console.warn(m));
Admiral.on("error", (m) => console.error(inspect(m)));
if (dbl) {
await dbl.postStats({
serverCount: stats.guilds,
shardCount: await master.calculateShards()
Admiral.on("stats", async (m) => {
await dbl.postStats({
serverCount: m.guilds,
shardCount: m.shardCount
});
});
}
});
}

View File

@ -1,7 +1,8 @@
class Command {
constructor(client, cluster, ipc, message, args, content, specialArgs) {
constructor(client, cluster, worker, ipc, message, args, content, specialArgs) {
this.client = client;
this.cluster = cluster;
this.worker = worker;
this.ipc = ipc;
this.message = message;
this.args = args;

View File

@ -2,7 +2,7 @@ const Command = require("./command.js");
const soundPlayer = require("../utils/soundplayer.js");
class MusicCommand extends Command {
constructor(client, cluster, ipc, message, args, content, specialArgs) {
constructor(client, cluster, worker, ipc, message, args, content, specialArgs) {
super(client, cluster, ipc, message, args, content, specialArgs);
this.connection = soundPlayer.players.get(message.channel.guild.id);
}

View File

@ -1,10 +1,10 @@
const { version } = require("../../package.json");
const collections = require("../../utils/collections.js");
const Command = require("../../classes/command.js");
class InfoCommand extends Command {
async run() {
const owner = await this.ipc.fetchUser(process.env.OWNER);
const stats = await this.ipc.getStats();
return {
"embed": {
"color": 16711680,
@ -23,7 +23,7 @@ class InfoCommand extends Command {
},
{
"name": "💬 Total Servers:",
"value": collections.stats.guilds ? collections.stats.guilds : `${this.client.guilds.size} (for this cluster only)`
"value": stats.guilds ? stats.guilds : `${this.client.guilds.size} (for this cluster only)`
},
{
"name": "✅ Official Server:",

View File

@ -11,7 +11,8 @@ class RestartCommand extends Command {
for (const command of collections.commands) {
await handler.unload(command);
}
this.ipc.broadcast("restart");
this.ipc.restartAllClusters();
//this.ipc.broadcast("restart");
}
static description = "Restarts me";

View File

@ -1,5 +1,4 @@
const { version } = require("../../package.json");
const collections = require("../../utils/collections.js");
const day = require("dayjs");
day.extend(require("dayjs/plugin/duration"));
const os = require("os");
@ -10,6 +9,7 @@ class StatsCommand extends Command {
const duration = day.duration(this.client.uptime).format(" D [days], H [hrs], m [mins], s [secs]");
const uptime = day.duration(process.uptime(), "seconds").format(" D [days], H [hrs], m [mins], s [secs]");
const owner = await this.ipc.fetchUser(process.env.OWNER);
const stats = await this.ipc.getStats();
return {
embed: {
"author": {
@ -24,12 +24,12 @@ class StatsCommand extends Command {
},
{
"name": "Cluster Memory Usage",
"value": `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`,
"value": `${stats.clusters[this.cluster].ram.toFixed(2)} MB`,
"inline": true
},
{
"name": "Total Memory Usage",
"value": collections.stats.totalRam ? `${collections.stats.totalRam.toFixed(2)} MB` : "Unknown",
"value": stats.totalRam ? `${stats.totalRam.toFixed(2)} MB` : "Unknown",
"inline": true
},
{
@ -66,12 +66,12 @@ class StatsCommand extends Command {
},
{
"name": "Servers",
"value": collections.stats.guilds ? collections.stats.guilds : `${this.client.guilds.size} (for this cluster only)`,
"value": stats.guilds ? stats.guilds : `${this.client.guilds.size} (for this cluster only)`,
"inline": true
},
{
"name": "Users (approximation)",
"value": collections.stats.users ? collections.stats.users : `${this.client.users.size} (for this cluster only)`,
"value": stats.users ? stats.users : `${this.client.users.size} (for this cluster only)`,
"inline": true
}
]

View File

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

View File

@ -1,6 +1,6 @@
const logger = require("../utils/logger.js");
// run when the bot is removed from a guild
module.exports = async (client, cluster, ipc, guild) => {
module.exports = async (client, cluster, worker, ipc, guild) => {
logger.log(`[GUILD LEAVE] ${guild.name} (${guild.id}) removed the bot.`);
};

View File

@ -5,7 +5,7 @@ const collections = require("../utils/collections.js");
const parseCommand = require("../utils/parseCommand.js");
// run when someone sends a message
module.exports = async (client, cluster, ipc, message) => {
module.exports = async (client, cluster, worker, ipc, message) => {
// ignore dms and other bots
if (message.author.bot) return;
@ -88,7 +88,7 @@ module.exports = async (client, cluster, ipc, message) => {
await database.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, 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
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
const result = await commandClass.run();
const endTime = new Date();
if ((endTime - startTime) >= 180000) reference.allowedMentions.repliedUser = true;

View File

@ -1,7 +1,7 @@
const player = require("../utils/soundplayer.js");
// run when a raw packet is sent, used for sending data to lavalink
module.exports = async (client, cluster, ipc, packet) => {
module.exports = async (client, cluster, worker, ipc, packet) => {
if (!player.manager) return;
switch (packet.t) {
case "VOICE_SERVER_UPDATE":

View File

@ -2,7 +2,7 @@ const soundPlayer = require("../utils/soundplayer.js");
const AwaitRejoin = require("../utils/awaitrejoin.js");
const { random } = require("../utils/misc.js");
module.exports = async (client, cluster, ipc, member, oldChannel) => {
module.exports = async (client, cluster, worker, ipc, member, oldChannel) => {
const connection = soundPlayer.players.get(oldChannel.guild.id);
if (connection && connection.type === "music" && oldChannel.id === connection.voiceChannel.id) {
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id).length === 0) {

View File

@ -1,5 +1,5 @@
const leaveHandler = require("./voiceChannelLeave.js");
module.exports = async (client, cluster, ipc, member, newChannel, oldChannel) => {
module.exports = async (client, cluster, worker, ipc, member, newChannel, oldChannel) => {
await leaveHandler(client, cluster, ipc, member, oldChannel);
};

153
package-lock.json generated
View File

@ -14,7 +14,8 @@
"dayjs": "^1.10.4",
"dotenv": "^9.0.2",
"emoji-regex": "^9.2.2",
"eris-sharder": "github:esmBot/eris-sharder#eris-dev",
"eris": "^0.15.1",
"eris-fleet": "^0.3.7",
"file-type": "^16.1.0",
"jsqr": "^1.3.1",
"lavacord": "^1.1.9",
@ -596,17 +597,6 @@
"node": ">=6"
}
},
"node_modules/ansi-gray": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-gray/-/ansi-gray-0.1.1.tgz",
"integrity": "sha1-KWLPVOyXksSFEKPetSRDaGHvclE=",
"dependencies": {
"ansi-wrap": "0.1.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
@ -626,14 +616,6 @@
"node": ">=4"
}
},
"node_modules/ansi-wrap": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/ansi-wrap/-/ansi-wrap-0.1.0.tgz",
"integrity": "sha1-qCJQ3bABXponyoLoLqYDu/pF768=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
@ -990,14 +972,6 @@
"simple-swizzle": "^0.2.2"
}
},
"node_modules/color-support": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
"integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==",
"bin": {
"color-support": "bin.js"
}
},
"node_modules/colorette": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz",
@ -1005,14 +979,6 @@
"dev": true,
"peer": true
},
"node_modules/colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
"engines": {
"node": ">=0.1.90"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -1213,9 +1179,9 @@
}
},
"node_modules/eris": {
"version": "0.15.2-dev",
"resolved": "git+ssh://git@github.com/abalabahaha/eris.git#ea9d6700c8e3fedf5d966da4babe195c8cd681da",
"license": "MIT",
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/eris/-/eris-0.15.1.tgz",
"integrity": "sha512-IQ3BPW6OjgFoqjdh+irPOa1jFlkotk+WNu2GQQ7QAQfbzQEPZgn+F+hpOxfMUXPHOZMX4sPKLkVDkMHAssBYhw==",
"dependencies": {
"ws": "^7.2.1"
},
@ -1227,17 +1193,12 @@
"tweetnacl": "^1.0.1"
}
},
"node_modules/eris-sharder": {
"version": "1.10.0",
"resolved": "git+ssh://git@github.com/esmBot/eris-sharder.git#3b7366e5d99012ca0e3350e4d81f384b48911c2d",
"license": "MIT",
"dependencies": {
"colors": "^1.1.2",
"eris": "github:abalabahaha/eris#dev",
"fancy-log": "^1.3.0"
},
"engines": {
"node": ">=8.0.0"
"node_modules/eris-fleet": {
"version": "0.3.7",
"resolved": "https://registry.npmjs.org/eris-fleet/-/eris-fleet-0.3.7.tgz",
"integrity": "sha512-irrGAZIwTXWxIfsSoi8YIm0nHImUADKG+wSr7yk5QgJfSFzIpCEgqFr4x7hdskfcwRa4CCR2HUrjuWDc0zITvg==",
"peerDependencies": {
"eris": "^0.15.0"
}
},
"node_modules/erlpack": {
@ -1606,20 +1567,6 @@
"node": ">=6"
}
},
"node_modules/fancy-log": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/fancy-log/-/fancy-log-1.3.3.tgz",
"integrity": "sha512-k9oEhlyc0FrVh25qYuSELjr8oxsCoc4/LEZfg2iJJrfEk/tZL9bCoJE47gqAvI2m/AUjluCS4+3I0eTx8n3AEw==",
"dependencies": {
"ansi-gray": "^0.1.1",
"color-support": "^1.1.3",
"parse-node-version": "^1.0.0",
"time-stamp": "^1.0.0"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@ -2560,14 +2507,6 @@
"node": ">=6"
}
},
"node_modules/parse-node-version": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parse-node-version/-/parse-node-version-1.0.1.tgz",
"integrity": "sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/path-exists": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
@ -3420,14 +3359,6 @@
"integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=",
"dev": true
},
"node_modules/time-stamp": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/time-stamp/-/time-stamp-1.1.0.tgz",
"integrity": "sha1-dkpaEa9QVhkhsTPztE5hhofg9cM=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
@ -4219,14 +4150,6 @@
"integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==",
"dev": true
},
"ansi-gray": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-gray/-/ansi-gray-0.1.1.tgz",
"integrity": "sha1-KWLPVOyXksSFEKPetSRDaGHvclE=",
"requires": {
"ansi-wrap": "0.1.0"
}
},
"ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
@ -4240,11 +4163,6 @@
"color-convert": "^1.9.0"
}
},
"ansi-wrap": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/ansi-wrap/-/ansi-wrap-0.1.0.tgz",
"integrity": "sha1-qCJQ3bABXponyoLoLqYDu/pF768="
},
"aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
@ -4520,11 +4438,6 @@
"simple-swizzle": "^0.2.2"
}
},
"color-support": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
"integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg=="
},
"colorette": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz",
@ -4532,11 +4445,6 @@
"dev": true,
"peer": true
},
"colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -4690,22 +4598,20 @@
}
},
"eris": {
"version": "git+ssh://git@github.com/abalabahaha/eris.git#ea9d6700c8e3fedf5d966da4babe195c8cd681da",
"from": "eris@github:abalabahaha/eris#dev",
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/eris/-/eris-0.15.1.tgz",
"integrity": "sha512-IQ3BPW6OjgFoqjdh+irPOa1jFlkotk+WNu2GQQ7QAQfbzQEPZgn+F+hpOxfMUXPHOZMX4sPKLkVDkMHAssBYhw==",
"requires": {
"opusscript": "^0.0.8",
"tweetnacl": "^1.0.1",
"ws": "^7.2.1"
}
},
"eris-sharder": {
"version": "git+ssh://git@github.com/esmBot/eris-sharder.git#3b7366e5d99012ca0e3350e4d81f384b48911c2d",
"from": "eris-sharder@github:esmBot/eris-sharder#eris-dev",
"requires": {
"colors": "^1.1.2",
"eris": "github:abalabahaha/eris#dev",
"fancy-log": "^1.3.0"
}
"eris-fleet": {
"version": "0.3.7",
"resolved": "https://registry.npmjs.org/eris-fleet/-/eris-fleet-0.3.7.tgz",
"integrity": "sha512-irrGAZIwTXWxIfsSoi8YIm0nHImUADKG+wSr7yk5QgJfSFzIpCEgqFr4x7hdskfcwRa4CCR2HUrjuWDc0zITvg==",
"requires": {}
},
"erlpack": {
"version": "git+ssh://git@github.com/abalabahaha/erlpack.git#5d0064f9e106841e1eead711a6451f99b0d289fd",
@ -4975,17 +4881,6 @@
"resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz",
"integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg=="
},
"fancy-log": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/fancy-log/-/fancy-log-1.3.3.tgz",
"integrity": "sha512-k9oEhlyc0FrVh25qYuSELjr8oxsCoc4/LEZfg2iJJrfEk/tZL9bCoJE47gqAvI2m/AUjluCS4+3I0eTx8n3AEw==",
"requires": {
"ansi-gray": "^0.1.1",
"color-support": "^1.1.3",
"parse-node-version": "^1.0.0",
"time-stamp": "^1.0.0"
}
},
"fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@ -5701,11 +5596,6 @@
"callsites": "^3.0.0"
}
},
"parse-node-version": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parse-node-version/-/parse-node-version-1.0.1.tgz",
"integrity": "sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA=="
},
"path-exists": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
@ -6366,11 +6256,6 @@
"integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=",
"dev": true
},
"time-stamp": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/time-stamp/-/time-stamp-1.1.0.tgz",
"integrity": "sha1-dkpaEa9QVhkhsTPztE5hhofg9cM="
},
"to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",

View File

@ -29,7 +29,8 @@
"dayjs": "^1.10.4",
"dotenv": "^9.0.2",
"emoji-regex": "^9.2.2",
"eris-sharder": "github:esmBot/eris-sharder#eris-dev",
"eris": "^0.15.1",
"eris-fleet": "^0.3.7",
"file-type": "^16.1.0",
"jsqr": "^1.3.1",
"lavacord": "^1.1.9",

110
shard.js
View File

@ -1,5 +1,5 @@
// shard base
const { Base } = require("eris-sharder");
const { BaseClusterWorker } = require("eris-fleet");
// path stuff
const { readdir } = require("fs").promises;
// fancy loggings
@ -23,9 +23,11 @@ const helpGenerator =
process.env.OUTPUT !== "" ? require("./utils/help.js") : null;
const http = require("http");
class Shard extends Base {
class Shard extends BaseClusterWorker {
constructor(bot) {
super(bot);
this.init();
}
async init() {
@ -48,7 +50,7 @@ class Shard extends Base {
logger.log("log", `Loading event from ${file}...`);
const eventName = file.split(".")[0];
const event = require(`./events/${file}`);
this.bot.on(eventName, event.bind(null, this.bot, this.clusterID, this.ipc));
this.bot.on(eventName, event.bind(null, this.bot, this.clusterID, this.workerID, this.ipc));
}
// connect to image api if enabled
@ -106,20 +108,40 @@ connected_workers ${image.connections.size}
});
}
// handle process stop
process.on("SIGINT", () => {
logger.log("warn", "SIGINT detected, shutting down...");
this.bot.editStatus("dnd", {
name: "Restarting/shutting down..."
});
for (const command in collections.commands) {
handler.unload(command);
}
this.bot.disconnect();
require("./utils/database.js").stop();
process.exit(0);
this.ipc.register("reload", async (message) => {
const result = await handler.unload(message.cmd);
if (result) return this.ipc.broadcast("reloadFail", { result: result });
const result2 = await handler.load(collections.paths.get(message.cmd));
if (result2) return this.ipc.broadcast("reloadFail", { result: result2 });
return this.ipc.broadcast("reloadSuccess");
});
return;
this.bot.privateChannels.limit = 0;
this.ipc.register("soundreload", async () => {
const soundStatus = await sound.checkStatus();
if (!soundStatus) {
const length = await sound.connect(this.bot);
return this.ipc.broadcast("soundReloadSuccess", { length });
} else {
return this.ipc.broadcast("soundReloadFail");
}
});
// connect to lavalink
if (!sound.status && !sound.connected) sound.connect(this.bot);
database.setup();
// set activity (a.k.a. the gamer code)
(async function activityChanger() {
this.bot.editStatus("dnd", {
name: `${misc.random(messages)} | @${this.bot.user.username} help`,
});
setTimeout(activityChanger.bind(this), 900000);
}).bind(this)();
logger.log("info", `Started worker ${this.workerID}.`);
}
async* getFiles(dir) {
@ -133,54 +155,16 @@ connected_workers ${image.connections.size}
}
}
async launch() {
await this.init();
this.ipc.register("stat", (message) => {
collections.stats = message;
shutdown(done) {
logger.log("warn", "SIGINT detected, shutting down...");
this.bot.editStatus("dnd", {
name: "Restarting/shutting down..."
});
this.ipc.register("restart", async () => {
this.bot.editStatus("dnd", {
name: "esmBot is restarting, please stand by."
});
process.exit(1);
});
this.ipc.register("reload", async (message) => {
const result = await handler.unload(message.cmd);
if (result) return this.ipc.broadcast("reloadFail", { result: result });
const result2 = await handler.load(collections.paths.get(message.cmd));
if (result2) return this.ipc.broadcast("reloadFail", { result: result2 });
return this.ipc.broadcast("reloadSuccess");
});
this.ipc.register("soundreload", async () => {
const soundStatus = await sound.checkStatus();
if (!soundStatus) {
const length = await sound.connect(this.bot);
return this.ipc.broadcast("soundReloadSuccess", { length });
} else {
return this.ipc.broadcast("soundReloadFail");
}
});
// connect to lavalink
if (!sound.status && !sound.connected) await sound.connect(this.bot);
this.bot.privateChannels.limit = 0;
await database.setup();
// set activity (a.k.a. the gamer code)
(async function activityChanger() {
this.bot.editStatus("dnd", {
name: `${misc.random(messages)} | @${this.bot.user.username} help`,
});
setTimeout(activityChanger.bind(this), 900000);
}).bind(this)();
logger.log("info", `Started cluster ${this.clusterID}.`);
for (const command in collections.commands) {
handler.unload(command);
}
require("./utils/database.js").stop();
done();
}
}

View File

@ -27,6 +27,4 @@ class Cache extends Map {
}
exports.prefixCache = new Cache();
exports.disabledCache = new Cache();
exports.stats = {};
exports.disabledCache = new Cache();

View File

@ -1,4 +1,4 @@
exports.log = (type, content) => content ? process.send({ name: type, msg: content }) : process.send({ name: "info", msg: type });
exports.log = (type, content) => content ? process.send({ op: type, msg: content }) : process.send({ op: "info", msg: type });
exports.error = (...args) => this.log("error", ...args);