import { StreamLabs } from '../../services/StreamLabs' ; import { TwitchChat } from '../../services/TwitchChat' ; import { WebhookPayload } from '../../schemas/github/webhook-payload' ; import { Config , getConfig } from '../../config' ; export interface ReactionHandleOptions < P = WebhookPayload > { payload : P ; } export interface ReactionCanHandleOptions < P = WebhookPayload > { payload : P ; event : string ; config ? : Config ; } export interface ReactionStatus { notified : boolean ; message : string ; } export abstract class Reaction < P = WebhookPayload > { public constructor ( private twitchChat , private streamlabs , protected config = getConfig ( ) ) { } abstract getStreamLabsMessage ( { payload } ) ; abstract getTwitchChatMessage ( { payload } ) ; abstract canHandle ( { payload , event } ) ; private async notifyStreamlabs ( { payload } ) { try { const message = this . getStreamLabsMessage ( { payload } ) ; await this . streamlabs . alert ( { message , } ) ; return { notified : true , message , } ; } catch { return { notified : false , message : '' , } ; } } private async notifyTwitch ( { payload } ) { try { const message = this . getTwitchChatMessage ( { payload } ) ; await this . twitchChat . send ( message ) ; return { notified : true , message , } ; } catch { return { notified : false , message : '' , } ; } } public async handle ( { payload , } ) { const [ streamlabs , twitchChat ] = await Promise . all ( [ this . notifyStreamlabs ( { payload } ) , this . notifyTwitch ( { payload } ) , ] ) ; return { twitchChat , streamlabs , } ; } }