From c793cf6c02699b1f3dfb07606ddd2aa5719afad2 Mon Sep 17 00:00:00 2001 From: Jaron <60853956+JaronZ@users.noreply.github.com> Date: Thu, 27 Jul 2023 23:53:26 +0200 Subject: [PATCH] refactor: use container env (#372) use container.env instead of process.env --- src/augment.d.ts | 14 -------------- src/bot.ts | 6 +++--- src/commands/support.ts | 2 +- src/listeners/client/guildCreate.ts | 2 +- src/listeners/client/guildDelete.ts | 2 +- src/logger.ts | 2 +- 6 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/augment.d.ts b/src/augment.d.ts index 64e245ef..933c2e6d 100644 --- a/src/augment.d.ts +++ b/src/augment.d.ts @@ -2,7 +2,6 @@ import type {PrismaClient} from "@prisma/client"; import {Player} from "discord-player"; import type {parseEnv} from "./lib/Env"; -export * from "@sapphire/pieces"; declare module "@sapphire/pieces" { export interface Container { player: Player; @@ -10,16 +9,3 @@ declare module "@sapphire/pieces" { env: ReturnType; } } - -declare global { - namespace NodeJS { - interface ProcessEnv { - GUILD: string; - OWNER: string; - CLIENT_ID: string; - CONSOLE_URL: string; - GUILDS_URL: string; - STATCORD_API_KEY: string; - } - } -} diff --git a/src/bot.ts b/src/bot.ts index b9eede3b..19f0eb93 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -10,11 +10,12 @@ import {PrismaClient} from "@prisma/client"; import {parseEnv} from "./lib/Env"; config(); +container.env = parseEnv(); const client = new SapphireClient({ intents: [IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildVoiceStates], statcord: { - client_id: process.env.CLIENT_ID, - key: process.env.STATCORD_API_KEY, + client_id: container.env.CLIENT, + key: container.env.STATCORD_API_KEY, autopost: true, debug: true } @@ -29,7 +30,6 @@ container.player = Player.singleton(client, { }); container.logger = new Logger(container, {level: LogLevel.Debug}); container.prisma = new PrismaClient(); -container.env = parseEnv(); async function main() { await container.player.extractors.loadDefault(); diff --git a/src/commands/support.ts b/src/commands/support.ts index 8ad71444..e51d9d56 100644 --- a/src/commands/support.ts +++ b/src/commands/support.ts @@ -13,7 +13,7 @@ export class SupportCommand extends Command { public async chatInputRun(interaction: Command.ChatInputInteraction): Promise { await interaction.deferReply({ephemeral: true}); - const guild = await interaction.client.guilds.fetch(process.env.GUILD); + const guild = await interaction.client.guilds.fetch(this.container.env.GUILD); return interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/listeners/client/guildCreate.ts b/src/listeners/client/guildCreate.ts index c6c1a4e2..9773b515 100644 --- a/src/listeners/client/guildCreate.ts +++ b/src/listeners/client/guildCreate.ts @@ -7,7 +7,7 @@ import {Guild, EmbedBuilder, Colors, WebhookClient} from "discord.js"; }) export class GuildCreateListener extends Listener { public run(guild: Guild): any { - return new WebhookClient({url: process.env.GUILDS_URL}).send({ + return new WebhookClient({url: this.container.env.GUILDS_URL}).send({ embeds: [ new EmbedBuilder() .setColor(Colors.Green) diff --git a/src/listeners/client/guildDelete.ts b/src/listeners/client/guildDelete.ts index 5e5ac746..113bc6c6 100644 --- a/src/listeners/client/guildDelete.ts +++ b/src/listeners/client/guildDelete.ts @@ -7,7 +7,7 @@ import {Guild, EmbedBuilder, Colors, WebhookClient} from "discord.js"; }) export class GuildDeleteListener extends Listener { public run(guild: Guild): any { - return new WebhookClient({url: process.env.GUILDS_URL}).send({ + return new WebhookClient({url: this.container.env.GUILDS_URL}).send({ embeds: [ new EmbedBuilder() .setColor(Colors.Red) diff --git a/src/logger.ts b/src/logger.ts index bab039a4..33df5f8a 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -14,7 +14,7 @@ export class WebhookLogFormat { } export class Logger extends SapphireLogger { - private readonly webhook = new WebhookClient({url: process.env.CONSOLE_URL}); + private readonly webhook = new WebhookClient({url: sapphireContainer.env.CONSOLE_URL}); private readonly webhookFormats = new Map([ [LogLevel.Trace, new WebhookLogFormat(Colors.Grey, "Trace")], [LogLevel.Debug, new WebhookLogFormat("#ff00ff", "Debug")], // Magenta