Improve voice connection checking, take advantage of optional chaining operators

This commit is contained in:
Essem 2022-07-23 16:02:04 -05:00
parent df43f9eb9d
commit 398ce07bd2
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
11 changed files with 36 additions and 27 deletions

View file

@ -7,7 +7,7 @@ class BroadcastCommand extends Command {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) return "Only the bot owner can broadcast messages!";
const message = this.options.message ?? this.args.join(" ");
if (message && message.trim()) {
if (message?.trim()) {
this.ipc.broadcast("playbroadcast", message);
this.ipc.register("broadcastSuccess", () => {
this.ipc.unregister("broadcastSuccess");

View file

@ -13,7 +13,7 @@ class ChannelCommand extends Command {
if (this.args[0].toLowerCase() === "disable") {
let channel;
if (this.args[1] && this.args[1].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[1] >= 21154535154122752n) {
if (this.args[1]?.match(/^<?[@#]?[&!]?\d+>?$/) && this.args[1] >= 21154535154122752n) {
const id = this.args[1].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "");
if (guildDB.disabled.includes(id)) return "I'm already disabled in this channel!";
channel = this.channel.guild.channels.get(id);
@ -26,7 +26,7 @@ class ChannelCommand extends Command {
return `I have been disabled in this channel. To re-enable me, just run \`${guildDB.prefix}channel enable\`.`;
} else if (this.args[0].toLowerCase() === "enable") {
let channel;
if (this.args[1] && this.args[1].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[1] >= 21154535154122752n) {
if (this.args[1]?.match(/^<?[@#]?[&!]?\d+>?$/) && this.args[1] >= 21154535154122752n) {
const id = this.args[1].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "");
if (!guildDB.disabled.includes(id)) return "I'm not disabled in that channel!";
channel = this.channel.guild.channels.get(id);

View file

@ -18,12 +18,12 @@ class CommandCommand extends Command {
if (this.args[0].toLowerCase() === "disable") {
if (command === "command") return "You can't disable that command!";
if (disabled && disabled.includes(command)) return "That command is already disabled!";
if (disabled?.includes(command)) return "That command is already disabled!";
await db.disableCommand(this.channel.guild.id, command);
return `The command has been disabled. To re-enable it, just run \`${guildDB.prefix}command enable ${command}\`.`;
} else if (this.args[0].toLowerCase() === "enable") {
if (disabled && !disabled.includes(command)) return "That command isn't disabled!";
if (!disabled?.includes(command)) return "That command isn't disabled!";
await db.enableCommand(this.channel.guild.id, command);
return `The command \`${command}\` has been re-enabled.`;

View file

@ -29,7 +29,7 @@ class InfoCommand extends Command {
},
{
name: "💬 Total Servers:",
value: stats && stats.guilds ? 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

@ -29,12 +29,12 @@ class StatsCommand extends Command {
},
{
"name": "Cluster Memory Usage",
"value": stats && stats.clusters[this.cluster] ? `${stats.clusters[this.cluster].ram.toFixed(2)} MB` : `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`,
"value": stats?.clusters[this.cluster] ? `${stats.clusters[this.cluster].ram.toFixed(2)} MB` : `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`,
"inline": true
},
{
"name": "Total Memory Usage",
"value": stats && stats.totalRam ? `${stats.totalRam.toFixed(2)} MB` : "Unknown",
"value": stats?.totalRam ? `${stats.totalRam.toFixed(2)} MB` : "Unknown",
"inline": true
},
{
@ -72,7 +72,7 @@ class StatsCommand extends Command {
},
{
"name": "Servers",
"value": stats && stats.guilds ? 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
}
]