import _ from 'lodash' ; import Emoticons from 'constants/emoticons' ; import EmotesProvider , { Emote , EmoteProviderPrefix , TwitchRegExpEmotesMap } from 'libs/EmotesProvider' ; import { PreviewProvider } from 'libs/PreviewProvider' ; import { RawBadges , RawCheermote } from 'libs/Twitch' ; import { SerializedHighlights } from 'store/ducks/settings' ; import PreviewGithub from 'libs/PreviewGithub' ; import PreviewStrawPoll from 'libs/PreviewStrawPoll' ; import PreviewTwitch from 'libs/PreviewTwitch' ; import PreviewYoutube from 'libs/PreviewYoutube' ; /**
 * Manager for various resources used mostly during messages parsing like badges, emotes, cheermotes, etc.
 */ export default class Resources { class public static manager ( ) { if ( _ . isNil ( Resources . instance ) ) { Resources . instance = new Resources ( ) ; } return Resources . instance ; } private static instance : Resources ; private badges : RawBadges = { } ; private bots : Set < string > = new Set ( [ 'moobot' ] ) ; private cheermotes : RawCheermote [ ] = [ ] ; private emotesProviders : Map < EmoteProviderPrefix , EmotesProvider < Emote > > = new Map ( ) ; private highlights : SerializedHighlights = { } ; private highlightsIgnoredUsers : string [ ] = [ ] ; private highlightsPermanentUsers : string [ ] = [ ] ; private highlightAllMentions : boolean = false ; private emoticonsSetId = 0 ; private emoticonsMap : EmoticonsMap = { } ; private emoticonsList = _ . flatten ( _ . map ( Emoticons , ( set ) => _ . map ( set , ( id ) => id ) ) ) ; private previewProviders : Record < string , PreviewProvider > ; class private constructor ( ) { this . previewProviders = { [ PreviewGithub . getProviderId ( ) ] : PreviewGithub , [ PreviewStrawPoll . getProviderId ( ) ] : PreviewStrawPoll , [ PreviewTwitch . getProviderId ( ) ] : PreviewTwitch , [ PreviewYoutube . getProviderId ( ) ] : PreviewYoutube , } ; } param badges public setBadges ( badges ) { this . badges = badges ; } return public getBadges ( ) { return this . badges ; } param cheermotes public setCheermotes ( cheermotes ) { this . cheermotes = cheermotes ; } param id public setEmoticonsSetId ( id ) { const emoticonsSetId = _ . get ( Emoticons , id ) ; this . emoticonsSetId = ! _ . isNil ( emoticonsSetId ) ? id : 0 ; this . emoticonsMap = _ . reduce ( TwitchRegExpEmotesMap , ( map , code , regex ) => { map [ regex ] = { code , id : Emoticons [ this . emoticonsSetId ] [ regex ] . toString ( ) } ; return map ; } , { } as EmoticonsMap ) ; } return public getEmoticonsMap ( ) { return this . emoticonsMap ; } param id return public isEmoticon ( id ) { return _ . includes ( this . emoticonsList , id ) ; } return public getCheermotes ( ) { return this . cheermotes ; } param highlights param ignoredUsers param permanentUsers public setHighlights ( highlights , ignoredUsers , permanentUsers ) { this . highlights = highlights ; this . highlightsIgnoredUsers = ignoredUsers ; this . highlightsPermanentUsers = permanentUsers ; } param highlightAllMentions public setHighlightAllMentions ( highlightAllMentions ) { this . highlightAllMentions = highlightAllMentions ; } return public getHighlights ( ) { return this . highlights ; } param provider public addEmotesProvider ( provider ) { this . emotesProviders . set ( provider . prefix , provider ) ; } return public getEmotesProviders ( ) { return this . emotesProviders ; } param prefix return public getEmotesProvider ( prefix ) { return this . emotesProviders . get ( prefix ) ; } param bots public addBots ( bots ) { for ( const bot of bots ) { this . bots . add ( bot ) ; } } param username return public shouldIgnoreHighlights ( username ) { return _ . includes ( this . highlightsIgnoredUsers , username ) ; } param username return public shouldAlwaysHighlight ( username ) { return _ . includes ( this . highlightsPermanentUsers , username ) ; } return public shouldHighlightAllMentions ( ) { return this . highlightAllMentions ; } param username return public isBot ( username ) { return this . bots . has ( username ) ; } return public getPreviewProviders ( ) { return this . previewProviders ; } } /**
 * Emoticons map.
 */ type EmoticonsMap = Record < string , { code : string ; id : string ; } > ;