Skip to content

Commit c7b0597

Browse files
committed
ref: code clean up + comments
removed sqlite backups lol
1 parent 6db12aa commit c7b0597

File tree

7 files changed

+64
-25
lines changed

7 files changed

+64
-25
lines changed

src/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ import {
99
Routes,
1010
type APIApplicationCommand,
1111
} from "discord.js";
12-
import { CronJob } from "cron";
1312

1413
import { env } from "./config.ts";
1514
import commandsMap from "./commands.ts";
1615
import initTables from "./utils/db/init.ts";
1716
import { getTwitchToken } from "./utils/twitch/auth.ts";
18-
import backup from "./utils/backup.ts";
1917

2018
if (!env.discordToken || env.discordToken === "YOUR_DISCORD_TOKEN") {
2119
throw new Error("You MUST provide a discord token in .env!");
@@ -36,15 +34,6 @@ if (
3634
throw new Error("You MUST provide a Twitch client secret in .env!");
3735
}
3836

39-
// Start the cron jobs
40-
await fs.mkdir(path.resolve(process.cwd(), "backups"), { recursive: true });
41-
new CronJob("0 0 * * *", async () => {
42-
await backup(
43-
path.resolve(process.cwd(), "db.sqlite3"),
44-
`./backups/db-${new Date().toISOString().replace(/[:.]/g, "-")}.sqlite3`,
45-
);
46-
}).start();
47-
4837
const client = new Client({
4938
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
5039
});

src/types/database.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file contains TypeScript interfaces for the database schema used in the application.
2+
// YouTube Table Interface
13
export interface dbYouTube {
24
youtube_channel_id: string;
35
latest_video_id: string | null;
@@ -9,19 +11,22 @@ export interface dbYouTube {
911
youtube_channel_is_live: boolean;
1012
}
1113

14+
// Twitch Table Interface
1215
export interface dbTwitch {
1316
twitch_channel_id: string;
1417
is_live: boolean;
1518
}
1619

17-
export type dbDiscordTable = {
20+
// Guild YouTube Subscriptions Table Interface
21+
export interface dbDiscordTable {
1822
guild_id: string;
1923
guild_channel_id: string;
2024
guild_platform: string;
2125
platform_user_id: string;
2226
guild_ping_role: null | string;
23-
};
27+
}
2428

29+
// Bot Info Table Interface
2530
export interface dbBotInfo {
2631
locked_row: boolean;
2732
guilds_total: number;

src/types/youtube.d.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file contains TypeScript interfaces for the YouTube API responses and requests used in the bot.
2+
// YouTube Playlist API Response Interface
13
export interface YouTubePlaylistResponse {
24
kind: string;
35
etag: string;
@@ -55,6 +57,50 @@ export interface YouTubePlaylistResponse {
5557
};
5658
}
5759

60+
// YouTube Channel API Response Interface
61+
export interface YouTubeChannelResponse {
62+
kind: string;
63+
etag: string;
64+
pageInfo: {
65+
totalResults: number;
66+
resultsPerPage: number;
67+
};
68+
items: Array<{
69+
kind: string;
70+
etag: string;
71+
id: string;
72+
snippet: {
73+
title: string;
74+
description: string;
75+
customUrl: string;
76+
publishedAt: string;
77+
thumbnails: {
78+
default: {
79+
url: string;
80+
width: number;
81+
height: number;
82+
};
83+
medium: {
84+
url: string;
85+
width: number;
86+
height: number;
87+
};
88+
high: {
89+
url: string;
90+
width: number;
91+
height: number;
92+
};
93+
};
94+
localized: {
95+
title: string;
96+
description: string;
97+
};
98+
country: string;
99+
};
100+
}>;
101+
}
102+
103+
// YouTube Innertube Search Request Interface
58104
export interface InnertubeSearchRequest {
59105
contents: {
60106
twoColumnSearchResultsRenderer: {

src/utils/backup.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/utils/youtube/checkIfChannelIdIsValid.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
// This function checks if a given YouTube channel ID is valid by making a request to the YouTube Data API.
12
import { env } from "../../config";
23

34
export default async function checkIfChannelIdIsValid(channelId: string) {
5+
// Invalid channel ID format
6+
if (!channelId.startsWith("UC")) {
7+
return false;
8+
}
9+
410
const res = await fetch(
5-
`https://www.googleapis.com/youtube/v3/channels?part=snippet&id=${channelId}&key=${env.youtubeApiKey}`,
11+
`https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=${channelId}&key=${env.youtubeApiKey}`,
612
);
713
const data = await res.json();
814

src/utils/youtube/getChannelDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default async function (
1010
channelId: string,
1111
): Promise<channelDetails | null> {
1212
const res = await fetch(
13-
`https://www.googleapis.com/youtube/v3/channels?part=snippet&id=${channelId}&key=${env.youtubeApiKey}`,
13+
`https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=${channelId}&key=${env.youtubeApiKey}`,
1414
);
1515

1616
if (!res.ok) {

src/utils/youtube/getSinglePlaylistAndReturnVideoData.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This function is used when a new channel is being added to the database
2+
// It will also be used to get the content type of a new upload
3+
14
import type { YouTubePlaylistResponse } from "../../types/youtube";
25

36
import { env } from "../../config";

0 commit comments

Comments
 (0)