From c81d2bd2352d303aea25962444e9ba660b8222cf Mon Sep 17 00:00:00 2001 From: Starman <30315137+Starman3787@users.noreply.github.com> Date: Sun, 14 Jul 2024 23:02:10 +0100 Subject: [PATCH] upgrade to const --- src/Client.js | 4 ++-- src/gateway/eventHandler.js | 4 ++-- src/gateway/structures/_updatePresence.js | 2 +- src/managers/ChannelMessageManager.js | 6 +++--- src/managers/GuildMemberManager.js | 7 +++---- src/managers/GuildScheduledEventManager.js | 2 +- src/rest/betterRequestHandler.js | 6 +++--- src/rest/getBucket.js | 2 +- src/structures/Guild.js | 4 ++-- src/structures/Member.js | 2 +- src/util/deepCompare.js | 2 +- src/util/updateGuildPreferences.js | 4 ++-- 12 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/Client.js b/src/Client.js index ffeddc8e9..fbd2eb7eb 100644 --- a/src/Client.js +++ b/src/Client.js @@ -633,7 +633,7 @@ class Client extends EventsEmitter { body, ); - let messages = []; + const messages = []; for (let i = 0; i < data.length; i++) messages.push(new Message(this, data[i], data[i].channel_id, guild_id)); @@ -758,7 +758,7 @@ class Client extends EventsEmitter { body, ); if (data.length != 0) { - let members = []; + const members = []; for (let i = 0; i < data.length; i++) members.push( diff --git a/src/gateway/eventHandler.js b/src/gateway/eventHandler.js index 63c3c0a76..40ddef897 100644 --- a/src/gateway/eventHandler.js +++ b/src/gateway/eventHandler.js @@ -286,7 +286,7 @@ class EventHandler { } @ ${this.ws.time()} => THREAD_LIST_SYNC ${data.guild_id}`, ); - let threads = []; + const threads = []; for (let i = 0; i < data.threads.length; i++) threads.push(new Thread(this._client, data.threads[i], data.guild_id)); @@ -543,7 +543,7 @@ class EventHandler { } @ ${this.ws.time()} => MESSAGE_DELETE_BULK ${data.guild_id}`, ); - let messages = []; + const messages = []; for (let i = 0; i < data.ids.length; i++) messages.push( getMessage( diff --git a/src/gateway/structures/_updatePresence.js b/src/gateway/structures/_updatePresence.js index b11c88295..db1adfc0e 100644 --- a/src/gateway/structures/_updatePresence.js +++ b/src/gateway/structures/_updatePresence.js @@ -7,7 +7,7 @@ function _updatePresence( afk = false, since = null, ) { - let activities = []; + const activities = []; if (name) activities.push({ diff --git a/src/managers/ChannelMessageManager.js b/src/managers/ChannelMessageManager.js index c7593ad2c..11bc82435 100644 --- a/src/managers/ChannelMessageManager.js +++ b/src/managers/ChannelMessageManager.js @@ -27,7 +27,7 @@ class ChannelMessageManager { async fetch(options) { if (typeof options == "object") { if (this.cache.size != 0) { - let cachedMessages = []; + const cachedMessages = []; this.cache.forEach((key, value) => { if (options.before && value.id < options.before) cachedMessages.push(value); @@ -49,7 +49,7 @@ class ChannelMessageManager { [this.channel.id], body, ); - let messages = []; + const messages = []; for (let i = 0; i < data.length; i++) messages.push( new Message( @@ -87,7 +87,7 @@ class ChannelMessageManager { this.channel.id, ]); - let messages = []; + const messages = []; for (let i = 0; i < data.length; i++) messages.push( new Message( diff --git a/src/managers/GuildMemberManager.js b/src/managers/GuildMemberManager.js index 5d7ccaa63..d0bb47247 100644 --- a/src/managers/GuildMemberManager.js +++ b/src/managers/GuildMemberManager.js @@ -123,12 +123,11 @@ class GuildMemberManager { * @param {BigInt | String} user_id The id of the member to get. * @returns {Member} */ - async localFetch(user_id) { + localFetch(user_id) { const cached = this.cache.get(user_id.toString()); if (cached) return cached; - const stored = await this.retrieve(user_id); - if (stored) return stored; + return this.retrieve(user_id); } /** @@ -172,7 +171,7 @@ class GuildMemberManager { body, ); if (data.length != 0) { - let members = []; + const members = []; for (let i = 0; i < data.length; i++) members.push( diff --git a/src/managers/GuildScheduledEventManager.js b/src/managers/GuildScheduledEventManager.js index 6052c0597..7c4191e24 100644 --- a/src/managers/GuildScheduledEventManager.js +++ b/src/managers/GuildScheduledEventManager.js @@ -21,7 +21,7 @@ class GuildScheduledEventManager { [this.guild.id], ); - let eventsList = []; + const eventsList = []; for (let i = 0; i < data.length; i++) eventsList.push(new ScheduledEvent(this._client, data[i])); diff --git a/src/rest/betterRequestHandler.js b/src/rest/betterRequestHandler.js index 31153b38f..8840b3194 100644 --- a/src/rest/betterRequestHandler.js +++ b/src/rest/betterRequestHandler.js @@ -191,14 +191,14 @@ class BetterRequestHandler { new Date().getTime() / 1000 > bucket.reset + this.latency) ) { const serialize = (obj) => { - let str = []; + const str = []; for (let p in obj) if (Object.prototype.hasOwnProperty.call(obj, p)) str.push(`${encodeURIComponent(p)}=${encodeURIComponent(obj[p])}`); return str.join("&"); }; - let headers = { + const headers = { Authorization: this.authorization, "User-Agent": `DiscordBot (${require("../../package.json").repository.url.slice( 4, @@ -327,7 +327,7 @@ class BetterRequestHandler { this._client.emit("debug", `REMOVE ${hash} from request queue`); } else { - let retryNextIn = + const retryNextIn = Math.ceil(bucket.reset - new Date().getTime() / 1000) + this.latency; setTimeout(() => { diff --git a/src/rest/getBucket.js b/src/rest/getBucket.js index c27d191dc..0401788ea 100644 --- a/src/rest/getBucket.js +++ b/src/rest/getBucket.js @@ -1,7 +1,7 @@ async function getBucket(client, localRatelimitCache, hash) { if (client.redis) { try { - let rawBucket = (await client.redis.get(`gluon.paths.${hash}`)) || "{}"; + const rawBucket = (await client.redis.get(`gluon.paths.${hash}`)) || "{}"; return JSON.parse(rawBucket); } catch (error) { diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 3b708ecb2..6f0ac07a8 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -512,7 +512,7 @@ class Guild { * @type {String} */ get system_channel_flags() { - let flags = []; + const flags = []; if ((this._attributes & (0b1 << 0)) == 0b1 << 0) flags.push("SUPPRESS_JOIN_NOTIFICATIONS"); @@ -806,7 +806,7 @@ class Guild { this.id, ]); - let channels = []; + const channels = []; for (let i = 0; i < data.length; i++) channels.push(cacheChannel(this._client, data[i], this.id.toString())); diff --git a/src/structures/Member.js b/src/structures/Member.js index e1532b293..33a3a9ad8 100644 --- a/src/structures/Member.js +++ b/src/structures/Member.js @@ -145,7 +145,7 @@ class Member { get roles() { if (this._client.cacheRoles != true) return []; - let roles = []; + const roles = []; roles.push(this.guild.roles.cache.get(String(this._guild_id))); diff --git a/src/util/deepCompare.js b/src/util/deepCompare.js index c895794d6..be221529e 100644 --- a/src/util/deepCompare.js +++ b/src/util/deepCompare.js @@ -9,7 +9,7 @@ function deepCompare(object0, object1) { const keys1 = Object.keys(object1); const keys = [...new Set(keys0.concat(keys1))]; - let updatedFields = []; + const updatedFields = []; for (let i = 0; i < keys.length; i++) { if (object0[keys[i]] != object1[keys[i]]) updatedFields.push(keys[i]); diff --git a/src/util/updateGuildPreferences.js b/src/util/updateGuildPreferences.js index f0ae10aaf..09cbb995b 100644 --- a/src/util/updateGuildPreferences.js +++ b/src/util/updateGuildPreferences.js @@ -13,7 +13,7 @@ function updatePreferences(client, guild) { } function updateSingleGuildPreferences(client, guild) { - let currentGuild = client.guilds.cache.get(guild.id); + const currentGuild = client.guilds.cache.get(guild.id); if (!currentGuild) return; currentGuild._cache_options = 0; if (guild.options.serverLog == null) { @@ -32,7 +32,7 @@ function updateSingleGuildPreferences(client, guild) { j < guild.options.additionalServerLogOptions.ignoreChannels.length; j++ ) { - let currentGuildChannel = currentGuild.channels.cache.get( + const currentGuildChannel = currentGuild.channels.cache.get( guild.options.additionalServerLogOptions.ignoreChannels[j] ); if (!currentGuildChannel) continue;