import _ from 'lodash' ; /**
 * Base API URL.
 */ const BaseUrl = 'https://recent-messages.robotty.de/api/v2' ; /**
 * Robotty class.
 */ export default class Robotty { param channel return public static async fetchRecentMessages ( channel ) { const response = await Robotty . fetch ( Robotty . getUrl ( `/recent-messages/${ channel }` , { hideModerationMessages : true , hideModeratedMessages : true } ) ) ; const json = ( await response . json ( ) ) as RawRecentMessages ; if ( ! _ . isNil ( json . error ) ) { throw new Error ( json . error ) ; } return _ . filter ( _ . takeRight ( json . messages , 15 ) , ( message ) => message . includes ( `PRIVMSG #${ channel }` ) ) ; } param endpoint param searchParams return private static getUrl ( endpoint , searchParams = { } ) { const url = new URL ( BaseUrl . concat ( endpoint ) ) ; _ . forEach ( searchParams , ( value , key ) => url . searchParams . set ( key , _ . isString ( value ) ? value : value . toString ( ) ) ) ; return url . toString ( ) ; } param url return private static fetch ( url ) { const headers = new Headers ( { Accept : 'application/json' , } ) ; const request = new Request ( url , { headers } ) ; return fetch ( request ) ; } } /**
 * Recent messages returned by the API.
 */ type RawRecentMessages = { messages : string [ ] ; error : string | null ; } ;