import { awaitResponse } from "../await/await-response" ; import { SingleConnection } from "../client/connection" ; import { MessageError } from "../client/errors" ; import { Color , colorToHexString } from "../message/color" ; import { NoticeMessage } from "../message/twitch-types/notice" ; import { sendPrivmsg } from "./privmsg" ; export class SetColorError extends MessageError { public wantedColor : Color ; public constructor ( wantedColor , message ? , cause ? ) { super ( message , cause ) ; this . wantedColor = wantedColor ; } } const badNoticeIDs = [ "turbo_only_color" , "usage_color" , ] ; export async function setColor ( conn , color ) { const colorAsHex = colorToHexString ( color ) ; sendPrivmsg ( conn , conn . configuration . username , `/color ${ colorAsHex }` ) ; await awaitResponse ( conn , { failure : ( msg ) => msg instanceof NoticeMessage && msg . channelName === conn . configuration . username && badNoticeIDs . includes ( msg . messageID ! ) , success : ( msg ) => msg instanceof NoticeMessage && msg . channelName === conn . configuration . username && msg . messageID === "color_changed" , errorType : ( msg , cause ) => new SetColorError ( color , msg , cause ) , errorMessage : `Failed to set color to ${ colorAsHex }` , } ) ; }