mirror of
https://github.com/TheCommsChannel/TC2-BBS-mesh.git
synced 2025-08-07 22:22:23 -04:00
Menu Structure Changes
Menu structure changes to improve performance
This commit is contained in:
parent
5229cc5481
commit
ab154b2934
4 changed files with 198 additions and 232 deletions
|
@ -3,25 +3,52 @@ import logging
|
|||
from meshtastic import BROADCAST_NUM
|
||||
|
||||
from command_handlers import (
|
||||
handle_mail_command, handle_bulletin_command, handle_exit_command,
|
||||
handle_help_command, handle_stats_command, handle_fortune_command,
|
||||
handle_mail_command, handle_bulletin_command, handle_help_command, handle_stats_command, handle_fortune_command,
|
||||
handle_bb_steps, handle_mail_steps, handle_stats_steps, handle_wall_of_shame_command,
|
||||
handle_channel_directory_command, handle_channel_directory_steps, handle_send_mail_command,
|
||||
handle_read_mail_command, handle_check_mail_command, handle_delete_mail_confirmation, handle_post_bulletin_command,
|
||||
handle_check_bulletin_command, handle_read_bulletin_command, handle_read_channel_command,
|
||||
handle_post_channel_command, handle_list_channels_command, handle_quick_help_command
|
||||
)
|
||||
|
||||
from db_operations import add_bulletin, add_mail, delete_bulletin, delete_mail, get_db_connection, add_channel
|
||||
from utils import get_user_state, get_node_short_name, get_node_id_from_num, send_message
|
||||
|
||||
command_handlers = {
|
||||
"qch": handle_quick_help_command,
|
||||
"st": handle_stats_command,
|
||||
"fo": handle_fortune_command,
|
||||
"ws": handle_wall_of_shame_command,
|
||||
"exit": handle_exit_command,
|
||||
"help": handle_help_command
|
||||
main_menu_handlers = {
|
||||
"q": handle_quick_help_command,
|
||||
"b": lambda sender_id, interface: handle_help_command(sender_id, interface, 'bbs'),
|
||||
"u": lambda sender_id, interface: handle_help_command(sender_id, interface, 'utilities'),
|
||||
"x": handle_help_command
|
||||
}
|
||||
|
||||
bbs_menu_handlers = {
|
||||
"m": handle_mail_command,
|
||||
"b": handle_bulletin_command,
|
||||
"c": handle_channel_directory_command,
|
||||
"x": handle_help_command
|
||||
}
|
||||
|
||||
|
||||
utilities_menu_handlers = {
|
||||
"s": handle_stats_command,
|
||||
"f": handle_fortune_command,
|
||||
"w": handle_wall_of_shame_command,
|
||||
"x": handle_help_command
|
||||
}
|
||||
|
||||
|
||||
bulletin_menu_handlers = {
|
||||
"g": lambda sender_id, interface: handle_bb_steps(sender_id, '0', 1, {'board': 'General'}, interface, None),
|
||||
"i": lambda sender_id, interface: handle_bb_steps(sender_id, '1', 1, {'board': 'Info'}, interface, None),
|
||||
"n": lambda sender_id, interface: handle_bb_steps(sender_id, '2', 1, {'board': 'News'}, interface, None),
|
||||
"u": lambda sender_id, interface: handle_bb_steps(sender_id, '3', 1, {'board': 'Urgent'}, interface, None),
|
||||
"x": handle_help_command
|
||||
}
|
||||
|
||||
|
||||
board_action_handlers = {
|
||||
"r": lambda sender_id, interface, state: handle_bb_steps(sender_id, 'r', 2, state, interface, None),
|
||||
"p": lambda sender_id, interface, state: handle_bb_steps(sender_id, 'p', 2, state, interface, None),
|
||||
"x": handle_help_command
|
||||
}
|
||||
|
||||
def process_message(sender_id, message, interface, is_sync_message=False):
|
||||
|
@ -48,55 +75,85 @@ def process_message(sender_id, message, interface, is_sync_message=False):
|
|||
elif message.startswith("DELETE_MAIL|"):
|
||||
unique_id = message.split("|")[1]
|
||||
logging.info(f"Processing delete mail with unique_id: {unique_id}")
|
||||
recipient_id = get_recipient_id_by_mail(unique_id) # Fetch the recipient_id using this helper function
|
||||
recipient_id = get_recipient_id_by_mail(unique_id)
|
||||
delete_mail(unique_id, recipient_id, [], interface)
|
||||
elif message.startswith("CHANNEL|"):
|
||||
parts = message.split("|")
|
||||
channel_name, channel_url = parts[1], parts[2]
|
||||
add_channel(channel_name, channel_url)
|
||||
else:
|
||||
if message_lower in command_handlers:
|
||||
command_handlers[message_lower](sender_id, interface)
|
||||
elif state:
|
||||
command = state['command']
|
||||
step = state['step']
|
||||
|
||||
if command == 'MAIL':
|
||||
handle_mail_steps(sender_id, message, step, state, interface, bbs_nodes)
|
||||
elif command == 'BULLETIN':
|
||||
handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes)
|
||||
elif command == 'STATS':
|
||||
handle_stats_steps(sender_id, message, step, interface, bbs_nodes)
|
||||
elif command == 'CHANNEL_DIRECTORY':
|
||||
handle_channel_directory_steps(sender_id, message, step, state, interface)
|
||||
elif command == 'CHECK_MAIL':
|
||||
if step == 1:
|
||||
handle_read_mail_command(sender_id, message, state, interface)
|
||||
elif step == 2:
|
||||
handle_delete_mail_confirmation(sender_id, message, state, interface, bbs_nodes)
|
||||
elif command == 'CHECK_BULLETIN':
|
||||
if step == 1:
|
||||
handle_read_bulletin_command(sender_id, message, state, interface)
|
||||
elif command == 'CHECK_CHANNEL':
|
||||
if step == 1:
|
||||
handle_read_channel_command(sender_id, message, state, interface)
|
||||
elif command == 'LIST_CHANNELS':
|
||||
if step == 1:
|
||||
handle_read_channel_command(sender_id, message, state, interface)
|
||||
elif message.startswith("SM|"):
|
||||
handle_send_mail_command(sender_id, message, interface, bbs_nodes)
|
||||
elif message.startswith("CM"):
|
||||
if message_lower.startswith("sm,,"):
|
||||
handle_send_mail_command(sender_id, message_lower, interface, bbs_nodes)
|
||||
elif message_lower.startswith("cm"):
|
||||
handle_check_mail_command(sender_id, interface)
|
||||
elif message.startswith("PB|"):
|
||||
handle_post_bulletin_command(sender_id, message, interface, bbs_nodes)
|
||||
elif message.startswith("CB|"):
|
||||
handle_check_bulletin_command(sender_id, message, interface)
|
||||
elif message.startswith("CHP|"):
|
||||
handle_post_channel_command(sender_id, message, interface)
|
||||
elif message.startswith("CHL"):
|
||||
elif message_lower.startswith("pb,,"):
|
||||
handle_post_bulletin_command(sender_id, message_lower, interface, bbs_nodes)
|
||||
elif message_lower.startswith("cb,,"):
|
||||
handle_check_bulletin_command(sender_id, message_lower, interface)
|
||||
elif message_lower.startswith("chp,,"):
|
||||
handle_post_channel_command(sender_id, message_lower, interface)
|
||||
elif message_lower.startswith("chl"):
|
||||
handle_list_channels_command(sender_id, interface)
|
||||
else:
|
||||
handle_help_command(sender_id, interface)
|
||||
if state and state['command'] == 'MENU':
|
||||
menu_name = state['menu']
|
||||
if menu_name == 'bbs':
|
||||
handlers = bbs_menu_handlers
|
||||
elif menu_name == 'utilities':
|
||||
handlers = utilities_menu_handlers
|
||||
else:
|
||||
handlers = main_menu_handlers
|
||||
elif state and state['command'] == 'BULLETIN_MENU':
|
||||
handlers = bulletin_menu_handlers
|
||||
elif state and state['command'] == 'BULLETIN_ACTION':
|
||||
handlers = board_action_handlers
|
||||
else:
|
||||
handlers = main_menu_handlers
|
||||
|
||||
if message_lower == 'x':
|
||||
# Reset to main menu state
|
||||
handle_help_command(sender_id, interface)
|
||||
return
|
||||
|
||||
if message_lower in handlers:
|
||||
if state and state['command'] in ['BULLETIN_ACTION', 'BULLETIN_READ', 'BULLETIN_POST', 'BULLETIN_POST_CONTENT']:
|
||||
handlers[message_lower](sender_id, interface, state)
|
||||
else:
|
||||
handlers[message_lower](sender_id, interface)
|
||||
elif state:
|
||||
command = state['command']
|
||||
step = state['step']
|
||||
|
||||
if command == 'MAIL':
|
||||
handle_mail_steps(sender_id, message, step, state, interface, bbs_nodes)
|
||||
elif command == 'BULLETIN':
|
||||
handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes)
|
||||
elif command == 'STATS':
|
||||
handle_stats_steps(sender_id, message, step, interface)
|
||||
elif command == 'CHANNEL_DIRECTORY':
|
||||
handle_channel_directory_steps(sender_id, message, step, state, interface)
|
||||
elif command == 'CHECK_MAIL':
|
||||
if step == 1:
|
||||
handle_read_mail_command(sender_id, message, state, interface)
|
||||
elif step == 2:
|
||||
handle_delete_mail_confirmation(sender_id, message, state, interface, bbs_nodes)
|
||||
elif command == 'CHECK_BULLETIN':
|
||||
if step == 1:
|
||||
handle_read_bulletin_command(sender_id, message, state, interface)
|
||||
elif command == 'CHECK_CHANNEL':
|
||||
if step == 1:
|
||||
handle_read_channel_command(sender_id, message, state, interface)
|
||||
elif command == 'LIST_CHANNELS':
|
||||
if step == 1:
|
||||
handle_read_channel_command(sender_id, message, state, interface)
|
||||
elif command == 'BULLETIN_POST':
|
||||
handle_bb_steps(sender_id, message, 4, state, interface, bbs_nodes)
|
||||
elif command == 'BULLETIN_POST_CONTENT':
|
||||
handle_bb_steps(sender_id, message, 5, state, interface, bbs_nodes)
|
||||
elif command == 'BULLETIN_READ':
|
||||
handle_bb_steps(sender_id, message, 3, state, interface, bbs_nodes)
|
||||
else:
|
||||
handle_help_command(sender_id, interface)
|
||||
|
||||
|
||||
def on_receive(packet, interface):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue