49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import type { ChatMessage } from "@twurple/chat";
|
|
import { getDeskHeight } from "../../util/api-homeassistant.ts";
|
|
import { logSuccess } from "../../util/logger.ts";
|
|
import { BaseCommand } from "../base-command.ts";
|
|
import type { ICommandRequirements } from "../interface.ts";
|
|
|
|
export class PositionCommand extends BaseCommand {
|
|
name = "position";
|
|
cooldown = 0;
|
|
enabled = true;
|
|
|
|
requirements: ICommandRequirements = {
|
|
developer: false,
|
|
mod: false,
|
|
};
|
|
|
|
triggered = async (
|
|
channel: string,
|
|
user: string,
|
|
_text: string,
|
|
msg: ChatMessage,
|
|
) => {
|
|
logSuccess(`${channel} ${user} position command triggered`);
|
|
const position = await getPosition();
|
|
this.chatClient.say(channel, `darius is ${position} right now`, {
|
|
replyTo: msg,
|
|
});
|
|
};
|
|
}
|
|
|
|
async function getPosition(): Promise<string> {
|
|
const heightFromHA = await getDeskHeight();
|
|
if (!heightFromHA) {
|
|
return "unkown";
|
|
}
|
|
const height = convertHeightToCentimeters(heightFromHA.state);
|
|
if (height > 95) {
|
|
return "standing";
|
|
} else {
|
|
return "sitting";
|
|
}
|
|
}
|
|
|
|
function convertHeightToCentimeters(height: string): number {
|
|
const meters = parseFloat(height);
|
|
const centimeters = Math.round(meters * 100);
|
|
return centimeters;
|
|
}
|