@@ -50,3 +50,75 @@ export async function getBotInfo() {
5050 return null ;
5151 }
5252}
53+
54+ export async function updateBotInfoNotifications (
55+ platform : "youtube" | "bluesky" | "twitch" ,
56+ ) {
57+ const query = `
58+ INSERT INTO bot_info_notifications (date, total_${ platform } )
59+ VALUES (CURRENT_DATE, 1)
60+ ON CONFLICT (date) DO UPDATE
61+ SET total_${ platform } = bot_info_notifications.total_${ platform } + 1;
62+ ` ;
63+
64+ try {
65+ const client : PoolClient = await pool . connect ( ) ;
66+
67+ await client . query ( query , [ platform ] ) ;
68+
69+ client . release ( ) ;
70+
71+ console . log ( `Bot info notifications updated for ${ platform } ` ) ;
72+ } catch ( err ) {
73+ console . error (
74+ `Error updating bot info notifications for ${ platform } :` ,
75+ err ,
76+ ) ;
77+ }
78+ }
79+
80+ export async function getBotInfoNotifications ( ) {
81+ const query = `SELECT * FROM bot_info_notifications` ;
82+
83+ try {
84+ const client : PoolClient = await pool . connect ( ) ;
85+ const result : QueryResult < any > = await client . query ( query ) ;
86+
87+ client . release ( ) ;
88+
89+ return result . rows ;
90+ } catch ( err ) {
91+ console . error ( "Error getting bot info notifications:" , err ) ;
92+
93+ return [ ] ;
94+ }
95+ }
96+
97+ export async function updateBotInfoNotificationsTimings (
98+ channel_id : string ,
99+ time_ms : number ,
100+ ) : Promise < void > {
101+ const query = `
102+ INSERT INTO bot_info_notifications_timings (time, channel_id, time_ms)
103+ VALUES (NOW(), $1, $2)
104+ ON CONFLICT (time, channel_id) DO UPDATE
105+ SET time_ms = EXCLUDED.time_ms;
106+ ` ;
107+
108+ try {
109+ const client : PoolClient = await pool . connect ( ) ;
110+
111+ await client . query ( query , [ channel_id , time_ms ] ) ;
112+
113+ client . release ( ) ;
114+
115+ console . log (
116+ `Bot info notifications timings updated for channel ${ channel_id } ` ,
117+ ) ;
118+ } catch ( err ) {
119+ console . error (
120+ `Error updating bot info notifications timings for channel ${ channel_id } :` ,
121+ err ,
122+ ) ;
123+ }
124+ }
0 commit comments