home assistant integration; volume for tidal; do some abstracting
This commit is contained in:
48
src/commands/impl/position.ts
Normal file
48
src/commands/impl/position.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user