Update pagebot.py

This commit is contained in:
majmongoose
2026-08-23 08:18:19 -04:00
parent 05e7c1e335
commit b2fb924450
+37 -9
View File
@@ -119,6 +119,20 @@ def convert_to_text(mp3_path, mp3_name):
print(f"Error during conversion: {e}")
return ""
def parse_dispatch_filename(filename):
name = os.path.splitext(filename)[0]
parts = name.split('-', 1)
station_number = parts[0].strip()
remainder = parts[1].strip() if len(parts) > 1 else ""
segments = remainder.split('_')
station_name = segments[0] if segments else ""
timestamp = ""
if len(segments) >= 6:
year, month, day = segments[1], segments[2], segments[3]
hour, minute, second = segments[4], segments[5], segments[6] if len(segments) > 6 else "00"
timestamp = f"{month}/{day}/{year} {hour}:{minute}:{second}"
return station_number, station_name, timestamp
async def upload_to_discord(mp4_file, text):
if mp4_file is None:
print("Conversion failed. Skipping upload.")
@@ -126,18 +140,32 @@ async def upload_to_discord(mp4_file, text):
channel = client.get_channel(secrets_file.channel_id)
if channel:
filename = os.path.basename(mp4_file)
station_number, station_name, timestamp = parse_dispatch_filename(filename)
description = timestamp if timestamp else ""
if text:
description += f"\n\n{text}" if description else text
embed = discord.Embed(
title=f"Station {station_number} - {station_name}",
description=description,
color=0xFF0000
)
role_name = station_number
role = discord.utils.get(channel.guild.roles, name=role_name)
mention = f"{role.mention}" if role else ""
with open(mp4_file, 'rb') as f:
await channel.send(filename, file=discord.File(f))
await channel.send(
content=f"{mention} {secrets_file.notify_text}".strip() if mention else None,
embed=embed,
file=discord.File(f)
)
if not role:
print(f"Role '{role_name}' not found.")
if secrets_file.delete_after_upload:
os.remove(mp4_file)
if text != "":
await channel.send(f"The following text was transcoded from the recording: \n{text}")
role_name = filename.split('-', 1)[0].strip()
role = discord.utils.get(channel.guild.roles, name=role_name)
if role:
await channel.send(f"{role.mention} {secrets_file.notify_text}")
else:
print(f"Role '{role_name}' not found.")
else:
print(f"Could not find channel with ID {secrets_file.channel_id}")