add ping command
This commit is contained in:
40
src/commands/impl/ping.ts
Normal file
40
src/commands/impl/ping.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user