Implment first draft for discord module
This commit is contained in:
@@ -9,6 +9,7 @@ from internal.logger import create_logger
|
||||
from internal.op25_config_utls import scan_local_library
|
||||
import paho.mqtt.client as mqtt
|
||||
import requests
|
||||
from internal.discord_radio import DiscordRadioBot
|
||||
|
||||
# Initialize logging
|
||||
LOGGER = create_logger(__name__)
|
||||
@@ -29,6 +30,9 @@ NODE_LONG = os.getenv("NODE_LONG")
|
||||
# Global flag to track MQTT connection state
|
||||
MQTT_CONNECTED = False
|
||||
|
||||
# Initialize the Discord Bot
|
||||
discord_bot = DiscordRadioBot(listen_port=23457, forward_ports=[23456])
|
||||
|
||||
def handle_c2_command(topic, payload):
|
||||
"""
|
||||
Parses and routes commands received from the C2 server by calling the
|
||||
@@ -105,6 +109,17 @@ def handle_c2_command(topic, payload):
|
||||
except requests.exceptions.RequestException as e:
|
||||
LOGGER.error(f"Failed to connect to OP25 terminal for tuning: {e}")
|
||||
|
||||
elif command_type == "discord_join":
|
||||
token = data.get("token")
|
||||
channel_id = data.get("channel_id")
|
||||
if token and channel_id:
|
||||
asyncio.create_task(discord_bot.start_session(token, channel_id))
|
||||
LOGGER.info("Initiating Discord Session...")
|
||||
|
||||
elif command_type == "discord_leave":
|
||||
asyncio.create_task(discord_bot.stop_session())
|
||||
LOGGER.info("Ending Discord Session...")
|
||||
|
||||
else:
|
||||
LOGGER.warning(f"Unknown command type received: {command_type}")
|
||||
|
||||
@@ -317,6 +332,10 @@ async def mqtt_lifecycle_manager():
|
||||
if last_tgid != 0:
|
||||
# --- END PREVIOUS CALL ---
|
||||
await stop_recording()
|
||||
|
||||
# Stop Discord Transmission
|
||||
discord_bot.stop_transmission()
|
||||
|
||||
audio_url = None
|
||||
if current_call_id:
|
||||
audio_url = await loop.run_in_executor(None, upload_audio, current_call_id)
|
||||
@@ -334,6 +353,10 @@ async def mqtt_lifecycle_manager():
|
||||
|
||||
# --- START NEW CALL ---
|
||||
LOGGER.debug(f"Call Start: TGID {current_tgid} ({current_meta.get('alpha_tag')})")
|
||||
|
||||
# Trigger Discord Transmission
|
||||
discord_bot.start_transmission()
|
||||
discord_bot.update_system_presence(current_meta.get('sysname', 'Scanning'))
|
||||
|
||||
# Generate ID
|
||||
start_ts = int(now.timestamp())
|
||||
@@ -371,6 +394,10 @@ async def mqtt_lifecycle_manager():
|
||||
elif (now - potential_end_time).total_seconds() > DEBOUNCE_SECONDS:
|
||||
# --- END CALL (Debounce Expired) ---
|
||||
await stop_recording()
|
||||
|
||||
# Stop Discord Transmission
|
||||
discord_bot.stop_transmission()
|
||||
|
||||
audio_url = None
|
||||
if current_call_id:
|
||||
audio_url = await loop.run_in_executor(None, upload_audio, current_call_id)
|
||||
|
||||
Reference in New Issue
Block a user