Compare commits

...

7 Commits

Author SHA1 Message Date
Logan Cusano
d19e2ade76 Update install to use the stable build 2025-07-13 01:03:58 -04:00
Logan Cusano
5050443692 Pull the latest code when building the docker container 2025-07-06 19:35:41 -04:00
Logan Cusano
7802a4a865 Update bot presence when joining discord as well as when starting OP25 (through join command) 2025-06-29 20:52:01 -04:00
Logan Cusano
ef8045559c Update the presence of the bot when the op25 config is set, or the bot is started 2025-06-29 18:48:55 -04:00
Logan Cusano
0a82a9b6e6 Fix bug with token in join server 2025-06-29 18:02:20 -04:00
Logan Cusano
743e405ff6 Use the active token if one exists 2025-06-29 18:00:21 -04:00
Logan Cusano
0300ef2407 Update the install script 2025-06-29 14:23:32 -04:00
3 changed files with 111 additions and 27 deletions

View File

@@ -73,18 +73,22 @@ def command(func):
@command
async def join_server(websocket, system_id, guild_id, channel_id):
# Takes guild ID, channel ID, and optionally system_id. If system ID is not included then it will skip OP25 logic
global bot_token
bot_status = await drb_api.get_bot_status()
print("Bot status:", bot_status)
# Check if the bot is running
if 'bot_running' not in bot_status or not bot_status['bot_running']:
# Get a token
global bot_token
bot_token = await srv_api.request_token()
print("Bot token:", bot_token)
if not bot_token or "token" not in bot_token or not bot_token['token']:
raise Exception("No bot token received") # TODO - Handle this better
# Get a token if one is not already
if not bot_token:
bot_token = await srv_api.request_token()
if not bot_token or "token" not in bot_token or not bot_token['token']:
raise Exception("No bot token received") # TODO - Handle this better
bot_token = bot_token['token']
print("Bot token:", bot_token)
# Run the bot if not
await drb_api.start_bot(bot_token['token'])
await drb_api.start_bot(bot_token)
# Set the presence of the bot
await drb_api.update_bot_presence()
# Check if the bot is connected to the guild, if not join
if 'connected_guilds' not in bot_status or int(guild_id) not in bot_status['connected_guilds']:
# Join the server
@@ -126,6 +130,9 @@ async def join_server(websocket, system_id, guild_id, channel_id):
# Start OP25
await drb_api.start_op25()
# Update the presence of the discord bot
await drb_api.update_bot_presence()
client_status['op25_status'] = OP25StatusValues.LISTENING
print("OP25 Startup Complete")
@@ -212,6 +219,9 @@ async def op25_set(websocket, system_id):
await drb_api.generate_op25_config(temp_config)
# Update the presence of the discord bot (if running)
await drb_api.update_bot_presence()
# Example command
@command
async def run_task(websocket, task_id, duration_seconds):

View File

@@ -100,6 +100,11 @@ class DRBCDBAPI(BaseAPI):
print("Getting bot status")
return await self._get("/bot/status")
async def update_bot_presence(self):
"""Updates the bot's precense with the configured system."""
print("Getting bot status")
return await self._post("/op25/update-presence")
# Example Usage (assuming your FastAPI app is running on http://localhost:8000)
async def example_usage():
"""Demonstrates asynchronous API interaction using httpx."""

View File

