diff options
| author | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-22 15:32:57 +0100 |
|---|---|---|
| committer | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-22 15:32:57 +0100 |
| commit | 72487019b3f255cece40a8073bbad8bc9968a3b7 (patch) | |
| tree | b6590e63039cdc8b1820bd345cdfe83f28ff839b /174bg/discord-bot/source/commands/oncall-check.js | |
| parent | da0509c91376f56f133872eddd2e4282d76f215e (diff) | |
| download | unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.tar unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.tar.gz unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.tar.bz2 unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.tar.xz unnamed-group-72487019b3f255cece40a8073bbad8bc9968a3b7.zip | |
major code refactor, add uex lookup
Diffstat (limited to '174bg/discord-bot/source/commands/oncall-check.js')
| -rw-r--r-- | 174bg/discord-bot/source/commands/oncall-check.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/174bg/discord-bot/source/commands/oncall-check.js b/174bg/discord-bot/source/commands/oncall-check.js new file mode 100644 index 0000000..7a3886d --- /dev/null +++ b/174bg/discord-bot/source/commands/oncall-check.js @@ -0,0 +1,51 @@ +import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js"; +import { login } from "../controllers/pocketbase.js"; + +export default { + data: new SlashCommandBuilder() + .setName("oncall-check") + .setDescription("Returns a list of members who are currently on call.") + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), + execute: async (interaction) => { + const date = new Date(); + const dateUTCHours = date.getUTCHours(); + const dateUTCMinutes = date.getUTCMinutes(); + const dateUTCDay = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][date.getUTCDay()]; + + const pb = await login(); + + const members = await pb.collection("members").getFullList(); + + let membersOnCall = []; + + for (const member of members) { + try { + if (member.onCallSchedule) { + const available = member.onCallSchedule[dateUTCDay]?.available || false; + + if (available) { + const start = member.onCallSchedule[dateUTCDay].start; + const startHours = start.split(":")[0]; + const startMinutes = start.split(":")[1]; + const end = member.onCallSchedule[dateUTCDay].end; + const endHours = end.split(":")[0]; + const endMinutes = end.split(":")[1]; + + console.log(`Checking on-call schedule for member ${member.name}: ${start} - ${end} (UTC)`); + + if ((dateUTCHours > startHours || (dateUTCHours === startHours && dateUTCMinutes >= startMinutes)) && (dateUTCHours < endHours || (dateUTCHours === endHours && dateUTCMinutes <= endMinutes))) { + membersOnCall.push(member); + } + } + } + } catch (error) { + console.error(`Error checking on-call schedule for member ${member.name}:`, error); + } + } + + await interaction.reply({ + content: `${membersOnCall.map((member) => `- <@${member.discordId}>`).join("\n") || "No members are currently on call."}`, + ephemeral: true, + }); + }, +}; |
