implement for desk control

This commit is contained in:
Darius
2025-11-16 21:18:12 +01:00
parent 0fb087fbd9
commit 2aaae8e05c
6 changed files with 59 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
import type { ChatMessage } from "@twurple/chat";
import { getDeskPositionText } from "../../util/api-homeassistant.js";
import { getDeskPosition } from "../../util/api-homeassistant.js";
import { calculateSecondsBetween } from "../../util/general.js";
import { logSuccess } from "../../util/logger.js";
import { BaseCommand } from "../base-command.js";
@@ -22,15 +22,15 @@ export class PositionCommand extends BaseCommand {
msg: ChatMessage,
) => {
logSuccess(`${channel} ${user} position command triggered`);
const position = await getDeskPositionText();
const position = await getDeskPosition();
if (position) {
const time = calculateSecondsBetween(
new Date(position.last_changed).getTime(),
new Date(position.raw.last_changed).getTime(),
Date.now(),
).toReadable(true);
this.chatClient.say(
channel,
`darius has been ${position.state} for ${time}`,
`darius has been ${position.asText()} for ${time}`,
{
replyTo: msg,
},

View File

@@ -1,13 +1,14 @@
import type { ChatMessage } from "@twurple/chat";
import { getDeskHeight, startStandingAutomation } from "../../util/api-homeassistant.js";
import { getDeskPosition, startStandingAutomation } from "../../util/api-homeassistant.js";
import { logInfo, logSuccess } from "../../util/logger.js";
import { BaseCommand } from "../base-command.js";
import type { ICommandRequirements } from "../interface.ts";
import { Config } from "../../config/config.js";
import { calculateSecondsBetween } from "../../util/general.js";
export class StandCommand extends BaseCommand {
name = "stand";
cooldown = 60;
cooldown = 300;
enabled = true;
requirements: ICommandRequirements = {
@@ -23,11 +24,33 @@ export class StandCommand extends BaseCommand {
) => {
logSuccess(`${channel} ${user} position command triggered`);
// const position = await getDeskHeight();
const position = await getDeskPosition();
// if (position?.state > 100) {
if (!position) {
this.chatClient.say(channel, `error: aborting operation`, {
replyTo: msg,
});
return
}
// }
if (position.asBoolean) {
this.chatClient.say(channel, `desk already is in standing mode`, {
replyTo: msg,
});
return
}
const lastMoved = calculateSecondsBetween(
new Date(position.raw.last_changed).getTime(),
Date.now(),
);
if (60 > lastMoved.seconds) {
this.chatClient.say(channel, `desk has moved too recently. please wait`, {
replyTo: msg,
});
return
}
if (Config.night_time.contains()) {
this.chatClient.say(channel, `command disabled during nighttime`, {
@@ -39,7 +62,7 @@ export class StandCommand extends BaseCommand {
const response = await startStandingAutomation();
logInfo(response)
this.chatClient.say(channel, `blabla`, {
this.chatClient.say(channel, `desk is now moving into standing position`, {
replyTo: msg,
});
};