From 782fca6574ab09599a01f9d72838212c49b2909b Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Thu, 26 Jun 2025 23:08:07 -0600 Subject: [PATCH] Gwuh --- README.MD | 35 +++++++++++++++++++++++++++++++++++ index.js | 6 ++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 README.MD diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..0e05ee0 --- /dev/null +++ b/README.MD @@ -0,0 +1,35 @@ +# Kuma Discord Status Bot + +This script integrates [Uptime Kuma](https://github.com/louislam/uptime-kuma) status pages with Discord, posting live status updates to specified channels. + +## Features + +- Fetches status from Uptime Kuma API. +- Posts and updates rich embed messages in Discord channels. +- Supports multiple channels and status pages. +- Updates every 5 minutes via cron. + +## Setup + +### 1. Requirements + +- Node.js (v16+ recommended) +- Discord bot token +- Uptime Kuma instance with API access + +### 2. Configuration +Create a `.env` file in the root directory with the following variables: +``` +KUMA_BASE_URL=https://your-uptime-kuma-instance.com +TOKEN=your-discord-bot-token +``` + +### 3. Subscription Configuration +Create a `subs.json` file in the root directory to define which channels should receive updates. +Example: +```json +{ + "channel_id_1": "status_page_id_1", + "channel_id_2": "status_page_id_2" +} +``` \ No newline at end of file diff --git a/index.js b/index.js index 78caa5c..d8a6c9f 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,9 @@ function getStatus(input) { let fieldParts = []; for (monitor of cat.monitors) { - const monitorText = `${monitor.heartbeats[0].status ? "<:online:1307359583785713744>" : "<:offline:1307359600592424971>"} ${monitor.name}\n`; + const status = new Boolean(monitor.heartbeats[0].status); // Turn it into a boolean because 0 and 1 are not always reliable in JS + console.log(`Monitor: ${monitor.name}, Status: ${status}`); + const monitorText = `${status ? "<:online:1307359583785713744>" : "<:offline:1307359600592424971>"} ${monitor.name}\n`; // Check if adding this monitor's text will exceed 1024 characters if (fieldText.length + monitorText.length > 1024) { @@ -61,7 +63,7 @@ function getStatus(input) { } // If the monitor is offline, increment the offline count - if (!monitor.heartbeats[0].status) offline++; + if (!status) offline++; total++; }