From 4e5b91750423a4f628d8ffec1e0a730fa08c37be Mon Sep 17 00:00:00 2001 From: Alexander Emanuelsson Date: Wed, 31 Jul 2024 14:44:44 +0200 Subject: [PATCH] Use client directly in discordTools instead of passing as argument --- index.ts | 2 +- src/commands/blacklist.js | 4 +- src/commands/credentials.js | 10 +-- src/commands/reset.js | 28 ++++---- src/commands/role.js | 2 +- src/discordEvents/messageCreate.ts | 8 +-- src/discordTools/discord-embeds.ts | 10 +-- src/discordTools/discord-tools.ts | 79 +++++++++++++++------- src/discordTools/discordMessages.js | 4 +- src/discordTools/remove-guild-channels.ts | 4 +- src/discordTools/setup-guild-category.ts | 5 +- src/discordTools/setup-guild-channels.ts | 4 +- src/discordTools/setup-server-list.ts | 2 +- src/discordTools/setup-settings-menu.ts | 4 +- src/discordTools/setup-storage-monitors.ts | 2 +- src/discordTools/setup-switch-groups.ts | 2 +- src/discordTools/setup-switches.ts | 2 +- src/discordTools/setup-trackers.ts | 2 +- src/handlers/battlemetricsHandler.js | 2 +- src/handlers/buttonHandler.js | 28 ++++---- src/handlers/discordCommandHandler.js | 4 +- src/handlers/permissionHandler.js | 4 +- src/handlers/selectMenuHandler.js | 2 +- src/structures/DiscordBot.js | 4 +- src/structures/RustPlus.js | 2 +- src/util/FcmListener.js | 5 +- src/util/FcmListenerLite.js | 2 +- 27 files changed, 129 insertions(+), 98 deletions(-) diff --git a/index.ts b/index.ts index 21c364351..42cbb0c67 100644 --- a/index.ts +++ b/index.ts @@ -51,7 +51,7 @@ createMissingDirectories(); export const log = Logger.createLogger('logs/rustplusplus.log'); export const localeManager = new LocaleManager(Config.general.language); -const client = new DiscordBot({ +export const client = new DiscordBot({ intents: [ Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMessages, diff --git a/src/commands/blacklist.js b/src/commands/blacklist.js index 171a2e6d7..e2e9097ac 100644 --- a/src/commands/blacklist.js +++ b/src/commands/blacklist.js @@ -78,7 +78,7 @@ module.exports = { return; } - const guild = await discordToolsgetGuild(client, guildId); + const guild = await discordTools.getGuild(guildId); switch (interaction.options.getSubcommand()) { case 'add': { @@ -216,7 +216,7 @@ module.exports = { let steamIds = ''; for (const discordId of instance.blacklist['discordIds']) { - const user = await discordToolsgetMember(client, guildId, discordId) + const user = await discordTools.getMember(guildId, discordId) let name = ''; if (user) name = `${user.user.username} (${user.id})`; else name = `${discordId}`; diff --git a/src/commands/credentials.js b/src/commands/credentials.js index c10591e69..ad1515e5d 100644 --- a/src/commands/credentials.js +++ b/src/commands/credentials.js @@ -182,13 +182,13 @@ async function addCredentials(client, interaction, verifyId) { /* Start Fcm Listener */ if (isHoster) { - require('../util/FcmListener')(client, await discordTools.getGuild(client, interaction.guildId)); + require('../util/FcmListener')(client, await discordTools.getGuild(interaction.guildId)); if (prevHoster !== null) { - require('../util/FcmListenerLite')(client, await discordTools.getGuild(client, interaction.guildId), prevHoster); + require('../util/FcmListenerLite')(client, await discordTools.getGuild(interaction.guildId), prevHoster); } } else { - require('../util/FcmListenerLite')(client, await discordTools.getGuild(client, interaction.guildId), steamId); + require('../util/FcmListenerLite')(client, await discordTools.getGuild(interaction.guildId), steamId); const rustplus = client.rustplusInstances[guildId]; if (rustplus && rustplus.team.leaderSteamId === steamId) { @@ -329,9 +329,9 @@ async function setHosterCredentials(client, interaction, verifyId) { await DiscordMessages.sendServerMessage(guildId, rustplus.serverId); } - require('../util/FcmListener')(client, await discordTools.getGuild(client, interaction.guildId)); + require('../util/FcmListener')(client, await discordTools.getGuild(interaction.guildId)); if (prevHoster !== null) { - require('../util/FcmListenerLite')(client, await discordTools.getGuild(client, interaction.guildId), prevHoster); + require('../util/FcmListenerLite')(client, await discordTools.getGuild(interaction.guildId), prevHoster); } log.info(client.intlGet(null, 'slashCommandValueChange', { diff --git a/src/commands/reset.js b/src/commands/reset.js index db18558bc..1a3779ce7 100644 --- a/src/commands/reset.js +++ b/src/commands/reset.js @@ -86,7 +86,7 @@ module.exports = { return; } - const guild = await discordTools.getGuild(client, interaction.guildId); + const guild = await discordTools.getGuild(interaction.guildId); switch (interaction.options.getSubcommand()) { case 'discord': { @@ -103,10 +103,10 @@ module.exports = { /* Ignore */ } - await discordTools.clearTextChannel(client, guild.id, instance.channelIds.information, 100); - await discordTools.clearTextChannel(client, guild.id, instance.channelIds.switches, 100); - await discordTools.clearTextChannel(client, guild.id, instance.channelIds.switchGroups, 100); - await discordTools.clearTextChannel(client, guild.id, instance.channelIds.storageMonitors, 100); + await discordTools.clearTextChannel(guild.id, instance.channelIds.information, 100); + await discordTools.clearTextChannel(guild.id, instance.channelIds.switches, 100); + await discordTools.clearTextChannel(guild.id, instance.channelIds.switchGroups, 100); + await discordTools.clearTextChannel(guild.id, instance.channelIds.storageMonitors, 100); const rustplus = client.rustplusInstances[guild.id]; if (rustplus && rustplus.isOperational) { @@ -135,7 +135,7 @@ module.exports = { } break; case 'information': { - await discordTools.clearTextChannel(client, guild.id, instance.channelIds.information, 100); + await discordTools.clearTextChannel(guild.id, instance.channelIds.information, 100); const rustplus = client.rustplusInstances[guild.id]; if (rustplus && rustplus.isOperational) { @@ -152,7 +152,7 @@ module.exports = { case 'servers': { const perms = PermissionHandler.getPermissionsRemoved(client, guild); try { - const category = await discordTools.getCategory(client, guild.id, instance.channelIds.category); + const category = await discordTools.getCategory(guild.id, instance.channelIds.category); await category.permissionOverwrites.set(perms); } catch (e) { @@ -172,7 +172,7 @@ module.exports = { case 'settings': { const perms = PermissionHandler.getPermissionsRemoved(client, guild); try { - const category = await discordTools.getCategory(client, guild.id, instance.channelIds.category); + const category = await discordTools.getCategory(guild.id, instance.channelIds.category); await category.permissionOverwrites.set(perms); } catch (e) { @@ -190,12 +190,12 @@ module.exports = { } break; case 'switches': { - await discordTools.clearTextChannel(client, guild.id, instance.channelIds.switches, 100); - await discordTools.clearTextChannel(client, guild.id, instance.channelIds.switchGroups, 100); + await discordTools.clearTextChannel(guild.id, instance.channelIds.switches, 100); + await discordTools.clearTextChannel(guild.id, instance.channelIds.switchGroups, 100); const perms = PermissionHandler.getPermissionsRemoved(client, guild); try { - const category = await discordTools.getCategory(client, guild.id, instance.channelIds.category); + const category = await discordTools.getCategory(guild.id, instance.channelIds.category); await category.permissionOverwrites.set(perms); } catch (e) { @@ -229,11 +229,11 @@ module.exports = { } break; case 'storagemonitors': { - await discordTools.clearTextChannel(client, guild.id, instance.channelIds.storageMonitors, 100); + await discordTools.clearTextChannel(guild.id, instance.channelIds.storageMonitors, 100); const perms = PermissionHandler.getPermissionsRemoved(client, guild); try { - const category = await discordTools.getCategory(client, guild.id, instance.channelIds.category); + const category = await discordTools.getCategory(guild.id, instance.channelIds.category); await category.permissionOverwrites.set(perms); } catch (e) { @@ -256,7 +256,7 @@ module.exports = { case 'trackers': { const perms = PermissionHandler.getPermissionsRemoved(client, guild); try { - const category = await discordTools.getCategory(client, guild.id, instance.channelIds.category); + const category = await discordTools.getCategory(guild.id, instance.channelIds.category); await category.permissionOverwrites.set(perms); } catch (e) { diff --git a/src/commands/role.js b/src/commands/role.js index 30ad16d32..0b7410748 100644 --- a/src/commands/role.js +++ b/src/commands/role.js @@ -86,7 +86,7 @@ module.exports = { value: `${interaction.options.getSubcommand()}` })); - const guild = await discordTools.getGuild(client, interaction.guildId); + const guild = await discordTools.getGuild(interaction.guildId); if (guild) { const category = await setupGuildCategory(client, guild); await setupGuildChannels(client, guild, category); diff --git a/src/discordEvents/messageCreate.ts b/src/discordEvents/messageCreate.ts index 7424d3f68..f1a6e880b 100644 --- a/src/discordEvents/messageCreate.ts +++ b/src/discordEvents/messageCreate.ts @@ -38,9 +38,9 @@ export async function execute(client: typeof DiscordBot, message: Message) { if (instance.blacklist['discordIds'].includes(message.author.id) && Object.values(instance.channelIds).includes(message.channelId)) { - const guild = await discordTools.getGuild(client, guildId); + const guild = await discordTools.getGuild(guildId); if (!guild) return; - const channel = await discordTools.getTextChannel(client, guild.id, message.channelId); + const channel = await discordTools.getTextChannel(guild.id, message.channelId); if (!channel) return; log.info(client.intlGet(null, `userPartOfBlacklistDiscord`, { guild: `${guild.name} (${guild.id})`, @@ -55,9 +55,9 @@ export async function execute(client: typeof DiscordBot, message: Message) { await DiscordCommandHandler.discordCommandHandler(rustplus, client, message); } else if (message.channelId === instance.channelIds.teamchat) { - const guild = await discordTools.getGuild(client, guildId); + const guild = await discordTools.getGuild(guildId); if (!guild) return; - const channel = await discordTools.getTextChannel(client, guild.id, message.channelId); + const channel = await discordTools.getTextChannel(guild.id, message.channelId); if (!channel) return; log.info(client.intlGet(null, `logDiscordMessage`, { guild: `${guild.name} (${guild.id})`, diff --git a/src/discordTools/discord-embeds.ts b/src/discordTools/discord-embeds.ts index 8052d635e..b2582d2d2 100644 --- a/src/discordTools/discord-embeds.ts +++ b/src/discordTools/discord-embeds.ts @@ -114,7 +114,7 @@ export async function getServerEmbed(client: typeof DiscordBot, guildId: string, let hoster = lm.getIntl(language, 'unknown'); if (creds.hasOwnProperty(server.steamId)) { - const member = await discordTools.getMember(client, guildId, creds[server.steamId].discordUserId); + const member = await discordTools.getMember(guildId, creds[server.steamId].discordUserId); if (member !== undefined) { hoster = member.user.username; } @@ -555,7 +555,7 @@ export async function getStorageMonitorNotFoundEmbed(client: typeof DiscordBot, const server = instance.serverList[serverId]; const entity = server.storageMonitors[entityId]; const creds = credentials.readCredentialsFile(); - const user = await discordTools.getMember(client, guildId, creds[server.steamId].discordUserId); + const user = await discordTools.getMember(guildId, creds[server.steamId].discordUserId); const grid = entity.location !== null ? ` (${entity.location})` : ''; return getEmbed({ @@ -578,7 +578,7 @@ export async function getSmartSwitchNotFoundEmbed(client: typeof DiscordBot, gui const server = instance.serverList[serverId]; const entity = instance.serverList[serverId].switches[entityId]; const creds = credentials.readCredentialsFile(); - const user = await discordTools.getMember(client, guildId, creds[server.steamId].discordUserId); + const user = await discordTools.getMember(guildId, creds[server.steamId].discordUserId); const grid = entity.location !== null ? ` (${entity.location})` : ''; return getEmbed({ @@ -601,7 +601,7 @@ export async function getSmartAlarmNotFoundEmbed(client: typeof DiscordBot, guil const server = instance.serverList[serverId]; const entity = server.alarms[entityId]; const creds = credentials.readCredentialsFile(); - const user = await discordTools.getMember(client, guildId, creds[server.steamId].discordUserId); + const user = await discordTools.getMember(guildId, creds[server.steamId].discordUserId); const grid = entity.location !== null ? ` (${entity.location})` : ''; return getEmbed({ @@ -1073,7 +1073,7 @@ export async function getCredentialsShowEmbed(client: typeof DiscordBot, guildId let hoster = ''; for (const credential in creds) { - const user = await discordTools.getMember(client, guildId, creds[credential].discordUserId); + const user = await discordTools.getMember(guildId, creds[credential].discordUserId); names += `${user !== undefined ? user.user.username : lm.getIntl(language, 'unknown')}\n`; steamIds += `${credential}\n`; hoster += `${credential === instance.hoster ? `${constants.LEADER_EMOJI}\n` : '\u200B\n'}`; diff --git a/src/discordTools/discord-tools.ts b/src/discordTools/discord-tools.ts index 81fa12bb4..118ea5abe 100644 --- a/src/discordTools/discord-tools.ts +++ b/src/discordTools/discord-tools.ts @@ -20,12 +20,12 @@ import * as discordjs from 'discord.js'; -import { log } from '../../index'; +import { log, client } from '../../index'; import { localeManager as lm } from '../../index'; const Config = require('../../config'); const { DiscordBot } = require('../structures/DiscordBot.js'); -export async function getGuild(client: typeof DiscordBot, guildId: string): Promise { +export async function getGuild(guildId: string): Promise { try { if (!Config.discord.useCache) { await client.guilds.fetch(); @@ -38,9 +38,9 @@ export async function getGuild(client: typeof DiscordBot, guildId: string): Prom return undefined; } -export async function getRole(client: typeof DiscordBot, guildId: string, role: string, isRoleId: boolean = true): +export async function getRole(guildId: string, role: string, isRoleId: boolean = true): Promise { - const guild = await getGuild(client, guildId); + const guild = await getGuild(guildId); if (guild instanceof discordjs.Guild) { try { @@ -61,9 +61,9 @@ export async function getRole(client: typeof DiscordBot, guildId: string, role: return undefined; } -export async function getMember(client: typeof DiscordBot, guildId: string, member: string, isMemberId: boolean = true): +export async function getMember(guildId: string, member: string, isMemberId: boolean = true): Promise { - const guild = await getGuild(client, guildId); + const guild = await getGuild(guildId); if (guild instanceof discordjs.Guild) { try { @@ -84,9 +84,9 @@ export async function getMember(client: typeof DiscordBot, guildId: string, memb return undefined; } -async function getChannel(client: typeof DiscordBot, guildId: string, channel: string, isChannelId: boolean = true): +async function getChannel(guildId: string, channel: string, isChannelId: boolean = true): Promise { - const guild = await getGuild(client, guildId); + const guild = await getGuild(guildId); if (guild instanceof discordjs.Guild) { try { @@ -107,30 +107,30 @@ async function getChannel(client: typeof DiscordBot, guildId: string, channel: s return undefined; } -export async function getTextChannel(client: typeof DiscordBot, guildId: string, channel: string, +export async function getTextChannel(guildId: string, channel: string, isChannelId: boolean = true): Promise { - const ch = await getChannel(client, guildId, channel, isChannelId); + const ch = await getChannel(guildId, channel, isChannelId); if (ch && ch.type === discordjs.ChannelType.GuildText) { return ch as discordjs.TextChannel; } return undefined; } -export async function getCategory(client: typeof DiscordBot, guildId: string, category: string, +export async function getCategory(guildId: string, category: string, isCategoryId: boolean = true): Promise { - const categoryChannel = await getChannel(client, guildId, category, isCategoryId); + const categoryChannel = await getChannel(guildId, category, isCategoryId); if (categoryChannel && categoryChannel.type === discordjs.ChannelType.GuildCategory) { return categoryChannel as discordjs.CategoryChannel; } return undefined; } -export async function getMessage(client: typeof DiscordBot, guildId: string, channelId: string, messageId: string): +export async function getMessage(guildId: string, channelId: string, messageId: string): Promise { - const guild = await getGuild(client, guildId); + const guild = await getGuild(guildId); if (guild instanceof discordjs.Guild) { - const channel = await getTextChannel(client, guildId, channelId); + const channel = await getTextChannel(guildId, channelId); if (channel instanceof discordjs.TextChannel) { try { @@ -145,9 +145,8 @@ export async function getMessage(client: typeof DiscordBot, guildId: string, cha return undefined; } -export async function deleteMessage(client: typeof DiscordBot, guildId: string, channelId: string, messageId: string): - Promise { - const message = await getMessage(client, guildId, channelId, messageId); +export async function deleteMessage(guildId: string, channelId: string, messageId: string): Promise { + const message = await getMessage(guildId, channelId, messageId); if (message instanceof discordjs.Message) { try { await message.delete(); @@ -159,10 +158,10 @@ export async function deleteMessage(client: typeof DiscordBot, guildId: string, return false; } -export async function createChannel(client: typeof DiscordBot, guildId: string, name: string, +export async function createChannel(guildId: string, name: string, type: discordjs.ChannelType.GuildCategory | discordjs.ChannelType.GuildText): Promise { - const guild = await getGuild(client, guildId); + const guild = await getGuild(guildId); if (guild instanceof discordjs.Guild) { try { @@ -187,9 +186,9 @@ export async function createChannel(client: typeof DiscordBot, guildId: string, return undefined; } -export async function deleteChannel(client: typeof DiscordBot, guildId: string, channel: string, +export async function deleteChannel(guildId: string, channel: string, isChannelId: boolean = true): Promise { - const ch = await getChannel(client, guildId, channel, isChannelId); + const ch = await getChannel(guildId, channel, isChannelId); if (ch) { try { await ch.delete(); @@ -201,9 +200,9 @@ export async function deleteChannel(client: typeof DiscordBot, guildId: string, return false; } -export async function clearTextChannel(client: typeof DiscordBot, guildId: string, channelId: string, +export async function clearTextChannel(guildId: string, channelId: string, numberOfMessages: number): Promise { - const channel = await getTextChannel(client, guildId, channelId); + const channel = await getTextChannel(guildId, channelId); if (channel instanceof discordjs.TextChannel) { try { @@ -311,4 +310,36 @@ export async function messageEdit(message: discordjs.Message, content: discordjs } return undefined; +} + +/* Only used for messages/interactions to a guild text channel message, not member PM. */ +export async function sendUpdateMessage(guildId: string, content: discordjs.MessageCreateOptions | + discordjs.MessageEditOptions, channelId: string | null, messageId: string | null, interaction: discordjs.Interaction | null = null): + Promise { + if (interaction !== null) { + await interactionUpdate(interaction, content as discordjs.InteractionUpdateOptions); + return undefined; + } + + if (channelId === null) { + return undefined; + } + + const message = messageId !== null ? await getMessage(guildId, channelId, messageId) : undefined; + if (message !== undefined) { + /* Message already exist, so update it. */ + return await messageEdit(message, content as discordjs.MessageEditOptions); + } + else { + /* Message does not exist, so create it. */ + const channel = await getTextChannel(guildId, channelId); + + if (channel instanceof discordjs.TextChannel) { + return await messageSend(channel, content as discordjs.MessageCreateOptions); + } + else { + log.error(lm.getIntl(Config.general.language, 'couldNotGetChannelWithId', { id: channelId })); + return undefined; + } + } } \ No newline at end of file diff --git a/src/discordTools/discordMessages.js b/src/discordTools/discordMessages.js index a938ac981..7ec79f568 100644 --- a/src/discordTools/discordMessages.js +++ b/src/discordTools/discordMessages.js @@ -38,13 +38,13 @@ module.exports = { } let message = messageId !== null ? - await discordTools.getMessage(Client.client, guildId, channelId, messageId) : undefined; + await discordTools.getMessage(guildId, channelId, messageId) : undefined; if (message !== undefined) { return await discordTools.messageEdit(message, content); } else { - const channel = await discordTools.getTextChannel(Client.client, guildId, channelId); + const channel = await discordTools.getTextChannel(guildId, channelId); if (!channel) { log.error(Client.client.intlGet(null, 'couldNotGetChannelWithId', { id: channelId })); diff --git a/src/discordTools/remove-guild-channels.ts b/src/discordTools/remove-guild-channels.ts index 18854e8f5..c7d593400 100644 --- a/src/discordTools/remove-guild-channels.ts +++ b/src/discordTools/remove-guild-channels.ts @@ -34,11 +34,11 @@ export async function removeGuildChannels(client: typeof DiscordBot, guild: Guil continue; } - await discordTools.deleteChannel(client, guildId, channelId as string); + await discordTools.deleteChannel(guildId, channelId as string); instance.channelIds[channelName] = null; } - await discordTools.deleteChannel(client, guildId, categoryId as string); + await discordTools.deleteChannel(guildId, categoryId as string); instance.channelIds['category'] = null; client.setInstance(guildId, instance); diff --git a/src/discordTools/setup-guild-category.ts b/src/discordTools/setup-guild-category.ts index f97a1739b..ca075f108 100644 --- a/src/discordTools/setup-guild-category.ts +++ b/src/discordTools/setup-guild-category.ts @@ -31,10 +31,11 @@ export async function setupGuildCategory(client: typeof DiscordBot, guild: Guild let category = undefined; if (instance.channelIds.category !== null) { - category = await discordTools.getCategory(client, guildId, instance.channelIds.category); + category = await discordTools.getCategory(guildId, instance.channelIds.category); } if (category === undefined) { - category = await discordTools.createChannel(client, guildId, 'rustplusplus', ChannelType.GuildCategory) as CategoryChannel; + category = await discordTools.createChannel(guildId, 'rustplusplus', + ChannelType.GuildCategory) as CategoryChannel; if (!category) return undefined; instance.channelIds.category = category.id; client.setInstance(guildId, instance); diff --git a/src/discordTools/setup-guild-channels.ts b/src/discordTools/setup-guild-channels.ts index fbd90e00e..bf08be3b3 100644 --- a/src/discordTools/setup-guild-channels.ts +++ b/src/discordTools/setup-guild-channels.ts @@ -49,10 +49,10 @@ async function addTextChannel(name: string, idName: string, client: typeof Disco let channel = undefined; if (instance.channelIds[idName] !== null) { - channel = await discordTools.getTextChannel(client, guildId, instance.channelIds[idName]); + channel = await discordTools.getTextChannel(guildId, instance.channelIds[idName]); } if (channel === undefined) { - channel = await discordTools.createChannel(client, guildId, name, ChannelType.GuildText) as TextChannel; + channel = await discordTools.createChannel(guildId, name, ChannelType.GuildText) as TextChannel; if (!channel) return undefined; instance.channelIds[idName] = channel.id; client.setInstance(guildId, instance); diff --git a/src/discordTools/setup-server-list.ts b/src/discordTools/setup-server-list.ts index cec74684e..3cc3bdec2 100644 --- a/src/discordTools/setup-server-list.ts +++ b/src/discordTools/setup-server-list.ts @@ -28,7 +28,7 @@ export async function setupServerList(client: typeof DiscordBot, guild: Guild) { const guildId = guild.id; const instance = client.getInstance(guildId); - await discordTools.clearTextChannel(client, guildId, instance.channelIds.servers, 100); + await discordTools.clearTextChannel(guildId, instance.channelIds.servers, 100); for (const serverId in instance.serverList) { await DiscordMessages.sendServerMessage(guildId, serverId); diff --git a/src/discordTools/setup-settings-menu.ts b/src/discordTools/setup-settings-menu.ts index 38f853de1..77348c675 100644 --- a/src/discordTools/setup-settings-menu.ts +++ b/src/discordTools/setup-settings-menu.ts @@ -32,7 +32,7 @@ const { DiscordBot } = require('../structures/DiscordBot.js'); export async function setupSettingsMenu(client: typeof DiscordBot, guild: Guild, forced: boolean = false) { const guildId = guild.id; const instance = client.getInstance(guildId); - const channel = await discordTools.getTextChannel(client, guildId, instance.channelIds.settings); + const channel = await discordTools.getTextChannel(guildId, instance.channelIds.settings); if (!channel) { log.error('SetupSettingsMenu: ' + client.intlGet(null, 'invalidGuildOrChannel')); @@ -40,7 +40,7 @@ export async function setupSettingsMenu(client: typeof DiscordBot, guild: Guild, } if (instance.firstTime || forced) { - await discordTools.clearTextChannel(client, guildId, instance.channelIds.settings, 100); + await discordTools.clearTextChannel(guildId, instance.channelIds.settings, 100); await setupGeneralSettings(client, guildId, channel); await setupNotificationSettings(client, guildId, channel); diff --git a/src/discordTools/setup-storage-monitors.ts b/src/discordTools/setup-storage-monitors.ts index b45036d3c..2925782f8 100644 --- a/src/discordTools/setup-storage-monitors.ts +++ b/src/discordTools/setup-storage-monitors.ts @@ -30,7 +30,7 @@ export async function setupStorageMonitors(client: typeof DiscordBot, rustplus: const serverId = rustplus.serverId; if (rustplus.isNewConnection) { - await discordTools.clearTextChannel(client, guildId, instance.channelIds.storageMonitors, 100); + await discordTools.clearTextChannel(guildId, instance.channelIds.storageMonitors, 100); } for (const entityId in instance.serverList[serverId].storageMonitors) { diff --git a/src/discordTools/setup-switch-groups.ts b/src/discordTools/setup-switch-groups.ts index a570e0dd7..6ea0ba339 100644 --- a/src/discordTools/setup-switch-groups.ts +++ b/src/discordTools/setup-switch-groups.ts @@ -28,7 +28,7 @@ export async function setupSwitchGroups(client: typeof DiscordBot, rustplus: typ const instance = client.getInstance(guildId); if (rustplus.isNewConnection) { - await discordTools.clearTextChannel(client, guildId, instance.channelIds.switchGroups, 100); + await discordTools.clearTextChannel(guildId, instance.channelIds.switchGroups, 100); } for (const groupId in instance.serverList[rustplus.serverId].switchGroups) { diff --git a/src/discordTools/setup-switches.ts b/src/discordTools/setup-switches.ts index 9b8df2729..e393380c6 100644 --- a/src/discordTools/setup-switches.ts +++ b/src/discordTools/setup-switches.ts @@ -29,7 +29,7 @@ export async function setupSwitches(client: typeof DiscordBot, rustplus: typeof const serverId = rustplus.serverId; if (rustplus.isNewConnection) { - await discordTools.clearTextChannel(client, guildId, instance.channelIds.switches, 100); + await discordTools.clearTextChannel(guildId, instance.channelIds.switches, 100); } for (const entityId in instance.serverList[serverId].switches) { diff --git a/src/discordTools/setup-trackers.ts b/src/discordTools/setup-trackers.ts index 79ea49910..ed33850d5 100644 --- a/src/discordTools/setup-trackers.ts +++ b/src/discordTools/setup-trackers.ts @@ -28,7 +28,7 @@ export async function setupTrackers(client: typeof DiscordBot, guild: Guild) { const guildId = guild.id; const instance = client.getInstance(guildId); - await discordTools.clearTextChannel(client, guildId, instance.channelIds.trackers, 100); + await discordTools.clearTextChannel(guildId, instance.channelIds.trackers, 100); for (const trackerId in instance.trackers) { await DiscordMessages.sendTrackerMessage(guildId, trackerId); diff --git a/src/handlers/battlemetricsHandler.js b/src/handlers/battlemetricsHandler.js index 79b3bd533..1776b495d 100644 --- a/src/handlers/battlemetricsHandler.js +++ b/src/handlers/battlemetricsHandler.js @@ -51,7 +51,7 @@ module.exports = { } else { if (instance.informationChannelMessageIds.battlemetricsPlayers !== null) { - await discordTools.deleteMessage(client, guildId, instance.channelIds.information, + await discordTools.deleteMessage(guildId, instance.channelIds.information, instance.informationChannelMessageIds.battlemetricsPlayers); instance.informationChannelMessageIds.battlemetricsPlayers = null; diff --git a/src/handlers/buttonHandler.js b/src/handlers/buttonHandler.js index 1ca84cf75..eca1d08f4 100644 --- a/src/handlers/buttonHandler.js +++ b/src/handlers/buttonHandler.js @@ -480,7 +480,7 @@ module.exports = async (client, interaction) => { const groupsToUpdate = []; for (const [entityId, content] of Object.entries(server.switches)) { if (!content.reachable) { - await discordTools.deleteMessage(client, guildId, instance.channelIds.switches, content.messageId); + await discordTools.deleteMessage(guildId, instance.channelIds.switches, content.messageId); delete server.switches[entityId]; for (const [groupId, groupContent] of Object.entries(server.switchGroups)) { @@ -497,14 +497,14 @@ module.exports = async (client, interaction) => { for (const [entityId, content] of Object.entries(server.alarms)) { if (!content.reachable) { - await discordTools.deleteMessage(client, guildId, instance.channelIds.alarms, content.messageId) + await discordTools.deleteMessage(guildId, instance.channelIds.alarms, content.messageId) delete server.alarms[entityId]; } } for (const [entityId, content] of Object.entries(server.storageMonitors)) { if (!content.reachable) { - await discordTools.deleteMessage(client, guildId, instance.channelIds.storageMonitors, + await discordTools.deleteMessage(guildId, instance.channelIds.storageMonitors, content.messageId) delete server.storageMonitors[entityId]; } @@ -621,9 +621,9 @@ module.exports = async (client, interaction) => { } if (rustplus && (rustplus.serverId === ids.serverId || rustplus.serverId === instance.activeServer)) { - await discordTools.clearTextChannel(client, rustplus.guildId, instance.channelIds.switches, 100); - await discordTools.clearTextChannel(client, rustplus.guildId, instance.channelIds.switchGroups, 100); - await discordTools.clearTextChannel(client, rustplus.guildId, instance.channelIds.storageMonitors, 100); + await discordTools.clearTextChannel(rustplus.guildId, instance.channelIds.switches, 100); + await discordTools.clearTextChannel(rustplus.guildId, instance.channelIds.switchGroups, 100); + await discordTools.clearTextChannel(rustplus.guildId, instance.channelIds.storageMonitors, 100); instance.activeServer = null; client.setInstance(guildId, instance); @@ -639,7 +639,7 @@ module.exports = async (client, interaction) => { await discordTools.deleteMessage(client, guildId, instance.channelIds.alarms, content.messageId); } - await discordTools.deleteMessage(client, guildId, instance.channelIds.servers, server.messageId); + await discordTools.deleteMessage(guildId, instance.channelIds.servers, server.messageId); delete instance.serverList[ids.serverId]; client.setInstance(guildId, instance); @@ -732,7 +732,7 @@ module.exports = async (client, interaction) => { return; } - await discordTools.deleteMessage(client, guildId, instance.channelIds.switches, + await discordTools.deleteMessage(guildId, instance.channelIds.switches, server.switches[ids.entityId].messageId); delete server.switches[ids.entityId]; @@ -785,7 +785,7 @@ module.exports = async (client, interaction) => { return; } - await discordTools.deleteMessage(client, guildId, instance.channelIds.alarms, + await discordTools.deleteMessage(guildId, instance.channelIds.alarms, server.alarms[ids.entityId].messageId); delete server.alarms[ids.entityId]; @@ -867,7 +867,7 @@ module.exports = async (client, interaction) => { return; } - await discordTools.deleteMessage(client, guildId, instance.channelIds.storageMonitors, + await discordTools.deleteMessage(guildId, instance.channelIds.storageMonitors, server.storageMonitors[ids.entityId].messageId); delete server.storageMonitors[ids.entityId]; @@ -907,7 +907,7 @@ module.exports = async (client, interaction) => { guildId, ids.serverId, ids.entityId, items); setTimeout(async () => { - await discordTools.deleteMessage(client, guildId, instance.channelIds.storageMonitors, message.id); + await discordTools.deleteMessage(guildId, instance.channelIds.storageMonitors, message.id); }, 30000); } else if (interaction.customId.startsWith('StorageMonitorContainerDelete')) { @@ -924,7 +924,7 @@ module.exports = async (client, interaction) => { return; } - await discordTools.deleteMessage(client, guildId, instance.channelIds.storageMonitors, + await discordTools.deleteMessage(guildId, instance.channelIds.storageMonitors, server.storageMonitors[ids.entityId].messageId); delete server.storageMonitors[ids.entityId]; @@ -1012,7 +1012,7 @@ module.exports = async (client, interaction) => { } if (server.switchGroups.hasOwnProperty(ids.groupId)) { - await discordTools.deleteMessage(client, guildId, instance.channelIds.switchGroups, + await discordTools.deleteMessage(guildId, instance.channelIds.switchGroups, server.switchGroups[ids.groupId].messageId); delete server.switchGroups[ids.groupId]; @@ -1101,7 +1101,7 @@ module.exports = async (client, interaction) => { return; } - await discordTools.deleteMessage(client, guildId, instance.channelIds.trackers, tracker.messageId); + await discordTools.deleteMessage(guildId, instance.channelIds.trackers, tracker.messageId); delete instance.trackers[ids.trackerId]; client.setInstance(guildId, instance); diff --git a/src/handlers/discordCommandHandler.js b/src/handlers/discordCommandHandler.js index 99fb57a3a..c0691557c 100644 --- a/src/handlers/discordCommandHandler.js +++ b/src/handlers/discordCommandHandler.js @@ -210,8 +210,8 @@ module.exports = { await DiscordMessages.sendDiscordCommandResponseMessage(rustplus, client, message, response); } - const guild = await discordTools.getGuild(client, message.guild.id); - const channel = await discordTools.getTextChannel(client, guild.id, message.channelId) + const guild = await discordTools.getGuild(message.guild.id); + const channel = await discordTools.getTextChannel(guild.id, message.channelId) log.info(client.intlGet(null, `logDiscordCommand`, { guild: `${guild.name} (${guild.id})`, channel: `${channel.name} (${channel.id})`, diff --git a/src/handlers/permissionHandler.js b/src/handlers/permissionHandler.js index 20789fa0a..b8cb4c431 100644 --- a/src/handlers/permissionHandler.js +++ b/src/handlers/permissionHandler.js @@ -95,7 +95,7 @@ module.exports = { if (instance.channelIds.category === null) return; - const category = await discordTools.getCategory(client, guild.id, instance.channelIds.category); + const category = await discordTools.getCategory(guild.id, instance.channelIds.category); if (category) { const perms = module.exports.getPermissionsReset(client, guild); try { @@ -109,7 +109,7 @@ module.exports = { for (const [name, id] of Object.entries(instance.channelIds)) { const writePerm = (name !== 'commands' && name !== 'teamchat') ? false : true; - const channel = await discordTools.getTextChannel(client, guild.id, id); + const channel = await discordTools.getTextChannel(guild.id, id); if (channel) { const perms = module.exports.getPermissionsReset(client, guild, writePerm); try { diff --git a/src/handlers/selectMenuHandler.js b/src/handlers/selectMenuHandler.js index 1109289eb..5e659b243 100644 --- a/src/handlers/selectMenuHandler.js +++ b/src/handlers/selectMenuHandler.js @@ -62,7 +62,7 @@ module.exports = async (client, interaction) => { components: [discordSelectMenus.getLanguageSelectMenu(guildId, interaction.values[0])] }); - const guild = await discordTools.getGuild(client, guildId); + const guild = await discordTools.getGuild(guildId); await registerSlashCommands(client, guild); } else if (interaction.customId === 'Prefix') { diff --git a/src/structures/DiscordBot.js b/src/structures/DiscordBot.js index 7fdee4885..15bd4a2c9 100644 --- a/src/structures/DiscordBot.js +++ b/src/structures/DiscordBot.js @@ -190,7 +190,7 @@ class DiscordBot extends Discord.Client { } async logInteraction(interaction, verifyId, type) { - const channel = await discordTools.getTextChannel(this, interaction.guildId, interaction.channelId); + const channel = await discordTools.getTextChannel(interaction.guildId, interaction.channelId); const args = new Object(); args['guild'] = `${interaction.member.guild.name} (${interaction.member.guild.id})`; args['channel'] = `${channel.name} (${interaction.channelId})`; @@ -468,7 +468,7 @@ class DiscordBot extends Discord.Client { if (!interaction.member.permissions.has(Discord.PermissionsBitField.Flags.Administrator) && !interaction.member.roles.cache.has(instance.roleId)) { - const role = await discordTools.getRole(this, interaction.guildId, instance.roleId); + const role = await discordTools.getRole(interaction.guildId, instance.roleId); const str = this.intlGet(interaction.guildId, 'notPartOfRole', { role: role.name }); await discordTools.interactionReply(interaction, discordEmbeds.getActionInfoEmbed(1, str)); log.warn(str); diff --git a/src/structures/RustPlus.js b/src/structures/RustPlus.js index a5437cb1c..638129996 100644 --- a/src/structures/RustPlus.js +++ b/src/structures/RustPlus.js @@ -2286,7 +2286,7 @@ class RustPlus extends RustPlusLib { } const discordUserId = credentials[player.steamId].discordUserId; - const user = await discordTools.getMember(Client.client, this.guildId, discordUserId); + const user = await discordTools.getMember(this.guildId, discordUserId); const content = { embeds: [discordEmbeds.getUserSendEmbed(this.guildId, this.serverId, callerName, message)] diff --git a/src/util/FcmListener.js b/src/util/FcmListener.js index 067713fc5..5ab1d3424 100644 --- a/src/util/FcmListener.js +++ b/src/util/FcmListener.js @@ -195,8 +195,7 @@ async function pairingServer(client, guild, full, data, body) { const server = instance.serverList[serverId]; let message = undefined; - if (server) message = await discordTools.getMessage(client, guild.id, - instance.channelIds.servers, server.messageId); + if (server) message = await discordTools.getMessage(guild.id, instance.channelIds.servers, server.messageId); let battlemetricsId = null; const bmInstance = new Battlemetrics(null, data.title); @@ -481,7 +480,7 @@ async function alarmRaidAlarm(client, guild, full, data, body) { } async function playerDeath(client, guild, full, data, body, discordUserId) { - const user = await discordTools.getMember(client, guild.id, discordUserId); + const user = await discordTools.getMember(guild.id, discordUserId); let png = null; if (body.targetId !== '') png = await Request.requestSteamProfilePicture(body.targetId); diff --git a/src/util/FcmListenerLite.js b/src/util/FcmListenerLite.js index f7ad8b4e3..c12cbe736 100644 --- a/src/util/FcmListenerLite.js +++ b/src/util/FcmListenerLite.js @@ -331,7 +331,7 @@ async function pairingEntityStorageMonitor(client, guild, full, data, body) { } async function playerDeath(client, guild, full, data, body, discordUserId) { - const user = await discordTools.getMember(client, guild.id, discordUserId); + const user = await discordTools.getMember(guild.id, discordUserId); if (!user) return; let png = null;