Files
twitch-bot/src/commands/impl/ping.ts
2025-09-29 00:11:55 +02:00

41 lines
1015 B
TypeScript

import type { ChatMessage } from "@twurple/chat";
import { calculateSecondsBetween } from "../../util/general.ts";
import { logSuccess } from "../../util/logger.ts";
import { BaseCommand } from "../base-command.ts";
import type { ICommandRequirements } from "../interface.ts";
export class PingCommand extends BaseCommand {
started: number;
constructor() {
super();
this.started = Date.now();
}
name = "ping";
cooldown = 0;
enabled = true;
requirements: ICommandRequirements = {
developer: false,
mod: false,
};
triggered = async (
channel: string,
user: string,
_text: string,
msg: ChatMessage,
) => {
logSuccess(`${channel} ${user} ping command triggered`);
const uptime = getUptime(this.started, Date.now());
const message = `uptime: ${uptime}`;
this.chatClient.say(channel, message, {
replyTo: msg,
});
};
}
function getUptime(start: number, now: number): string {
return calculateSecondsBetween(start, now).toReadable();
}