### Clone and Install LIVCK Discord Bot Source: https://github.com/livck/livck-discord-bot/blob/main/README.md This section details the initial steps to set up the LIVCK Discord Bot. It includes cloning the repository, installing Node.js dependencies using npm, configuring environment variables by copying an example file, and running database migrations. ```bash git clone https://github.com/LIVCK/livck-discord-bot.git cd livck-discord-bot npm install cp .env.example .env # Edit .env with your credentials node migrate.js node server.js ``` -------------------------------- ### Example Release Flow (git & npm) Source: https://github.com/livck/livck-discord-bot/blob/main/RELEASE.md A step-by-step example demonstrating a typical release flow, from working on a feature branch to merging, updating the version, and pushing to trigger the release pipeline. ```bash # 1. Work on feature branch git checkout -b feature/new-layout # ... make changes ... git commit -m "feat: add new layout option" git push origin feature/new-layout # 2. Create PR and merge to main # ... PR is reviewed and merged ... # 3. Update version on main branch git checkout main git pull origin main npm version minor # Creates commit + tag locally # 4. Push to trigger release git push origin main git push origin v1.1.0 # Triggers GitHub Actions release workflow # 5. Go to GitHub releases and review draft # 6. Publish when ready! ``` -------------------------------- ### LIVCK API Client: Making Requests Source: https://context7.com/livck/livck-discord-bot/llms.txt Demonstrates how to make GET requests to the LIVCK API using the client wrapper. It shows how to specify API endpoints and query parameters, and how the response data is structured. ```javascript // Make GET request to API endpoint const response = await livck.get('categories', { perPage: 100 }); // Returns { data: [...categories] } ``` -------------------------------- ### Status Embed Layout Rendering Examples (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt Demonstrates the usage of different layout renderers (Detailed, Compact, Overview, Minimal) for generating statuspage embeds in Discord. Each layout provides a distinct visual style for presenting service status, ranging from comprehensive lists to simple status indicators. ```javascript // Detailed Layout - Full service list renderDetailedLayout(service, statuspage, 'en'); // Creates embed with fields: // Category Name // **Service 1** // **Service 2** // Compact Layout - Grid with counters renderCompactLayout(service, statuspage, 'en'); // Creates embed with inline fields: // Category Name // ┃ **5/5** services // ┗━ 🟢 Operational // Overview Layout - Summary metrics renderOverviewLayout(service, statuspage, 'en'); // Creates embed with description: // 🟢 All systems operational // ```diff // + 10/10 services operational // ``` // Minimal Layout - Clean dots renderMinimalLayout(service, statuspage, 'en'); // Creates embed with description: // **Category Name** // 🟢 Service 1 // 🟢 Service 2 ``` -------------------------------- ### Subscription Database Model Definition and Creation (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt Defines the Sequelize model for storing subscription information, linking Discord guilds and channels to statuspages with specific configurations like locale, event types, layout, and update interval. It also shows an example of creating a new subscription record. ```javascript // Model definition const Subscription = sequelize.define('Subscription', { guildId: { type: DataTypes.STRING, allowNull: false }, channelId: { type: DataTypes.STRING, allowNull: false }, locale: { type: DataTypes.STRING(5), defaultValue: 'de', validate: { isIn: [['de', 'en']] } }, eventTypes: { type: DataTypes.JSON, defaultValue: { STATUS: true, NEWS: false } }, layout: { type: DataTypes.STRING(50), defaultValue: 'DETAILED' }, interval: { type: DataTypes.INTEGER, allowNull: false } }); // Create subscription const subscription = await models.Subscription.create({ guildId: '1234567890', channelId: '0987654321', statuspageId: statuspage.id, eventTypes: { STATUS: true, NEWS: true }, layout: 'COMPACT', locale: 'en', interval: 60 }); ``` -------------------------------- ### Get Status Embed Layout Renderer (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt The getLayoutRenderer function acts as a factory, returning the appropriate renderer function based on a layout key. This allows for dynamic generation of status embeds with different visual representations, such as detailed lists, compact grids, or minimal status dots. ```javascript import { getLayoutRenderer } from './messages/layoutRenderers.js'; // Get renderer by layout key const renderer = getLayoutRenderer('DETAILED'); // Available layouts: // - DETAILED: Full monitor list with categories // - COMPACT: Grid view with status counters // - OVERVIEW: Summary with key metrics // - MINIMAL: Ultra-clean status dots only // Render layout const embeds = renderer(statuspageService, statuspageRecord, 'en'); // Returns: [{ embed: EmbedBuilder, type: 'single' }] ``` -------------------------------- ### Regenerate Status Dot Emojis using Python Source: https://github.com/livck/livck-discord-bot/blob/main/assets/emojis/README.md Executes a Python script to regenerate status dot emojis. This command should be run from the 'assets/emojis' directory and requires Python 3 to be installed. ```bash cd assets/emojis python3 generate_status_dots.py ``` -------------------------------- ### LIVCK API Client: Initialization and Verification Source: https://context7.com/livck/livck-discord-bot/llms.txt Shows how to initialize the LIVCK API client and verify if a given URL points to a valid LIVCK statuspage. The verification checks for the presence of the 'lvk-version' header in the response. ```javascript import LIVCK from './api/livck.js'; // Initialize client with statuspage URL const livck = new LIVCK('https://status.example.com'); // Verify URL is a valid LIVCK statuspage const isValid = await livck.ensureIsLIVCK(); // Returns true if response headers include 'lvk-version' ``` -------------------------------- ### Environment Configuration Variables (.env) Source: https://context7.com/livck/livck-discord-bot/llms.txt Lists the required environment variables for configuring the LIVCK Discord Bot, including credentials for Discord, database connection details for MySQL/MariaDB, and Redis cache settings. Optional custom emojis are also included. ```bash # .env configuration # Discord Application Credentials DISCORD_CLIENT_ID=your_client_id DISCORD_CLIENT_SECRET=your_client_secret DISCORD_BOT_TOKEN=your_bot_token # MySQL/MariaDB Database DB_HOST=localhost DB_DATABASE=livck_bot DB_USERNAME=bot_user DB_PASSWORD=secure_password # Redis Cache REDIS_HOST=localhost REDIS_PORT=6379 REDIS_PASSWORD=redis_password # Optional Custom Emojis (for status indicators) EMOJI_GREEN_DOT=<:green:1234567890> EMOJI_RED_DOT=<:red:1234567890> EMOJI_ORANGE_DOT=<:orange:1234567890> ``` -------------------------------- ### LIVCK API Client: Building URLs Source: https://context7.com/livck/livck-discord-bot/llms.txt Illustrates the utility of the `build` method in the LIVCK API client, which constructs full API endpoint URLs. This is useful for creating direct links to specific API resources. ```javascript // Build full API URL const url = livck.build('alerts', 'v1'); // Returns 'https://status.example.com/api/v1/alerts' ``` -------------------------------- ### Create and Push Git Tag Source: https://github.com/livck/livck-discord-bot/blob/main/RELEASE.md Creating an annotated Git tag for a release and pushing it to the remote repository. Pushing the tag typically triggers automated release workflows. ```bash # Create annotated tag git tag -a v1.0.0 -m "Release v1.0.0" # Push tag to trigger release workflow git push origin v1.0.0 ``` -------------------------------- ### Configure Role Mentions for Event Notifications in JavaScript Source: https://context7.com/livck/livck-discord-bot/llms.txt This code illustrates how to set up role mentions for specific event types within the RoleMention model. It covers creating a new role mention entry and then using a utility function to build the mention string and associated role IDs for alerts. ```javascript // Create role mention await models.RoleMention.create({ subscriptionId: subscription.id, roleId: '1234567890', eventType: 'NEWS' // 'ALL', 'STATUS', or 'NEWS' }); // Build mention string for alerts import { buildRoleMentions } from './util/roleMentions.js'; const { content, roleIds, allowedMentions } = await buildRoleMentions( subscriptionId, 'NEWS' ); // content: '<@&1234567890> <@&0987654321>' // roleIds: ['1234567890', '0987654321'] // allowedMentions: { roles: roleIds } ``` -------------------------------- ### Re-creating a Release (git) Source: https://github.com/livck/livck-discord-bot/blob/main/RELEASE.md Instructions for deleting a Git tag locally and remotely, which is necessary before re-creating a tag for a release, often after fixing issues in the workflow. ```bash # Delete tag locally and remotely git tag -d v1.0.0 git push origin :refs/tags/v1.0.0 # Delete draft release on GitHub (manually) # Fix issues, then re-create tag git tag -a v1.0.0 -m "Release v1.0.0" git push origin v1.0.0 ``` -------------------------------- ### Statuspage Model Definition and Usage (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt Defines the Sequelize model for tracking LIVCK status pages, including URL, name, checking status, and failure counts. It also demonstrates how to find or create a statuspage entry. ```javascript // Model definition const Statuspage = sequelize.define('Statuspage', { url: { type: DataTypes.STRING, allowNull: false, unique: true }, name: { type: DataTypes.STRING, allowNull: true }, lastChecked: { type: DataTypes.DATE }, paused: { type: DataTypes.BOOLEAN, defaultValue: false }, pauseReason: { type: DataTypes.ENUM('TIMEOUT', 'NOT_LIVCK'), allowNull: true }, failureCount: { type: DataTypes.INTEGER, defaultValue: 0 } }); // Find or create statuspage const [statuspage, created] = await models.Statuspage.findOrCreate({ where: { url: 'https://status.example.com' }, defaults: { name: 'Example Status' } }); ``` -------------------------------- ### /livck resume - Resume a Paused Statuspage Source: https://context7.com/livck/livck-discord-bot/llms.txt Resumes monitoring for a statuspage that was automatically paused due to errors. ```APIDOC ## POST /livck resume ### Description Resumes monitoring for a LIVCK statuspage that may have been automatically paused due to persistent errors. This action allows the bot to resume fetching and reporting status updates. ### Method POST ### Endpoint `/livck resume` ### Parameters #### Query Parameters - **statuspageUrl** (string) - Required - The URL of the LIVCK statuspage to resume monitoring for. ### Response #### Success Response (200) - **success** (boolean) - Indicates if the resume operation was successful. - **message** (string) - A message detailing the outcome of the resume operation. #### Response Example ```json { "success": true, "message": "Statuspage resumed successfully." } ``` ``` -------------------------------- ### Discord Command Logic: Update Subscription Settings Source: https://context7.com/livck/livck-discord-bot/llms.txt Demonstrates updating settings for an existing LIVCK statuspage subscription. It shows how to modify the locale (language) and layout of a subscription using Sequelize ORM. ```javascript // Update locale await models.Subscription.update( { locale: 'de' }, { where: { id: subscriptionId } } ); // Update layout await models.Subscription.update( { layout: 'COMPACT' }, { where: { id: subscriptionId } } ); ``` -------------------------------- ### Configure Custom Link Buttons in JavaScript Source: https://context7.com/livck/livck-discord-bot/llms.txt This snippet demonstrates how to create and configure custom URL buttons for status messages using the CustomLink model. It shows the creation of a new link entry and the subsequent building of a Discord button component with optional emoji. ```javascript // Create custom link await models.CustomLink.create({ subscriptionId: subscription.id, label: 'Homepage', url: 'https://example.com', emoji: '🏠', position: 0 }); // Links rendered as Discord buttons const button = new ButtonBuilder() .setLabel(link.label) .setURL(link.url) .setStyle(ButtonStyle.Link); if (link.emoji) { button.setEmoji(link.emoji); } ``` -------------------------------- ### URL Normalization and String Utilities (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt Provides utility functions for normalizing URLs by adding 'https://', removing trailing slashes, and lowercasing. It also includes functions to extract the domain from a URL and truncate strings with an ellipsis. ```javascript import { normalizeUrl, domainFromUrl, truncate } from './util/String.js'; // Normalize URL - adds https, removes trailing slashes, lowercases const normalized = normalizeUrl('status.example.com'); // Returns: 'https://status.example.com' // Normalize with path ignored const base = normalizeUrl('https://status.example.com/api/v1', true); // Returns: 'https://status.example.com' // Extract domain from URL const domain = domainFromUrl('https://status.example.com/path'); // Returns: 'status.example.com' // Truncate text with ellipsis const shortened = truncate('Very long description text...', 50); // Returns: 'Very long description text...' (or truncated with ...) ``` -------------------------------- ### Discord Command Logic: List Subscriptions Source: https://context7.com/livck/livck-discord-bot/llms.txt Fetches and formats active LIVCK statuspage subscriptions for a Discord server. It queries the database for subscriptions and prepares embed objects to display subscription details, including channel, events, and language. ```javascript // Returns embeds for each subscription (max 10) const subscriptions = await models.Subscription.findAll({ where: { guildId: interaction.guildId }, include: [{ model: models.Statuspage }] }); // Each subscription embed includes: { author: { name: statuspage.name, url: statuspage.url, icon_url: faviconUrl }, fields: [ { name: 'Channel', value: '<#channelId>', inline: true }, { name: 'Events', value: 'All / Status / News', inline: true }, { name: 'Language', value: '🇬🇧 EN', inline: true } ], color: 0x5865F2 } ``` -------------------------------- ### Server Update Loop for Statuspage Monitoring (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt The main server loop responsible for continuously fetching and updating statuspage data. It processes statuspages in batches, handles caching to prevent duplicate updates, and triggers status and alert handlers. ```javascript // server.js - Main entry point import bot from './discord/bot.js'; import models from './models/index.js'; import { handleStatusPage } from './handlers/handleStatuspage.js'; import { handleAlerts } from './handlers/handleAlerts.js'; const BATCH_SIZE = 100; // Process 100 statuspages per batch const LOCK_TTL = 20; // Redis cache lock (seconds) const INTERVAL = 15000; // Update loop interval (15 seconds) // Initialize Discord bot const client = await bot(models); // Update loop const scheduleStatusPageUpdates = async (client) => { const statuspages = await models.Statuspage.findAll({ attributes: ['id', 'url', 'paused'] }); const activePages = statuspages.filter(sp => !sp.paused); for (const statuspage of activePages) { // Check cache to prevent duplicate updates const cacheKey = `dc-bot:statuspage:${statuspage.id}`; if (await cache.get(cacheKey)) continue; // Update status and alerts await Promise.all([ handleStatusPage(statuspage.id, client), handleAlerts(statuspage.id, client) ]); // Set cache lock await cache.set(cacheKey, 'true', { EX: LOCK_TTL }); } }; // Start continuous loop startUpdateLoop(client); ``` -------------------------------- ### Discord Command Definition: LIVCK Subscribe Source: https://context7.com/livck/livck-discord-bot/llms.txt Defines the structure for the '/livck subscribe' Discord command, used to initiate the subscription process for a LIVCK statuspage. It includes the command name, description, permissions, and subcommand options. ```javascript { name: 'livck', description: 'Manage LIVCK statuspages', default_member_permissions: '32', // ManageGuild dm_permission: false, options: [ { type: 1, // Subcommand name: 'subscribe', description: 'Subscribe a channel to a LIVCK statuspage' } ] } ``` -------------------------------- ### Fetch and Aggregate Statuspage Data (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt The StatuspageService class fetches and aggregates data from a statuspage, including categories, monitors, and recent alerts. It requires an initialized LIVCK API client and provides access to the aggregated data through its properties. ```javascript import StatuspageService from './services/statuspage.js'; import LIVCK from './api/livck.js'; const livck = new LIVCK('https://status.example.com'); const service = new StatuspageService(livck); // Fetch all data await service.fetchAll(); // Access categories with nested monitors console.log(service.categories); // [ // { // id: 1, // name: 'Core Services', // monitors: [ // { id: 1, name: 'API', state: 'AVAILABLE' }, // { id: 2, name: 'Database', state: 'AVAILABLE' } // ] // } // ] // Access recent alerts console.log(service.alerts); // [ // { // id: 1, // title: 'Scheduled Maintenance', // type: 'MAINTENANCE', // message: '

