File tree Expand file tree Collapse file tree 7 files changed +64
-25
lines changed Expand file tree Collapse file tree 7 files changed +64
-25
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,11 @@ import {
99 Routes ,
1010 type APIApplicationCommand ,
1111} from "discord.js" ;
12- import { CronJob } from "cron" ;
1312
1413import { env } from "./config.ts" ;
1514import commandsMap from "./commands.ts" ;
1615import initTables from "./utils/db/init.ts" ;
1716import { getTwitchToken } from "./utils/twitch/auth.ts" ;
18- import backup from "./utils/backup.ts" ;
1917
2018if ( ! env . discordToken || env . discordToken === "YOUR_DISCORD_TOKEN" ) {
2119 throw new Error ( "You MUST provide a discord token in .env!" ) ;
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-
4837const client = new Client ( {
4938 intents : [ GatewayIntentBits . Guilds , GatewayIntentBits . GuildMessages ] ,
5039} ) ;
Original file line number Diff line number Diff line change 1+ // This file contains TypeScript interfaces for the database schema used in the application.
2+ // YouTube Table Interface
13export 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
1215export 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
2530export interface dbBotInfo {
2631 locked_row : boolean ;
2732 guilds_total : number ;
Original file line number Diff line number Diff line change 1+ // This file contains TypeScript interfaces for the YouTube API responses and requests used in the bot.
2+ // YouTube Playlist API Response Interface
13export 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
58104export interface InnertubeSearchRequest {
59105 contents : {
60106 twoColumnSearchResultsRenderer : {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // This function checks if a given YouTube channel ID is valid by making a request to the YouTube Data API.
12import { env } from "../../config" ;
23
34export 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
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change 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+
14import type { YouTubePlaylistResponse } from "../../types/youtube" ;
25
36import { env } from "../../config" ;
You can’t perform that action at this time.
0 commit comments