Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/helpers/loadCommands.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Collection } from 'discord.js';
import { Status } from '../interactions/commands/status';
import { Command } from '../interfaces/Commands';
import { Keyfob } from '../interactions/commands/keyfob';

export type CommandCollection = Collection<string, Command>;

export default async function loadCommands(): Promise<CommandCollection> {
const allCommands = [new Status()];
const allCommands = [new Status(), new Keyfob()];
const commands = new Collection<string, Command>();

// Include all commands here
Expand Down
30 changes: 30 additions & 0 deletions src/interactions/commands/keyfob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { CommandInteraction, CacheType, EmbedBuilder } from "discord.js";
import { Command } from "../../interfaces/Commands";
import EventData from "../../interfaces/EventData.interface";
import HomeAssistant from "../../lib/homeassistant";

export class Keyfob extends Command {
title = "keyfob";
description = "Get the last scanned keyfob value";
isEphemeral = true;

async run(interaction: CommandInteraction<CacheType>, data: EventData): Promise<void> {
const homeAssistant = new HomeAssistant();
try {
const { state, last_changed } = (await homeAssistant.getEntity("cardreader.value"));
const date = new Date(last_changed);
const embed = new EmbedBuilder()
.setTitle("Keyfob")
.setFields([{
name: "Keyfob ID",
value: state
}])
.setFooter({
text: `Last Updated: ${date.getMonth() + 1}/${date.getDate()} @ ${date.getHours() % 12 || 12}:${date.getMinutes().toString().padStart(2, '0')} ${date.getHours() >= 12 ? 'PM' : 'AM'}`
})
interaction.editReply({ embeds: [embed] });
} catch (error) {
interaction.editReply("It seems no keyfob has been scanned recently. Try scanning it again");
}
}
}