Skip to content

Commit 67d0c18

Browse files
committed
style: update file based on suggestions
1 parent c40d5a7 commit 67d0c18

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ TWITCH_CLIENT_SECRET='YOUR_TWITCH_CLIENT_SECRET'
1717
CONFIG_UPDATE_INTERVAL_YOUTUBE='10'
1818
CONFIG_UPDATE_INTERVAL_TWITCH='2'
1919
CONFIG_DISCORD_LOGS_CHANNEL='YOUR_DISCORD_LOGS_CHANNEL'
20+
CONFIG_DISCORD_WAIT_FOR_GUILD_CACHE_TIME='YOUR_TIME_IN_SECONDS'
2021

2122
# Postgres URLs
2223
POSTGRES_URL='postgresql://user:password@server:port/database'

src/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface Config {
44
updateIntervalYouTube: number;
55
updateIntervalTwitch: number;
66
databaseUrl: string | undefined;
7+
discordWaitForGuildCacheTime: number;
78
}
89

910
export const config: Config = {
@@ -16,6 +17,10 @@ export const config: Config = {
1617
databaseUrl: runningInDevMode
1718
? process.env?.POSTGRES_DEV_URL
1819
: process.env?.POSTGRES_URL,
20+
discordWaitForGuildCacheTime: process.env
21+
?.CONFIG_DISCORD_WAIT_FOR_GUILD_CACHE_TIME
22+
? parseInt(process.env?.CONFIG_DISCORD_WAIT_FOR_GUILD_CACHE_TIME) * 1000
23+
: 10_000,
1924
};
2025

2126
interface Env {

src/utils/discord/updateGuildsOnStartup.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { eq } from "drizzle-orm";
44
import { dbDiscordTable } from "../../db/schema";
55
import client from "../..";
66
import { db } from "../../db/db";
7+
import { config } from "../../config";
78

89
export default async function () {
910
console.log("Checking for guilds to update on startup...");
@@ -15,7 +16,9 @@ export default async function () {
1516
console.log("Waiting for guilds to load...");
1617
currentGuilds = client.guilds.cache.map((guild) => guild.id);
1718
if (currentGuilds.length === 0) {
18-
await new Promise((resolve) => setTimeout(resolve, 10000));
19+
await new Promise((resolve) =>
20+
setTimeout(resolve, config.discordWaitForGuildCacheTime),
21+
);
1922
}
2023
}
2124

@@ -47,7 +50,7 @@ export default async function () {
4750
.where(eq(dbDiscordTable.guildId, guild.guildId))
4851
.returning();
4952

50-
if (result) {
53+
if (result.length > 0) {
5154
console.log(
5255
`Successfully removed guild ${guild.guildId} from tracking.`,
5356
);
@@ -77,10 +80,14 @@ export default async function () {
7780
})
7881
.returning();
7982

80-
if (result) {
81-
console.log(`Successfully added guild ${guildId} to tracking.`);
83+
if (result.length > 0) {
84+
console.log(
85+
`Successfully added guild ${guildId} to tracking.`,
86+
);
8287
} else {
83-
console.error(`Failed to add guild ${guildId} to tracking.`);
88+
console.error(
89+
`Failed to add guild ${guildId} to tracking.`,
90+
);
8491
}
8592
}),
8693
);

src/utils/youtube/fetchLatestUploads.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Platform } from "../../types/types.d.ts";
2-
1+
import { Platform } from "../../types/types.d";
32
import {
43
dbGuildYouTubeSubscriptionsTable,
54
dbYouTubeTable,

0 commit comments

Comments
 (0)