import * as readline from "node:readline"; import type { UserIdResolvable } from "@twurple/api"; import { apiClient } from "../core/client.ts"; import { logSuccess, logWarning } from "./logger.ts"; export async function getUserId(username: string): Promise { const user = await apiClient.users.getUserByName(username); if (user?.id) { logSuccess(`${user.name} => ${user.id}`); return user.id; } logWarning(`no user with name ${username} found`); return ""; } export async function promptForInput(prompt: string): Promise { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); return new Promise((resolve) => { rl.question(prompt, (answer) => { rl.close(); resolve(answer.trim()); }); }); } export function calculateSecondsBetween( start: number, end: number, ): { seconds: number; toReadable: (roundToMinutes?: boolean) => string } { const seconds = (end - start) / 1000; return { seconds, toReadable: (roundToMinutes?: boolean) => secondsToReadable(seconds, roundToMinutes), }; } export function secondsToReadable( secs: number, roundToMinutes: boolean = false, ): string { const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs; var days = Math.floor(totalSeconds / (3600 * 24)); var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600); var minutes = Math.floor((totalSeconds % 3600) / 60); var seconds = Math.floor(totalSeconds % 60); var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : ""; var hourDisplay = hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : ""; var minuteDisplay = minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : ""; var secondDisplay = seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : ""; return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace( /,\s*$/, "", ); } function meterToCentimeters(length: string): number { const meters = parseFloat(length); const centimeters = Math.round(meters * 100); return centimeters; }