File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ model User {
2626 quizAnswered Int @default (0 )
2727 quizAnsweredWrong Int @default (0 )
2828 points Float @default (0.0 )
29- isBotAdmin Boolean @default (false )
3029 createdAt DateTime @default (now () )
3130 updatedAt DateTime @updatedAt
3231}
Original file line number Diff line number Diff line change @@ -260,23 +260,27 @@ export async function unblockUser(lid: string): Promise<void> {
260260
261261export async function setBotAdmin ( lid : string , value : boolean ) : Promise < void > {
262262 try {
263- await prisma . user . update ( {
264- where : { lid } ,
265- data : { isBotAdmin : value } ,
266- } ) ;
263+ const key = `botadmin:${ lid } ` ;
264+ if ( value ) {
265+ // set without TTL so privilege persists
266+ await redis . set ( key , "1" ) ;
267+ } else {
268+ await redis . del ( key ) ;
269+ }
267270 } catch ( error ) {
268271 Sentry . captureException ( error ) ;
269- log . error ( "Database " , `Failed to set bot admin for: ${ lid } ` , error ) ;
272+ log . error ( "Redis " , `Failed to set bot admin for: ${ lid } ` , error ) ;
270273 }
271274}
272275
273276export async function isBotAdmin ( lid : string ) : Promise < boolean > {
274277 try {
275- const user = await prisma . user . findUnique ( { where : { lid } } ) ;
276- return ! ! user && ! ! user . isBotAdmin ;
278+ const key = `botadmin:${ lid } ` ;
279+ const val = await redis . get ( key ) ;
280+ return val !== null ;
277281 } catch ( error ) {
278282 Sentry . captureException ( error ) ;
279- log . error ( "Database " , `Failed to check bot admin: ${ lid } ` , error ) ;
283+ log . error ( "Redis " , `Failed to check bot admin: ${ lid } ` , error ) ;
280284 }
281285 return false ;
282286}
You can’t perform that action at this time.
0 commit comments