diff --git a/commands/admin.js b/commands/admin.js index 07f05d8..18c6be1 100644 --- a/commands/admin.js +++ b/commands/admin.js @@ -145,7 +145,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/alarm.js b/commands/alarm.js index ae1709f..b18e09d 100644 --- a/commands/alarm.js +++ b/commands/alarm.js @@ -186,7 +186,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/armbands.js b/commands/armbands.js index 5e46939..742261c 100644 --- a/commands/armbands.js +++ b/commands/armbands.js @@ -15,7 +15,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/bank.js b/commands/bank.js index ec939a1..f1e9768 100644 --- a/commands/bank.js +++ b/commands/bank.js @@ -52,7 +52,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/bounty.js b/commands/bounty.js index 081c2cb..93d39e1 100644 --- a/commands/bounty.js +++ b/commands/bounty.js @@ -49,7 +49,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/channels.js b/commands/channels.js index 82b0aa2..597b81c 100644 --- a/commands/channels.js +++ b/commands/channels.js @@ -14,7 +14,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/claim.js b/commands/claim.js index a06da20..a5ccdf2 100644 --- a/commands/claim.js +++ b/commands/claim.js @@ -21,7 +21,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/collect-income.js b/commands/collect-income.js index d21af22..a337e00 100644 --- a/commands/collect-income.js +++ b/commands/collect-income.js @@ -15,7 +15,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/config.js b/commands/config.js index 9f258a7..23e6fac 100644 --- a/commands/config.js +++ b/commands/config.js @@ -308,7 +308,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 @@ -327,7 +327,7 @@ module.exports = { const channelid = args[0].options[0].options[0].value; if (args[0].options[0].name == 'add') { - const channelAdd = client.channels.cache.get(channelid); + const channelAdd = client.GetChannel(channelid); const newChannelErrorEmbed = new EmbedBuilder().setColor(client.config.Colors.Red) let error = false; diff --git a/commands/event.js b/commands/event.js index a99f7b7..c4fb8d5 100644 --- a/commands/event.js +++ b/commands/event.js @@ -57,7 +57,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/excluded.js b/commands/excluded.js index 9a293b8..7925c4d 100644 --- a/commands/excluded.js +++ b/commands/excluded.js @@ -14,7 +14,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/factions.js b/commands/factions.js index 6ba25dc..d6291ac 100644 --- a/commands/factions.js +++ b/commands/factions.js @@ -21,7 +21,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/gamertag-link.js b/commands/gamertag-link.js index 5d68863..09ef079 100644 --- a/commands/gamertag-link.js +++ b/commands/gamertag-link.js @@ -20,7 +20,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/gamertag-unlink.js b/commands/gamertag-unlink.js index 82ed8ff..28d9c63 100644 --- a/commands/gamertag-unlink.js +++ b/commands/gamertag-unlink.js @@ -13,7 +13,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/help.js b/commands/help.js index 20027ab..4e2cf98 100644 --- a/commands/help.js +++ b/commands/help.js @@ -46,7 +46,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 @@ -80,10 +80,7 @@ module.exports = { (x) => x.aliases && x.aliases.includes(args[0].options[0].value) ); if (!cmd) - return client.sendError( - interaction, - `❌ | Unable to find that command.` - ); + return interaction.send({ content: `❌ | Unable to find that command.` }); let embed = new EmbedBuilder() .setDescription(cmd.description) @@ -129,7 +126,7 @@ module.exports = { } else if (args[0].name == 'credits') { const creditsEmbed = new EmbedBuilder() .setColor(client.config.Colors.Default) - .setTitle('QuarksBot Credits') + .setTitle('DayzRBot Credits') .setDescription(` **Bot Author:** McDazzzled#5307 @@ -141,7 +138,7 @@ module.exports = { const end = new Date().getTime(); const stats = new EmbedBuilder() .setColor(client.config.Colors.Default) - .setTitle('QuarksBot Statistics') + .setTitle('DayzRBot Statistics') .addFields( { name: 'Guilds', value: `${client.guilds.cache.size}`, inline: true }, { name: 'Users', value: `${client.users.cache.size}`, inline: true }, diff --git a/commands/leaderboard.js b/commands/leaderboard.js index 368d884..561ed98 100644 --- a/commands/leaderboard.js +++ b/commands/leaderboard.js @@ -39,7 +39,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/location.js b/commands/location.js index 4d994cb..10cc204 100644 --- a/commands/location.js +++ b/commands/location.js @@ -14,7 +14,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/lookup.js b/commands/lookup.js index 0febe81..34df0e3 100644 --- a/commands/lookup.js +++ b/commands/lookup.js @@ -38,7 +38,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/ping.js b/commands/ping.js index ffa1d81..33e676a 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -14,7 +14,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/player-list.js b/commands/player-list.js index a93ba99..2b3d8de 100644 --- a/commands/player-list.js +++ b/commands/player-list.js @@ -14,7 +14,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/player-stats.js b/commands/player-stats.js index fa6289f..16562eb 100644 --- a/commands/player-stats.js +++ b/commands/player-stats.js @@ -42,7 +42,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/purchase-emp.js b/commands/purchase-emp.js index fdff61d..98ec8b8 100644 --- a/commands/purchase-emp.js +++ b/commands/purchase-emp.js @@ -15,7 +15,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/purchase-uav.js b/commands/purchase-uav.js index 5f0cbea..3e3d843 100644 --- a/commands/purchase-uav.js +++ b/commands/purchase-uav.js @@ -32,7 +32,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/reset.js b/commands/reset.js index 6a69f96..0431ac5 100644 --- a/commands/reset.js +++ b/commands/reset.js @@ -22,7 +22,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/stats.js b/commands/stats.js index 652d43b..e043957 100644 --- a/commands/stats.js +++ b/commands/stats.js @@ -14,7 +14,7 @@ module.exports = { SlashCommand: { /** * - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js index 9843f16..23c3b20 100644 --- a/events/guildMemberAdd.js +++ b/events/guildMemberAdd.js @@ -3,7 +3,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = async (client, member) => { let GuildDB = await client.GetGuild(member.guild.id); - const channel = client.channels.cache.get(GuildDB.welcomeChannel); + const channel = client.GetChannel(GuildDB.welcomeChannel); let embed = new EmbedBuilder() .setColor(client.config.Colors.Default) diff --git a/package.json b/package.json index 497be8e..398d2ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "9.1.2", + "version": "9.1.3", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzRBot.js b/structures/DayzRBot.js index 30a6f6e..953f9a6 100644 --- a/structures/DayzRBot.js +++ b/structures/DayzRBot.js @@ -100,7 +100,6 @@ class DayzRBot extends Client { const client = this; } - log(Text) { this.logger.log(Text); } error(Text) { this.logger.error(Text); } @@ -186,7 +185,7 @@ class DayzRBot extends Client { "server.playerstats": s } }, function (err, res) { - if (err) this.error(err); + if (err) this.sendError(this.GetChannel(guild.adminLogsChannel), err); }); history.lastLog = lines[lines.length-1]; @@ -306,11 +305,14 @@ class DayzRBot extends Client { const event = require(EventsDir + "/" + file); if (['interactionCreate','guildMemberAdd'].includes(file.split(".")[0])) this.on(file.split(".")[0], i => event(this, i)); else this.on(file.split(".")[0], event.bind(null, this)); - this.logger.log("Event Loaded: " + file.split(".")[0]); + this.log("Event Loaded: " + file.split(".")[0]); }); }); } + // Allows shorter lines of code elsewhere + GetChannel(channel_id) { return this.channels.cache.get(channel_id); } + sendError(Channel, Error) { this.error(Error); let embed = new EmbedBuilder() @@ -320,7 +322,6 @@ class DayzRBot extends Client { Channel.send(embed); } - // Handles internal errors for slash commands. E.g failed to update database from slash command. sendInternalError(Interaction, Error) { this.error(Error); diff --git a/util/AdminLogsHandler.js b/util/AdminLogsHandler.js index 992da47..730aecb 100644 --- a/util/AdminLogsHandler.js +++ b/util/AdminLogsHandler.js @@ -6,7 +6,7 @@ module.exports = { let guild = await client.GetGuild(guildId); if (!client.exists(guild.connectionLogsChannel)) return; - const channel = client.channels.cache.get(guild.connectionLogsChannel); + const channel = client.GetChannel(guild.connectionLogsChannel); let newDt = await client.getDateEST(data.time); let unixTime = Math.floor(newDt.getTime()/1000); @@ -40,7 +40,7 @@ module.exports = { let guild = await client.GetGuild(guildId); if (!client.exists(guild.connectionLogsChannel)) return; - const channel = client.channels.cache.get(guild.connectionLogsChannel); + const channel = client.GetChannel(guild.connectionLogsChannel); if (!channel) return; let unixTime = Math.floor(newDt.getTime()/1000); diff --git a/util/AlarmsHandler.js b/util/AlarmsHandler.js index 3995758..2d00769 100644 --- a/util/AlarmsHandler.js +++ b/util/AlarmsHandler.js @@ -18,7 +18,7 @@ module.exports = { let distance = Math.sqrt(Math.pow(diff[0], 2) + Math.pow(diff[1], 2)).toFixed(2) if (distance < alarm.radius) { - const channel = client.channels.cache.get(alarm.channel); + const channel = client.GetChannel(alarm.channel); let newDt = await client.getDateEST(data.time); let unixTime = Math.floor(newDt.getTime()/1000); @@ -90,7 +90,7 @@ module.exports = { if (update) { client.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, {$set: { "server.uavs": uavs }}, function (err, res) { - if (err) return client.sendInternalError(interaction, err); + if (err) return client.sendError(client.GetChannel(guild.adminLogsChannel), err); }); } }, @@ -108,7 +108,7 @@ module.exports = { let distance = Math.sqrt(Math.pow(diff[0], 2) + Math.pow(diff[1], 2)).toFixed(2) if (distance < alarm.radius) { - const channel = client.channels.cache.get(alarm.channel); + const channel = client.GetChannel(alarm.channel); let newDt = await client.getDateEST(data.time); let unixTime = Math.floor(newDt.getTime()/1000); @@ -127,7 +127,7 @@ module.exports = { ExpireEvent: async(client, guild, e) => { let hasMR = (guild.memberRole != ""); - const channel = client.channels.cache.get(e.channel); + const channel = client.GetChannel(e.channel); if (client.exists(e.channel)) channel.send({ embeds: [new EmbedBuilder().setColor(client.config.colors.Default).setDescription(`${hasMR ? `<@&${guild.memberRole}>\n`:''}**The ${e.name} Event has ended!**`)] }); client.dbo.collection("guilds").updateOne({ "server.serverID": guild.serverID }, { @@ -135,7 +135,7 @@ module.exports = { "server.events": e } }, function(err, res) { - if (err) return client.sendInternalError(interaction, err); + if (err) return client.sendError(client.GetChannel(guild.adminLogsChannel), err); }); }, @@ -152,7 +152,7 @@ module.exports = { .setDescription(`**${e.name} Event**\n${e.gamertag} was located at **[${player.pos[0]}, ${player.pos[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${player.pos[0]};${player.pos[1]})** at `); if (!client.exists(e.channel)) return module.exports.ExpireEvent(client, guild, e); // Expire event since it has invalid channel. - const channel = client.channels.cache.get(e.channel); + const channel = client.GetChannel(e.channel); channel.send({ embeds: [trackEvent], content: `${hasMR ? `\n<@&${guild.memberRole}>`:'@here'}` }); let now = new Date(); diff --git a/util/KillfeedHandler.js b/util/KillfeedHandler.js index 92b8668..f0b269d 100644 --- a/util/KillfeedHandler.js +++ b/util/KillfeedHandler.js @@ -7,7 +7,7 @@ module.exports = { HandleKillfeed: async (client, guildId, stats, line) => { let guild = await client.GetGuild(guildId); - const channel = client.channels.cache.get(guild.killfeedChannel); + const channel = client.GetChannel(guild.killfeedChannel); let templateKilled = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>\) killed by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) with (.*) from (.*) meters /g; let template = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)\[HP\: (.*)\] hit by Player \"(.*)\" \(id=(.*) pos=<(.*)>\) into (.*) for (.*) damage \((.*)\) with (.*) from (.*) meters /g; @@ -115,14 +115,14 @@ module.exports = { let newBank = new User(); newBank.createUser(killerStat.discordID, guildId, guild.startingBalance); newBank.save().catch(err => { - if (err) return client.sendInternalError(interaction, err); + if (err) return client.sendError(client.GetChannel(guild.killfeedChannel), err); }); } else banking = banking.user; if (!client.exists(banking.guilds[guildId])) { const success = addUser(banking.guilds, guildId, killer.discordID, this, guild.startingBalance); - if (!success) return client.sendError(guild.connectionLogsChannel, 'Failed to add bank'); + if (!success) return client.sendError(client.GetChannel(guild.killfeedChannel), 'Automatic Bounty Payout: Failed to add bank to database.'); } const newBalance = banking.guilds[guildId].balance + totalBounty; @@ -132,7 +132,7 @@ module.exports = { [`user.guilds.${guildId}.balance`]: newBalance, } }, function(err, res) { - if (err) return client.sendError(guild.connectionLogsChannel, err); + if (err) return client.sendError(client.GetChannel(guild.killfeedChannel), `Killfeed Error: Updating killer bank balance\n${err}`); }); receivedBounty = new EmbedBuilder() diff --git a/util/LogsHandler.js b/util/LogsHandler.js index 4488b0d..6be5c53 100644 --- a/util/LogsHandler.js +++ b/util/LogsHandler.js @@ -197,7 +197,7 @@ module.exports = { if (!client.exists(guild.playerstats)) guild.playerstats = []; if (!client.exists(guild.activePlayersChannel)) return; - const channel = client.channels.cache.get(guild.activePlayersChannel); + const channel = client.GetChannel(guild.activePlayersChannel); let activePlayers = guild.playerstats.filter(p => p.connected == true); let des = ``; @@ -223,7 +223,7 @@ module.exports = { return channel.send({ embeds: [PlayersEmbed, activePlayersEmbed] }).then(sentMessage => { setTimeout(() => { - sentMessage.delete().catch(error => client.sendError(channel, error)); + sentMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); }, 360000); }); } diff --git a/util/NitradoAPI.js b/util/NitradoAPI.js index dd1fd73..d3e95e9 100644 --- a/util/NitradoAPI.js +++ b/util/NitradoAPI.js @@ -39,10 +39,7 @@ module.exports = { let bans = res.data.gameserver.settings.general.bans; if (ban) bans += `\r\n${gamertag}`; else if (!ban) bans = bans.replace(gamertag, ''); - else { - client.error("Incorrect Ban Option: HandlePlayerBan") - throw "Incorrect Ban Option: HandlePlayerBan" - } + else client.error("Incorrect Ban Option: HandlePlayerBan"); const formData = new FormData(); formData.append("category", "general"); diff --git a/util/RegisterSlashCommands.js b/util/RegisterSlashCommands.js index 447e841..4672aec 100644 --- a/util/RegisterSlashCommands.js +++ b/util/RegisterSlashCommands.js @@ -5,7 +5,7 @@ const { REST } = require('@discordjs/rest'); /** * Register slash commands for a guild - * @param {require("../structures/QuarksBot")} client + * @param {require("../structures/DayzRBot")} client */ module.exports = { // Register guild commands