import { ClusterClient } from 'detritus-client' ; import { EventSubscription } from 'detritus-utils' ; import { Store } from './store' ; export type ServerExecutionsStored = { nick : boolean ; prune : boolean ; } ; class ServerExecutionsStore extends Store < string , ServerExecutionsStored > { constructor ( ) { super ( { expire : 0 } ) ; } getOrCreate ( key ) { let value ; if ( this . has ( key ) ) { value = this . get ( key ) as ServerExecutionsStored ; } else { value = { nick : false , prune : false } ; this . insert ( key , value ) ; } return value ; } insert ( key , payload ) { this . set ( key , payload ) ; } create ( cluster ) { const subscriptions = [ ] ; { const subscription = cluster . subscribe ( 'guildDelete' , ( event ) => { const { guildId , guild } = event ; if ( ! guild || guild . left ) { this . delete ( guildId ) ; } } ) ; subscriptions . push ( subscription ) ; } return subscriptions ; } } export default new ServerExecutionsStore ( ) ;