Fixed some issues regarding eris-sharder and newer eris versions

This commit is contained in:
TheEssem 2021-04-29 16:56:32 -05:00
parent 33808685f3
commit 19922858f2
16 changed files with 61 additions and 56 deletions

1
app.js
View file

@ -47,6 +47,7 @@ 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 (dbl) {
await dbl.postStats({

View file

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

View file

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

View file

@ -1,4 +1,5 @@
const { version } = require("../../package.json");
const collections = require("../../utils/collections.js");
const Command = require("../../classes/command.js");
class InfoCommand extends Command {
@ -20,7 +21,7 @@ class InfoCommand extends Command {
},
{
"name": "💬 Total Servers:",
"value": this.client.guilds.size
"value": collections.stats.guilds ? collections.stats.guilds : `${this.client.guilds.size} (for this cluster only)`
},
{
"name": "✅ Official Server:",

View file

@ -1,4 +1,5 @@
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");
@ -20,15 +21,17 @@ class StatsCommand extends Command {
"value": `v${version}${process.env.NODE_ENV === "development" ? "-dev" : ""}`
},
{
"name": "Memory Usage",
"value": `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`
"name": "Cluster Memory Usage",
"value": `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`,
"inline": true
},
{
"name": "Shard",
"value": this.client.guildShardMap[this.message.channel.guild.id]
"name": "Total Memory Usage",
"value": collections.stats.totalRam ? `${collections.stats.totalRam.toFixed(2)} MB` : "Unknown",
"inline": true
},
{
"name": "Uptime",
"name": "Bot Uptime",
"value": uptime
},
{
@ -41,11 +44,18 @@ class StatsCommand extends Command {
},
{
"name": "Library",
"value": `Eris ${require("eris").VERSION}`
"value": `Eris ${require("eris").VERSION}`,
"inline": true
},
{
"name": "Node.js Version",
"value": process.version
"value": process.version,
"inline": true
},
{
"name": "Shard",
"value": this.client.guildShardMap[this.message.channel.guild.id],
"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, guild) => {
module.exports = async (client, cluster, ipc, guild) => {
logger.log("info", `[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, guild) => {
module.exports = async (client, cluster, 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 commands = [...collections.aliases.keys(), ...collections.commands.keys()];
// run when someone sends a message
module.exports = async (client, message) => {
module.exports = async (client, cluster, ipc, message) => {
// ignore dms and other bots
if (message.author.bot) return;
@ -85,7 +85,7 @@ module.exports = async (client, message) => {
try {
await database.addCount(collections.aliases.has(command) ? collections.aliases.get(command) : command);
const startTime = new Date();
const commandClass = new cmd(client, message, args, message.content.substring(prefix.length).trim().replace(command, "").trim());
const commandClass = new cmd(client, cluster, ipc, message, args, message.content.substring(prefix.length).trim().replace(command, "").trim());
const result = await commandClass.run(); // we also provide the message content as a parameter for cases where we need more accuracy
const endTime = new Date();
if (typeof result === "string" || (typeof result === "object" && result.embed)) {

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, packet) => {
module.exports = async (client, cluster, 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, member, oldChannel) => {
module.exports = async (client, cluster, 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, member, newChannel, oldChannel) => {
await leaveHandler(client, member, oldChannel);
module.exports = async (client, cluster, ipc, member, newChannel, oldChannel) => {
await leaveHandler(client, cluster, ipc, member, oldChannel);
};

44
package-lock.json generated
View file

@ -16,7 +16,7 @@
"duckduckgo-images-api": "^1.0.5",
"emoji-regex": "^9.2.2",
"eris": "^0.15.0",
"eris-sharder": "^1.10.0",
"eris-sharder": "github:discordware/eris-sharder#eris-dev",
"file-type": "^16.1.0",
"jsqr": "^1.3.1",
"lavacord": "^1.1.9",
@ -1163,12 +1163,12 @@
},
"node_modules/eris-sharder": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/eris-sharder/-/eris-sharder-1.10.0.tgz",
"integrity": "sha512-cDazqx7KKM1tpMl2+UFlxwAG7fEnGBxssf/juayVR+If+nfuzUazm0nekRre8cbU4PZMjZmQPxWmDNlOcdFfAA==",
"resolved": "git+ssh://git@github.com/discordware/eris-sharder.git#94b5330234ef908fa984284223f68edd3c718de2",
"license": "MIT",
"dependencies": {
"asciiart-logo": "^0.2.6",
"colors": "^1.1.2",
"eris": "^0.13.1",
"eris": "github:abalabahaha/eris#dev",
"fancy-log": "^1.3.0"
},
"engines": {
@ -1176,26 +1176,20 @@
}
},
"node_modules/eris-sharder/node_modules/eris": {
"version": "0.13.4",
"resolved": "https://registry.npmjs.org/eris/-/eris-0.13.4.tgz",
"integrity": "sha512-IFA14nasCig8xp8cVCULvzBuJ0qpYqJ3XyEtm9OLdC177DYDCJ9QM2Aq+KOpejIVl7838n9AyRlLI6w9Eu3PiQ==",
"version": "0.15.1-dev",
"resolved": "git+ssh://git@github.com/abalabahaha/eris.git#340ffe9118ccf8f938598c90c65418fc624608db",
"license": "MIT",
"dependencies": {
"ws": "^7.2.1"
},
"engines": {
"node": ">=8.0.0"
"node": ">=10.4.0"
},
"optionalDependencies": {
"opusscript": "^0.0.7",
"opusscript": "^0.0.8",
"tweetnacl": "^1.0.1"
}
},
"node_modules/eris-sharder/node_modules/opusscript": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.7.tgz",
"integrity": "sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==",
"optional": true
},
"node_modules/erlpack": {
"version": "0.1.3",
"resolved": "git+ssh://git@github.com/abalabahaha/erlpack.git#5d0064f9e106841e1eead711a6451f99b0d289fd",
@ -4841,31 +4835,23 @@
}
},
"eris-sharder": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/eris-sharder/-/eris-sharder-1.10.0.tgz",
"integrity": "sha512-cDazqx7KKM1tpMl2+UFlxwAG7fEnGBxssf/juayVR+If+nfuzUazm0nekRre8cbU4PZMjZmQPxWmDNlOcdFfAA==",
"version": "git+ssh://git@github.com/discordware/eris-sharder.git#94b5330234ef908fa984284223f68edd3c718de2",
"from": "eris-sharder@github:discordware/eris-sharder#eris-dev",
"requires": {
"asciiart-logo": "^0.2.6",
"colors": "^1.1.2",
"eris": "^0.13.1",
"eris": "github:abalabahaha/eris#dev",
"fancy-log": "^1.3.0"
},
"dependencies": {
"eris": {
"version": "0.13.4",
"resolved": "https://registry.npmjs.org/eris/-/eris-0.13.4.tgz",
"integrity": "sha512-IFA14nasCig8xp8cVCULvzBuJ0qpYqJ3XyEtm9OLdC177DYDCJ9QM2Aq+KOpejIVl7838n9AyRlLI6w9Eu3PiQ==",
"version": "git+ssh://git@github.com/abalabahaha/eris.git#340ffe9118ccf8f938598c90c65418fc624608db",
"from": "eris@github:abalabahaha/eris#dev",
"requires": {
"opusscript": "^0.0.7",
"opusscript": "^0.0.8",
"tweetnacl": "^1.0.1",
"ws": "^7.2.1"
}
},
"opusscript": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.7.tgz",
"integrity": "sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==",
"optional": true
}
}
},

View file

@ -29,7 +29,7 @@
"duckduckgo-images-api": "^1.0.5",
"emoji-regex": "^9.2.2",
"eris": "^0.15.0",
"eris-sharder": "^1.10.0",
"eris-sharder": "github:discordware/eris-sharder#eris-dev",
"file-type": "^16.1.0",
"jsqr": "^1.3.1",
"lavacord": "^1.1.9",

View file

@ -47,7 +47,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.bot.on(eventName, event.bind(null, this.bot, this.clusterID, this.ipc));
}
// connect to image api if enabled
@ -101,6 +101,10 @@ class Shard extends Base {
} catch {
logger.error("Might have failed to register some things");
}
this.ipc.register("stat", (message) => {
collections.stats = message;
});
// connect to lavalink
if (!sound.status && !sound.connected) await sound.connect(this.bot);
@ -117,7 +121,6 @@ class Shard extends Base {
setTimeout(activityChanger.bind(this), 900000);
}).bind(this)();
if (process.env.PMTWO === "true") process.send("ready");
logger.log("info", `Started cluster ${this.clusterID}.`);
}

View file

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

View file

@ -11,12 +11,12 @@ module.exports = async (client, message, pages, timeout = 120000) => {
}
const reactionCollector = new ReactionCollector(client, currentPage, (message, reaction, member) => emojiList.includes(reaction.name) && !member.bot, { time: timeout });
reactionCollector.on("reaction", async (msg, reaction, member) => {
if (member === message.author.id) {
if (member.id === message.author.id) {
switch (reaction.name) {
case "◀":
page = page > 0 ? --page : pages.length - 1;
currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("◀", member);
if (manageMessages) msg.removeReaction("◀", member.id);
break;
case "🔢":
message.channel.createMessage(`${message.author.mention}, what page do you want to jump to?`).then(askMessage => {
@ -29,7 +29,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
if (manageMessages) await response.delete();
page = Number(response.content) - 1;
currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("🔢", member);
if (manageMessages) msg.removeReaction("🔢", member.id);
});
}).catch(error => {
throw error;
@ -38,7 +38,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
case "▶":
page = page + 1 < pages.length ? ++page : 0;
currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("▶", member);
if (manageMessages) msg.removeReaction("▶", member.id);
break;
case "🗑":
reactionCollector.emit("end");