Scheduled maintenance...

', // created_at: '2024-01-15T10:00:00Z' // } // ] ``` -------------------------------- ### /livck edit - Edit Subscription Settings Source: https://context7.com/livck/livck-discord-bot/llms.txt Opens an interactive menu to modify language, layout, custom links, and role mentions for an existing subscription. ```APIDOC ## PUT /livck edit ### Description Allows editing of existing subscription settings, including language, layout, custom links, and role mentions. This command typically initiates an interactive process or modal for selection. ### Method PUT ### Endpoint `/livck edit` ### Parameters #### Query Parameters - **subscription** (string) - Required - Identifier for the subscription to edit (e.g., statuspage URL or channel ID). This parameter is often used for autocomplete selection. #### Request Body *The structure of the request body depends on the specific edit action initiated after selecting a subscription. Examples include updating locale or layout.* - **locale** (string) - Optional - New language for notifications. Options: `de`, `en`. - **layout** (string) - Optional - New display layout. Options: `DETAILED`, `COMPACT`, `OVERVIEW`, `MINIMAL`. ### Request Example (Updating Locale) ```json { "locale": "de" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the subscription was updated successfully. #### Response Example ```json { "message": "Subscription settings updated successfully." } ``` ``` -------------------------------- ### Translation System for i18n (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt Implements a singleton translation system for managing locales, replacing placeholders, and handling pluralization. It supports dynamic locale setting and provides localized strings for commands and messages. ```javascript import translation, { trans } from './util/Translation.js'; // Set current locale translation.setLocale('en'); // Get translation with placeholders const message = translation.trans('commands.livck.subscribe.success', { url: 'https://status.example.com', channelId: '1234567890' }); // Returns: "Successfully subscribed to https://status.example.com in <#1234567890>" // Pluralization support (zero|singular|plural) const count = translation.trans('messages.status.services_count', {}, 5); // lang/en.json: "no services|1 service|:count services" // Returns: "5 services" // Discord localization for commands const localizations = translation.localizeExcept('commands.livck.description'); // Returns: { 'de': 'German description' } (excludes default 'en') ``` -------------------------------- ### Hotfix Release Process (git & npm) Source: https://github.com/livck/livck-discord-bot/blob/main/RELEASE.md Steps for creating a hotfix release, which involves creating a dedicated branch, fixing a critical bug, bumping the patch version, and merging back into the main branch. ```bash # 1. Create hotfix branch from main git checkout -b hotfix/critical-bug main # 2. Fix the bug git commit -m "fix: critical bug in status updates" # 3. Bump patch version npm version patch # 4. Merge to main and tag git checkout main git merge hotfix/critical-bug git push origin main # 5. Push tag to trigger release git push origin v1.0.1 ``` -------------------------------- ### /livck list - List Active Subscriptions Source: https://context7.com/livck/livck-discord-bot/llms.txt Displays all active statuspage subscriptions for the current server with edit and delete options. ```APIDOC ## GET /livck list ### Description Displays all active statuspage subscriptions for the current server. Each subscription is presented as an embed with key details. ### Method GET ### Endpoint `/livck list` ### Parameters No parameters required. ### Response #### Success Response (200) - **embeds** (array) - An array of embed objects, each representing a subscription. Each embed contains: - **author** (object) - **name** (string) - The name of the statuspage. - **url** (string) - The URL of the statuspage. - **icon_url** (string) - URL of the statuspage favicon. - **fields** (array) - **name** (string) - Field name (e.g., 'Channel', 'Events', 'Language'). - **value** (string) - Field value. - **inline** (boolean) - Whether the field is displayed inline. - **color** (integer) - The color of the embed. #### Response Example ```json [ { "author": { "name": "status.example.com", "url": "https://status.example.com", "icon_url": "https://example.com/favicon.png" }, "fields": [ { "name": "Channel", "value": "<#1234567890123456789>", "inline": true }, { "name": "Events", "value": "All", "inline": true }, { "name": "Language", "value": "🇬🇧 EN", "inline": true } ], "color": 5636080 } ] ``` ``` -------------------------------- ### /livck subscribe - Subscribe to a Statuspage Source: https://context7.com/livck/livck-discord-bot/llms.txt Subscribes a Discord channel to receive status updates from a LIVCK statuspage. Configuration is done via a modal. ```APIDOC ## POST /livck subscribe ### Description Subscribes a Discord channel to receive status updates from a LIVCK statuspage. Opens a modal for configuration including URL, channel, event types, language, and layout. ### Method POST ### Endpoint `/livck subscribe` ### Parameters #### Request Body - **url** (string) - Required - LIVCK statuspage URL (e.g., `https://status.example.com`) - **channelId** (string) - Required - Target Discord channel ID (e.g., `1234567890123456789`) - **events** (string) - Optional - Event types to subscribe to. Options: `ALL`, `STATUS`, `NEWS`. Defaults to `ALL`. - **locale** (string) - Optional - Language for notifications. Options: `de`, `en`. Defaults to `en`. - **layout** (string) - Optional - Display layout for status updates. Options: `DETAILED`, `COMPACT`, `OVERVIEW`, `MINIMAL`. Defaults to `DETAILED`. ### Request Example ```json { "url": "https://status.example.com", "channelId": "1234567890123456789", "events": "ALL", "locale": "en", "layout": "DETAILED" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating successful subscription. #### Response Example ```json { "message": "Successfully subscribed to status.example.com for updates." } ``` ``` -------------------------------- ### Update Package Version (npm) Source: https://github.com/livck/livck-discord-bot/blob/main/RELEASE.md Commands to update the version number in the package.json file using npm. Supports patch, minor, and major version increments following semantic versioning. ```bash npm version patch # 1.0.0 -> 1.0.1 npm version minor # 1.0.0 -> 1.1.0 npm version major # 1.0.0 -> 2.0.0 ``` -------------------------------- ### Discord Command Logic: Resume Statuspage Source: https://context7.com/livck/livck-discord-bot/llms.txt Resumes monitoring for a LIVCK statuspage that may have been automatically paused due to errors. It utilizes a `StatuspagePauseManager` to handle the resumption process and returns a success status. ```javascript // Resume a paused statuspage const result = await StatuspagePauseManager.resume(statuspage, true); // Result structure { success: true, message: 'Statuspage resumed successfully' } ``` -------------------------------- ### Commit Changes (git) Source: https://github.com/livck/livck-discord-bot/blob/main/RELEASE.md Committing changes to version control, specifically focusing on package.json and package-lock.json after a version bump. This prepares the changes for tagging and release. ```bash git add package.json package-lock.json git commit -m "chore: bump version to v1.0.0" ``` -------------------------------- ### LIVCK API Client - LIVCK Class Source: https://context7.com/livck/livck-discord-bot/llms.txt HTTP client for interacting with LIVCK statuspage APIs. Handles request building, error handling, and response parsing. ```APIDOC ## LIVCK Class - API Wrapper ### Description Provides an HTTP client interface to interact with LIVCK statuspage APIs. It simplifies making requests, managing API endpoints, and handling responses. ### Initialization ```javascript import LIVCK from './api/livck.js'; // Initialize client with statuspage URL const livck = new LIVCK('https://status.example.com'); ``` ### Methods #### `ensureIsLIVCK()` - **Description**: Verifies if the provided URL is a valid LIVCK statuspage by checking response headers. - **Returns**: `Promise` - `true` if the URL is a LIVCK statuspage, `false` otherwise. #### `get(endpoint, params)` - **Description**: Makes a GET request to a specified API endpoint. - **Parameters**: - **endpoint** (string): The API endpoint path (e.g., `categories`). - **params** (object): Optional query parameters for the request (e.g., `{ perPage: 100 }`). - **Returns**: `Promise` - The parsed JSON response, typically containing a `data` field. - **Example**: `await livck.get('categories', { perPage: 100 });` #### `build(endpoint, version)` - **Description**: Constructs the full API URL for a given endpoint and version. - **Parameters**: - **endpoint** (string): The API endpoint path (e.g., `alerts`). - **version** (string): The API version (e.g., `v1`). - **Returns**: `string` - The complete API URL. - **Example**: `livck.build('alerts', 'v1'); // Returns 'https://status.example.com/api/v1/alerts'` ``` -------------------------------- ### Restart Discord Bot using PM2 or Node.js Source: https://github.com/livck/livck-discord-bot/blob/main/assets/emojis/README.md Commands to restart the Discord bot. This is necessary after updating environment variables or code changes to apply the new configurations. It supports restarting via PM2 or directly with Node.js. ```bash # Restart the bot pm2 restart discord-bot ``` ```bash # or node server.js ``` -------------------------------- ### Handle Statuspage Updates and Render Embeds (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt The handleStatusPage function is the core handler for processing statuspage data and updating Discord embeds for all associated subscriptions. It fetches statuspage records, aggregates data using StatuspageService, and then renders and updates Discord messages based on subscription configurations. ```javascript import { handleStatusPage } from './handlers/handleStatuspage.js'; // Process a statuspage and update all subscriptions await handleStatusPage(statuspageId, discordClient); // Internal flow: // 1. Fetch statuspage record with subscriptions // 2. Create StatuspageService and fetch data // 3. For each subscription with STATUS events: // - Get layout renderer based on subscription.layout // - Render embeds with locale // - Load custom link buttons // - Update or create Discord message ``` -------------------------------- ### Discord Command Logic: Unsubscribe Source: https://context7.com/livck/livck-discord-bot/llms.txt Handles the removal of LIVCK statuspage subscriptions from a Discord server. It supports unsubscribing by providing the statuspage URL or by targeting a specific channel where the subscription is active. ```javascript // Unsubscribe by URL await models.Subscription.destroy({ where: { guildId: interaction.guildId, statuspageId: statuspage.id } }); // Unsubscribe by channel await models.Subscription.destroy({ where: { guildId: interaction.guildId, channelId: channel.id } }); ``` -------------------------------- ### /livck unsubscribe - Remove a Subscription Source: https://context7.com/livck/livck-discord-bot/llms.txt Removes a statuspage subscription from a channel. Can target by URL or channel. ```APIDOC ## DELETE /livck unsubscribe ### Description Removes a statuspage subscription from the current server. The subscription can be identified by its statuspage URL or the Discord channel it's subscribed to. ### Method DELETE ### Endpoint `/livck unsubscribe` ### Parameters #### Query Parameters - **url** (string) - Optional - The URL of the LIVCK statuspage to unsubscribe from. - **channelId** (string) - Optional - The ID of the Discord channel to unsubscribe from. *Note: Either `url` or `channelId` must be provided.* ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating successful unsubscription. #### Response Example ```json { "message": "Successfully unsubscribed from status.example.com." } ``` ``` -------------------------------- ### Discord Modal Submission Data: LIVCK Subscription Source: https://context7.com/livck/livck-discord-bot/llms.txt Represents the data structure submitted through a modal when subscribing to a LIVCK statuspage. It includes the statuspage URL, target channel ID, event types, language, and desired layout. ```javascript { url: 'https://status.example.com', // LIVCK statuspage URL channelId: '1234567890123456789', // Target Discord channel ID events: 'ALL', // 'ALL', 'STATUS', or 'NEWS' locale: 'en', // 'de' or 'en' layout: 'DETAILED' // 'DETAILED', 'COMPACT', 'OVERVIEW', or 'MINIMAL' } ``` -------------------------------- ### Process Incident Notifications (JavaScript) Source: https://context7.com/livck/livck-discord-bot/llms.txt The handleAlerts function processes alerts from a statuspage and posts or updates incident notifications in Discord, including role mentions. It filters alerts to only include those from the last 3 days and uses specific colors for different alert types (INCIDENT, MAINTENANCE, ANNOUNCEMENT). ```javascript import { handleAlerts } from './handlers/handleAlerts.js'; // Process alerts for a statuspage await handleAlerts(statuspageId, discordClient); // Alert embed colors by type: // - INCIDENT: Red (0xe74c3c) // - MAINTENANCE (scheduled): Yellow (0xf39c12) // - ANNOUNCEMENT: Blurple (0x5865F2) // Only processes alerts from last 3 days const THREE_DAYS_MS = 3 * 24 * 60 * 60 * 1000; const recentAlerts = alerts.filter(alert => { const alertAge = Date.now() - new Date(alert.created_at).getTime(); return alertAge <= THREE_DAYS_MS; }); ``` -------------------------------- ### Discord Command Definition: LIVCK Edit Source: https://context7.com/livck/livck-discord-bot/llms.txt Defines the structure for the '/livck edit' Discord command, which allows users to modify existing subscriptions. It includes an option for selecting the subscription to edit, utilizing autocomplete for user-friendly selection. ```javascript { type: 1, // Subcommand name: 'edit', options: [{ type: 3, // String name: 'subscription', required: true, autocomplete: true }] } ``` -------------------------------- ### Configure Environment Variables for Status Dot Emojis Source: https://github.com/livck/livck-discord-bot/blob/main/assets/emojis/README.md Sets environment variables for custom Discord status dot emojis. These variables store the emoji IDs obtained from Discord, allowing the bot to use custom visual indicators for operational status. ```env EMOJI_GREEN_DOT=<:green_dot:YOUR_ID_HERE> EMOJI_RED_DOT=<:red_dot:YOUR_ID_HERE> EMOJI_ORANGE_DOT=<:orange_dot:YOUR_ID_HERE> ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.