Skip to content

Commit

Permalink
refactor: use container env (#372)
Browse files Browse the repository at this point in the history
use container.env instead of process.env
  • Loading branch information
JaronZ authored Jul 27, 2023
1 parent 6025055 commit c3fdd88
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 21 deletions.
14 changes: 0 additions & 14 deletions src/augment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,10 @@ 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;
prisma: PrismaClient;
env: ReturnType<typeof parseEnv>;
}
}

declare global {
namespace NodeJS {
interface ProcessEnv {
GUILD: string;
OWNER: string;
CLIENT_ID: string;
CONSOLE_URL: string;
GUILDS_URL: string;
STATCORD_API_KEY: string;
}
}
}
6 changes: 3 additions & 3 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class SupportCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputInteraction): Promise<any> {
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()
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/client/guildCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Guild, EmbedBuilder, Colors, WebhookClient} from "discord.js";
})
export class GuildCreateListener extends Listener<typeof Events.GuildCreate> {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/client/guildDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Guild, EmbedBuilder, Colors, WebhookClient} from "discord.js";
})
export class GuildDeleteListener extends Listener<typeof Events.GuildDelete> {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, WebhookLogFormat>([
[LogLevel.Trace, new WebhookLogFormat(Colors.Grey, "Trace")],
[LogLevel.Debug, new WebhookLogFormat("#ff00ff", "Debug")], // Magenta
Expand Down

0 comments on commit c3fdd88

Please sign in to comment.