diff --git a/api/index.js b/api/index.js index f24e3f7..c830130 100644 --- a/api/index.js +++ b/api/index.js @@ -33,10 +33,10 @@ const Rinit = 0x08; const start = process.hrtime(); const log = (msg, jobNum) => { - console.log(`[${process.hrtime(start)[1] / 1000000}${jobNum !== undefined ? `:${jobNum}` : ""}]\t ${msg}`); + console.log(`[${process.hrtime(start)[1] / 1000000}${jobNum ? `:${jobNum}` : ""}]\t ${msg}`); }; const error = (msg, jobNum) => { - console.error(`[${process.hrtime(start)[1] / 1000000}${jobNum !== undefined ? `:${jobNum}` : ""}]\t ${msg}`); + console.error(`[${process.hrtime(start)[1] / 1000000}${jobNum ? `:${jobNum}` : ""}]\t ${msg}`); }; class JobCache extends Map { @@ -53,8 +53,8 @@ const jobs = new JobCache(); const queue = []; // Array of IDs -const MAX_JOBS = process.env.JOBS !== "" && process.env.JOBS !== undefined ? parseInt(process.env.JOBS) : cpus().length * 4; // Completely arbitrary, should usually be some multiple of your amount of cores -const PASS = process.env.PASS !== "" && process.env.PASS !== undefined ? process.env.PASS : undefined; +const MAX_JOBS = process.env.JOBS && process.env.JOBS !== "" ? parseInt(process.env.JOBS) : cpus().length * 4; // Completely arbitrary, should usually be some multiple of your amount of cores +const PASS = process.env.PASS && process.env.PASS !== "" ? process.env.PASS : undefined; let jobAmount = 0; const acceptJob = (id, sock) => { diff --git a/app.js b/app.js index 7db0dd6..9a20ecf 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,12 @@ if (process.platform === "win32") console.error("\x1b[1m\x1b[31m\x1b[40m" + `WIN32 IS NOT OFFICIALLY SUPPORTED! Although there's a (very) slim chance of it working, multiple aspects of the bot are built with UNIX-like systems in mind and could break on Win32-based systems. If you want to run the bot on Windows, using Windows Subsystem for Linux is highly recommended. The bot will continue to run past this message, but keep in mind that it could break at any time. Continue running at your own risk; alternatively, stop the bot using Ctrl+C and install WSL.` + "\x1b[0m"); +if (process.versions.node.split(".")[0] < 15) { + console.error(`You are currently running Node.js version ${process.version}. +esmBot requires Node.js version 15 or above. +Please refer to step 3 of the setup guide.`); + process.exit(1); +} // load config from .env file import { config } from "dotenv"; @@ -55,6 +61,7 @@ const Admiral = new Fleet({ BotWorker: Shard, token: `Bot ${process.env.TOKEN}`, fetchTimeout: 900000, + useCentralRequestHandler: true, startingStatus: { status: "idle", game: { diff --git a/commands/general/avatar.js b/commands/general/avatar.js index d75929a..bdf308f 100644 --- a/commands/general/avatar.js +++ b/commands/general/avatar.js @@ -2,7 +2,7 @@ import Command from "../../classes/command.js"; class AvatarCommand extends Command { async run() { - if (this.message.mentions[0] !== undefined) { + if (this.message.mentions[0]) { return this.message.mentions[0].dynamicAvatarURL(null, 1024); } else if (await this.ipc.fetchUser(this.args[0])) { const user = await this.ipc.fetchUser(this.args[0]); diff --git a/utils/database/postgresql.js b/utils/database/postgresql.js index 8cee141..6a05639 100644 --- a/utils/database/postgresql.js +++ b/utils/database/postgresql.js @@ -44,8 +44,8 @@ export async function removeTag(name, guild) { export async function disableCommand(guild, command) { const guildDB = await this.getGuild(guild); - await connection.query("UPDATE guilds SET disabled_commands = $1 WHERE guild_id = $2", [(guildDB.disabled_commands ? [...guildDB.disabled_commands, command] : [command]).filter((v) => v !== undefined), guild]); - disabledCmdCache.set(guild, guildDB.disabled_commands ? [...guildDB.disabled_commands, command] : [command].filter((v) => v !== undefined)); + await connection.query("UPDATE guilds SET disabled_commands = $1 WHERE guild_id = $2", [(guildDB.disabled_commands ? [...guildDB.disabled_commands, command] : [command]).filter((v) => !!v), guild]); + disabledCmdCache.set(guild, guildDB.disabled_commands ? [...guildDB.disabled_commands, command] : [command].filter((v) => !!v)); } export async function enableCommand(guild, command) { @@ -138,4 +138,4 @@ export async function setup() { export async function stop() { await connection.end(); -} \ No newline at end of file +} diff --git a/utils/database/sqlite.js b/utils/database/sqlite.js index e11d4a1..82e72c3 100644 --- a/utils/database/sqlite.js +++ b/utils/database/sqlite.js @@ -73,8 +73,8 @@ export async function getCounts() { export async function disableCommand(guild, command) { const guildDB = await this.getGuild(guild); - connection.prepare("UPDATE guilds SET disabled_commands = ? WHERE guild_id = ?").run(JSON.stringify((guildDB.disabledCommands ? [...JSON.parse(guildDB.disabledCommands), command] : [command]).filter((v) => v !== undefined)), guild); - collections.disabledCmdCache.set(guild, guildDB.disabled_commands ? [...JSON.parse(guildDB.disabledCommands), command] : [command].filter((v) => v !== undefined)); + connection.prepare("UPDATE guilds SET disabled_commands = ? WHERE guild_id = ?").run(JSON.stringify((guildDB.disabledCommands ? [...JSON.parse(guildDB.disabledCommands), command] : [command]).filter((v) => !!v)), guild); + collections.disabledCmdCache.set(guild, guildDB.disabled_commands ? [...JSON.parse(guildDB.disabledCommands), command] : [command].filter((v) => !!v)); } export async function enableCommand(guild, command) { diff --git a/utils/services/prometheus.js b/utils/services/prometheus.js index 8fb4277..e9eb518 100644 --- a/utils/services/prometheus.js +++ b/utils/services/prometheus.js @@ -7,7 +7,7 @@ class PrometheusWorker extends BaseServiceWorker { constructor(setup) { super(setup); - if (process.env.METRICS !== "" && process.env.METRICS !== undefined) { + if (process.env.METRICS && process.env.METRICS !== "") { this.httpServer = createServer(async (req, res) => { if (req.method !== "GET") { res.statusCode = 405; diff --git a/utils/soundplayer.js b/utils/soundplayer.js index 630154b..99572e5 100644 --- a/utils/soundplayer.js +++ b/utils/soundplayer.js @@ -68,7 +68,7 @@ export async function play(client, sound, message, music = false) { if (!tracks || tracks.length === 0) return "I couldn't find that song!"; if (music) { const sortedTracks = tracks.map((val) => { return val.track; }); - const playlistTracks = playlistInfo.selectedTrack !== undefined ? sortedTracks : [sortedTracks[0]]; + const playlistTracks = playlistInfo.selectedTrack ? sortedTracks : [sortedTracks[0]]; queues.set(voiceChannel.guild.id, oldQueue ? [...oldQueue, ...playlistTracks] : playlistTracks); } const connection = await manager.join({