mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-05-21 23:05:19 +00:00
61ee86168b
Updated the GitHub Actions workflow to exclude the dist directory from shellcheck checks, ensuring cleaner linting results. fix(command_manager): reorder datetime import Moved the datetime import to the correct position in command_manager.py for better code organization. fix(reload_config): improve config value retrieval Refactored the _read_config_value function in reload_config.sh to ensure default values are returned correctly when the key is not found in the config file. fix(tests): adjust imports in test_scheduler_logic Updated import statements in test_scheduler_logic.py for consistency and clarity.
69 lines
2.1 KiB
Bash
Executable File
69 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# reload_config.sh — Reload bot configuration via the admin API.
|
|
#
|
|
# Calls POST /api/admin/reload on the bot's built-in admin HTTP server.
|
|
# Equivalent to the !reload DM admin command: triggers bot.reload_config()
|
|
# in-process and returns the result immediately as JSON.
|
|
#
|
|
# Prerequisites:
|
|
# [Admin] section in config.ini with enabled = true, port = 5001, token = <secret>
|
|
#
|
|
# Usage:
|
|
# ./scripts/reload_config.sh # uses config.ini in cwd
|
|
# ./scripts/reload_config.sh /path/to/config.ini # explicit config path
|
|
#
|
|
# Environment overrides:
|
|
# ADMIN_PORT — override port (default: read from config, fallback 5001)
|
|
# ADMIN_TOKEN — override token (default: read from config)
|
|
|
|
set -euo pipefail
|
|
|
|
CONFIG="${1:-config.ini}"
|
|
|
|
# --- read port and token from config.ini unless overridden by env -----
|
|
_read_config_value() {
|
|
local key="$1" default="$2"
|
|
local value=""
|
|
if [ -f "$CONFIG" ]; then
|
|
value="$(grep -A20 '^\[Admin\]' "$CONFIG" \
|
|
| grep -m1 "^${key}[[:space:]]*=" \
|
|
| sed 's/^[^=]*=[[:space:]]*//' \
|
|
| tr -d '[:space:]' \
|
|
|| true)"
|
|
fi
|
|
if [ -n "$value" ]; then
|
|
printf '%s\n' "$value"
|
|
else
|
|
printf '%s\n' "$default"
|
|
fi
|
|
}
|
|
|
|
ADMIN_PORT="${ADMIN_PORT:-$(_read_config_value port 5001)}"
|
|
ADMIN_PORT="${ADMIN_PORT:-5001}"
|
|
|
|
ADMIN_TOKEN="${ADMIN_TOKEN:-$(_read_config_value token '')}"
|
|
|
|
if [ -z "$ADMIN_TOKEN" ]; then
|
|
echo "ERROR: no admin token found in $CONFIG [Admin] section and ADMIN_TOKEN env not set." >&2
|
|
exit 1
|
|
fi
|
|
|
|
URL="http://127.0.0.1:${ADMIN_PORT}/api/admin/reload"
|
|
|
|
echo "Calling ${URL} ..."
|
|
RESPONSE=$(curl -sf -X POST "$URL" \
|
|
-H "Authorization: Bearer ${ADMIN_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
--max-time 10 2>&1) || {
|
|
echo "ERROR: could not reach admin server at ${URL}" >&2
|
|
echo " Is the bot running with [Admin] enabled = true?" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "$RESPONSE"
|
|
|
|
# Surface the 'success' flag as the exit code (0 = success, 1 = config rejected)
|
|
if echo "$RESPONSE" | grep -q '"success": *false'; then
|
|
exit 1
|
|
fi
|