@@ -14,11 +14,11 @@ install_prereqs() {
sudo apt-get update -y
sudo apt-get install docker.io -y
sudo usermod -aG docker $(whoami)
sudo reboot
sudo su $(whoami)
fi
}
install_discord_bot() {
run_discord_bot() {
local drb_container_name="drb-client-discord-bot"
# Stop and remove existing container if it's running/exists
if docker ps -a --format '{{.Names}}' | grep -q "^${drb_container_name}$"; then
@@ -31,14 +31,14 @@ install_discord_bot() {
fi
mkdir -p $(pwd)/configs
echo -e "${GREEN}Installing the discord bot...${NC}"
docker pull git.vpn.cusano.net/logan/drb-client-discord-bot/drb-client-discord-bot:nightly
docker pull git.vpn.cusano.net/logan/drb-client-discord-bot/drb-client-discord-bot:stable
docker run -d --privileged \
-v /dev:/dev \
-v $(pwd)/configs:/configs \
--name "${drb_container_name}" \
--network=host \
--restart unless-stopped \
git.vpn.cusano.net/logan/drb-client-discord-bot/drb-client-discord-bot:nightly
git.vpn.cusano.net/logan/drb-client-discord-bot/drb-client-discord-bot:stable
}
create_config_json() {
@@ -62,7 +62,7 @@ create_config_json() {
if [ -f "$(pwd)/data/config.json" ]; then
echo -e "${GREEN}Successfully created 'config.json'.${NC}"
echo -e "${GREEN}Content of config.json:${NC}"
cat config.json
cat $(pwd)/data/config.json
else
echo -e "${RED}Error: Failed to create 'config.json'.${NC}"
exit 1 # Exit with an error code if file creation fails
@@ -73,6 +73,9 @@ start_docker_container() {
local container_name="drb-client-app-container" # A unique name for your container
local image_name="drb-client-app" # From your Makefile
# Check to make sure the repo is up to date
git pull
echo -e "${GREEN}Building Docker image '${image_name}'...${NC}"
# Build the Docker image from the current directory
if ! docker build -t "${image_name}" .; then
@@ -95,12 +98,13 @@ start_docker_container() {
echo -e "${GREEN}Starting new container '${container_name}' from image '${image_name}' with restart policy 'unless-stopped'.${NC}"
# Run the container
if docker run -d \
--name "${container_name}" \
--restart unless-stopped \
-v "$(pwd)/data":/data \
--network=host \
"${image_name}"; then
docker run -d \
--name "${container_name}" \
--restart unless-stopped \
-v "$(pwd)/data":/data \
--network=host \
"${image_name}"
if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then
echo -e "${GREEN}Docker container '${container_name}' started successfully in detached mode.${NC}"
echo -e "${GREEN}It is configured to restart automatically on daemon startup or if it exits (unless stopped manually).${NC}"
echo -e "${GREEN}You can check its status with: docker ps -f name=${container_name}${NC}"
@@ -113,16 +117,81 @@ start_docker_container() {
# --- Main script execution ---
# Install PreReqs
install_prereqs
# Default flags
RUN_BOTH_DOCKERS=false
RUN_DISCORD_DOCKER=false
RUN_CLIENT_DOCKER=false
FULL_INSTALL=true
# Create config.json
create_config_json
# Parse command-line arguments
# We use a while loop with a case statement to handle different options.
# getopts is for short options (e.g., -r)
# For long options (e.g., --run), we'll handle them manually or use a more advanced parser.
# Build and Start Docker container
start_docker_container
while [[ "$#" -gt 0 ]]; do
case "$1" in
-r|--run)
RUN_BOTH_DOCKERS=true
FULL_INSTALL=false # If -r is passed, we don't do a full install
shift # Move to next argument
;;
-c|--client)
RUN_CLIENT_DOCKER=true
FULL_INSTALL=false
shift
;;
-d|--discord|-l)
RUN_DISCORD_DOCKER=true
FULL_INSTALL=false
shift
;;
*)
echo "Unknown parameter passed: $1"
shift
;;
esac
done
# Download the drb discord bot
install_discord_bot
if [ "$FULL_INSTALL" = true ]; then
echo -e "${GREEN}--- Starting full installation and setup ---${NC}"
# Install PreReqs
install_prereqs
echo -e "${GREEN}--- All installation and startup steps finished ---${NC}"
# Create config.json
create_config_json
# Build and Start Docker container
start_docker_container
# Download/update and run the drb discord bot
run_discord_bot
echo -e "${GREEN}--- All installation and startup steps finished ---${NC}"
elif [ "$RUN_BOTH_DOCKERS" = true ]; then
# Build and run the DRB client container
echo -e "${GREEN}--- Starting DRB Client Docker container ---${NC}"
start_docker_container
# Download/update and run the DRB Discord Bot container
echo -e "${GREEN}--- Starting DRB Listener Docker container ---${NC}"
run_discord_bot
echo -e "${GREEN}--- Docker containers startup finished ---${NC}"
elif [ "$RUN_DISCORD_DOCKER" = true ]; then
# Download/update and run the DRB Discord Bot container
echo -e "${GREEN}--- Starting DRB Listener Docker container ---${NC}"
run_discord_bot
echo -e "${GREEN}--- Discord Docker container startup finished ---${NC}"
elif [ "$RUN_CLIENT_DOCKER" = true ]; then
# Build and run the DRB client container
echo -e "${GREEN}--- Starting DRB Client Docker container ---${NC}"
start_docker_container
echo -e "${GREEN}--- Client Docker container startup finished ---${NC}"
else
# This case should ideally not be hit if flags are handled correctly,
# but it's here for completeness.
echo -e "${YELLOW}---No valid operation specified. Exiting.${NC}"
exit 1
fi