import { timer, of, Subscription } from 'rxjs'; import { switchMap, filter, tap } from 'rxjs/operators'; import { Guild } from 'discord.js'; import { DyFM_Async, DyFM_Error } from '@futdevpro/fsm-dynamo'; import { DyNTS_SingletonService } from '../../../_services/base/singleton.service'; import { DyNTS_DiBo_Main_ControlService } from './dibo-main.control-service'; import { DyNTS_global_settings } from '../../../_collections/global-settings.const'; export abstract class DyNTS_DiBo_Routines_ControlService extends DyNTS_SingletonService { /* static getInstance(): DyNTS_DiBo_Routines_ControlService { return DyNTS_DiBo_Routines_ControlService.getSingletonInstance(); } */ protected mainDiscordBot_CS: DyNTS_DiBo_Main_ControlService; protected abstract getMainDiscordBotControlService(): DyNTS_DiBo_Main_ControlService; get discordServer(): Guild { return this.mainDiscordBot_CS?.discordServer; } private _routinesStarted: boolean; get routinesStarted(): boolean { return this._routinesStarted; } /* protected constructor() { super(); if (!this.discordServer) { throw new DyFM_Error({ ...this.getDefaultErrorSettings( 'constructor', new Error( 'Discord server not yet initialized, ' + 'should only be called after DiscordBot_ControlService.start' ), 'system-init' ), errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-RCS-C000`, }) } } */ async setup(issuer: string): Promise { try { this.mainDiscordBot_CS = this.getMainDiscordBotControlService(); if (!this.mainDiscordBot_CS) { throw new DyFM_Error({ ...this.getDefaultErrorSettings('setup', new Error('Main Discord Bot Control Service not found'), issuer), errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-RCS-S01`, }) } } catch (error) { throw new DyFM_Error({ ...this.getDefaultErrorSettings('setup', error, issuer), errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-RCS-S000`, }) } } async start(issuer: string): Promise { try { if (!this.discordServer) { throw new DyFM_Error({ ...this.getDefaultErrorSettings( 'start', new Error( 'Discord server not yet initialized, ' + 'should only be called after DiscordBot_ControlService.start' ), issuer, ), errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-RCS-ST01`, }) } await this.startRoutines(issuer); this._routinesStarted = true; } catch (error) { throw new DyFM_Error({ ...this.getDefaultErrorSettings('start', error, issuer), errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DiBo-RCS-ST0`, }) } } abstract startRoutines(issuer: string): Promise; }