1616 */
1717
1818import { isDate } from 'node:util/types' ;
19- import type {
20- Infraction ,
21- InfractionStatus ,
22- InfractionType ,
23- Prisma ,
24- } from '@prisma/client' ;
19+ import type { Infraction , InfractionStatus , InfractionType , Prisma } from '@prisma/client' ;
2520import type { Client , Snowflake , User } from 'discord.js' ;
2621import { HubService } from '#src/services/HubService.js' ;
2722import db from '#src/utils/Db.js' ;
28- import {
29- logServerUnblacklist ,
30- logUserUnblacklist ,
31- } from '#src/utils/hub/logger/ModLogs.js' ;
23+ import { logServerUnblacklist , logUserUnblacklist } from '#src/utils/hub/logger/ModLogs.js' ;
3224import type { ConvertDatesToString } from '#types/Utils.d.ts' ;
3325import { CacheManager } from '#src/managers/CacheManager.js' ;
3426import getRedis from '#src/utils/Redis.js' ;
@@ -92,11 +84,7 @@ export default class InfractionManager {
9284 filter : { type : InfractionType ; hubId : string ; status ?: InfractionStatus } ,
9385 data : Prisma . InfractionUpdateInput ,
9486 ) {
95- const infraction = await this . fetchInfraction (
96- filter . type ,
97- filter . hubId ,
98- filter . status ,
99- ) ;
87+ const infraction = await this . fetchInfraction ( filter . type , filter . hubId , filter . status ) ;
10088 if ( ! infraction ) return null ;
10189
10290 const updated = await db . infraction . update ( {
@@ -121,27 +109,20 @@ export default class InfractionManager {
121109 } ) ;
122110 }
123111
124- public async getHubInfractions (
125- hubId : string ,
126- opts ?: { type ?: InfractionType ; count ?: number } ,
127- ) {
112+ public async getHubInfractions ( hubId : string , opts ?: { type ?: InfractionType ; count ?: number } ) {
128113 let infractionsArr =
129- ( await this . cacheManager . get (
130- `${ this . targetId } :${ hubId } ` ,
131- async ( ) => await this . queryEntityInfractions ( hubId ) ,
132- ) ) ?? [ ] ;
114+ ( await this . cacheManager . get (
115+ `${ this . targetId } :${ hubId } ` ,
116+ async ( ) => await this . queryEntityInfractions ( hubId ) ,
117+ ) ) ?? [ ] ;
133118
134119 if ( opts ?. type ) infractionsArr = infractionsArr . filter ( ( i ) => i . type === opts . type ) ;
135120 if ( opts ?. count ) infractionsArr = infractionsArr . slice ( 0 , opts . count ) ;
136121
137122 return this . updateInfractionDates ( infractionsArr ) ;
138123 }
139124
140- public async fetchInfraction (
141- type : InfractionType ,
142- hubId : string ,
143- status ?: InfractionStatus ,
144- ) {
125+ public async fetchInfraction ( type : InfractionType , hubId : string , status ?: InfractionStatus ) {
145126 const infractions = await this . getHubInfractions ( hubId , { type } ) ;
146127 const infraction = infractions . find (
147128 ( i ) => ( status ? i . status === status : true ) && i . type === type ,
@@ -155,10 +136,7 @@ export default class InfractionManager {
155136 hubId : string ,
156137 status : Exclude < InfractionStatus , 'ACTIVE' > = 'REVOKED' ,
157138 ) {
158- const revoked = await this . updateInfraction (
159- { type, hubId, status : 'ACTIVE' } ,
160- { status } ,
161- ) ;
139+ const revoked = await this . updateInfraction ( { type, hubId, status : 'ACTIVE' } , { status } ) ;
162140 return revoked ;
163141 }
164142
@@ -196,9 +174,9 @@ export default class InfractionManager {
196174 protected async cacheEntity ( entity : Infraction ) {
197175 const entitySnowflake = entity . userId ?? entity . serverId ;
198176 const key = this . getKey ( entitySnowflake as string , entity . hubId ) ;
199- const existing = (
200- await this . getHubInfractions ( entity . hubId , { type : entity . type } )
201- ) . filter ( ( i ) => i . id !== entity . id ) ;
177+ const existing = ( await this . getHubInfractions ( entity . hubId , { type : entity . type } ) ) . filter (
178+ ( i ) => i . id !== entity . id ,
179+ ) ;
202180
203181 return this . cacheManager . set ( key , [ ...existing , entity ] ) ;
204182 }
@@ -214,9 +192,7 @@ export default class InfractionManager {
214192 ) ;
215193 }
216194
217- protected updateInfractionDates (
218- infractions : ConvertDatesToString < Infraction > [ ] ,
219- ) {
195+ protected updateInfractionDates ( infractions : ConvertDatesToString < Infraction > [ ] ) {
220196 if ( infractions . length === 0 ) {
221197 return [ ] ;
222198 }
@@ -236,11 +212,7 @@ export default class InfractionManager {
236212 }
237213
238214 public filterValidInfractions ( infractions : Infraction [ ] ) : Infraction [ ] {
239- return (
240- infractions . filter (
241- ( { expiresAt } ) => ! expiresAt || expiresAt > new Date ( ) ,
242- ) ?? [ ]
243- ) ;
215+ return infractions . filter ( ( { expiresAt } ) => ! expiresAt || expiresAt > new Date ( ) ) ?? [ ] ;
244216 }
245217
246218 public isExpiredInfraction ( infraction : Infraction | null ) {
0 commit comments