Add files via upload

This commit is contained in:
TC² 2025-01-07 14:53:16 -05:00 committed by GitHub
commit 635e7f42d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 2399 additions and 0 deletions

45
commands.py Normal file
View file

@ -0,0 +1,45 @@
import database
import aprs_comm
def handle_command(callsign, command):
normalized_callsign = callsign.split('-')[0].upper()
parts = command.split(' ', 1)
cmd = parts[0].upper()
arg = parts[1] if len(parts) > 1 else ''
if cmd in ['LIST', 'L']:
bulletins = database.get_bulletins()
return [
f"{b[2]} {b[1]}: {b[0]}" for b in bulletins
] or ["No bulletins available."]
elif cmd in ['MSG', 'M']:
messages = database.get_messages_for_user(normalized_callsign)
return [
f"From {m[0]} ({m[2]}): {m[1]}" for m in messages
] or ["No messages for you."]
elif cmd in ['POST', 'P']:
if arg:
database.add_bulletin(normalized_callsign, arg)
return ["Bulletin posted."]
return ["Usage: POST <text>"]
elif cmd in ['SEND', 'S']:
args = arg.split(' ', 1)
if len(args) == 2:
recipient, message = args
database.add_message(normalized_callsign, recipient, message)
notification = f"You have a new message from {normalized_callsign}."
aprs_comm.send_direct_message(recipient, notification)
return [f"Message sent to {recipient}."]
return ["Usage: SEND <callsign> <text>"]
else:
return [
"Hello and Welcome to the TC2-BBS!",
"Please send a message with one of the commands below.",
"Commands: (L)IST, (M)SG, (P)OST <text>, (S)SEND <callsign> <text>"
]