import { awaitResponse } from "../await/await-response" ; import { SingleConnection } from "../client/connection" ; import { ConnectionError } from "../client/errors" ; import { NoticeMessage } from "../message/twitch-types/notice" ; import { isAnonymousUsername } from "../utils/is-anonymous-username" ; export class LoginError extends ConnectionError { } export async function sendLogin ( conn , username , password ? ) { if ( password != null ) { if ( ! isAnonymousUsername ( username ) && ! password . startsWith ( "oauth:" ) ) { password = "oauth:" + password ; } conn . sendRaw ( `PASS ${ password }` ) ; } conn . sendRaw ( `NICK ${ username }` ) ; await awaitResponse ( conn , { success : ( msg ) => msg . ircCommand === "001" , failure : ( msg ) => msg instanceof NoticeMessage , errorType : ( message , cause ) => new LoginError ( message , cause ) , errorMessage : "Failed to login" , } ) ; }