From 3646e775330bb3157a2877272d5b33c4a6b08f61 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 18:44:42 +0100 Subject: [PATCH 01/12] Added Ram usage to server stats --- command_handlers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 284a39f..4de1961 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -111,9 +111,11 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: psutil.cpu_percent() + psutil.virtual_memory().percent time.sleep(0.1) cpu = str(psutil.cpu_percent()/psutil.cpu_count()) - response = "CPU: " + cpu + "%" + ram = str(psutil.virtual_memory().percent) + response = "CPU: " + cpu + "%\nRAM:" + ram + "%" send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From a69b0b06029a7532d34a0c06a6bbe4b621eee458 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 18:47:56 +0100 Subject: [PATCH 02/12] fixed missing space in Ram usage message --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 4de1961..10a8142 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -115,7 +115,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): time.sleep(0.1) cpu = str(psutil.cpu_percent()/psutil.cpu_count()) ram = str(psutil.virtual_memory().percent) - response = "CPU: " + cpu + "%\nRAM:" + ram + "%" + response = "CPU: " + cpu + "%\nRAM: " + ram + "%" send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From 90730ba1ba24fd53074cd5eabdbf3dfe2569dd21 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 18:48:38 +0100 Subject: [PATCH 03/12] small code fix --- command_handlers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 10a8142..3fa9869 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -111,7 +111,6 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: psutil.cpu_percent() - psutil.virtual_memory().percent time.sleep(0.1) cpu = str(psutil.cpu_percent()/psutil.cpu_count()) ram = str(psutil.virtual_memory().percent) From 3bf27a30d991419d611223dad8ea2c9a9eb66dce Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 18:52:46 +0100 Subject: [PATCH 04/12] Added total ram --- command_handlers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index 3fa9869..054e8a8 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -113,8 +113,9 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): psutil.cpu_percent() time.sleep(0.1) cpu = str(psutil.cpu_percent()/psutil.cpu_count()) - ram = str(psutil.virtual_memory().percent) - response = "CPU: " + cpu + "%\nRAM: " + ram + "%" + ramu = str(psutil.virtual_memory().percent) + ramt = str(psutil.virtual_memory().total) + response = "CPU: " + cpu + "%\nRAM: " + ramu + "% Used of " + ramt send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From 38ad26166b98ab3a15dc54d6e678dcd8169fac49 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 19:04:51 +0100 Subject: [PATCH 05/12] Removed total ram as not reporting correctly. Will revisit in future --- command_handlers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index 054e8a8..06aded5 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -114,8 +114,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): time.sleep(0.1) cpu = str(psutil.cpu_percent()/psutil.cpu_count()) ramu = str(psutil.virtual_memory().percent) - ramt = str(psutil.virtual_memory().total) - response = "CPU: " + cpu + "%\nRAM: " + ramu + "% Used of " + ramt + response = "CPU: " + cpu + "%\nRAM: " + ramu send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From a1ab8977552b3766cb9db7a063824ce575667ca6 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 19:07:33 +0100 Subject: [PATCH 06/12] tidy up how server stats are displayed --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 06aded5..ec1cf41 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -114,7 +114,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): time.sleep(0.1) cpu = str(psutil.cpu_percent()/psutil.cpu_count()) ramu = str(psutil.virtual_memory().percent) - response = "CPU: " + cpu + "%\nRAM: " + ramu + response = "CPU: " + cpu + "% Used\nRAM: " + ramu + "% Used" send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From a6c306e021896a64d248a53874e367ef571a8f62 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 19:11:36 +0100 Subject: [PATCH 07/12] removed unused import --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index ec1cf41..be4122b 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -3,7 +3,7 @@ import random import time import psutil -from config_init import initialize_config +#from config_init import initialize_config from db_operations import ( add_bulletin, add_mail, delete_mail, get_bulletin_content, get_bulletins, From 70fab554f0b4e5beab7fbf73cfbc95f82eb29289 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 19:13:47 +0100 Subject: [PATCH 08/12] Tidy up code --- command_handlers.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index be4122b..edbcb75 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -3,7 +3,6 @@ import random import time import psutil -#from config_init import initialize_config from db_operations import ( add_bulletin, add_mail, delete_mail, get_bulletin_content, get_bulletins, @@ -16,31 +15,26 @@ from utils import ( update_user_state ) - def get_node_name(node_id, interface): node_info = interface.nodes.get(node_id) if node_info: return node_info['user']['longName'] return f"Node {node_id}" - def handle_mail_command(sender_id, interface): response = "✉️ MAIL MENU ✉️\n\nWhat would you like to do with mail?\n\n[0]Read\n[1]Send\n[2]Exit" send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'MAIL', 'step': 1}) - def handle_bulletin_command(sender_id, interface): response = "📰 BULLETIN MENU 📰\n\nWhich board would you like to enter?\n\n[0]General\n[1]Info\n[2]News\n[3]Urgent\n[4]Exit" send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'BULLETIN', 'step': 1}) - def handle_exit_command(sender_id, interface): send_message("Type 'HELP' for a list of commands.", sender_id, interface) update_user_state(sender_id, None) - def handle_help_command(sender_id, interface, state=None): title = "█▓▒░ Yorkshire BBS ░▒▓█\n\n" commands = [ @@ -78,13 +72,11 @@ def handle_help_command(sender_id, interface, state=None): response = title + "Available commands:\n" + "\n".join(commands) send_message(response, sender_id, interface) - def handle_stats_command(sender_id, interface): response = "What stats would you like to view?\n\n[0]Mesh Stats\n[1]Server Stats\n[2]Exit Stats Menu" send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'STATS', 'step': 1}) - def handle_fortune_command(sender_id, interface): try: with open('fortunes.txt', 'r') as file: @@ -98,7 +90,6 @@ def handle_fortune_command(sender_id, interface): except Exception as e: send_message(f"Error generating fortune: {e}", sender_id, interface) - def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): if step == 1: choice = int(message) @@ -164,7 +155,6 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): send_message(f"Total nodes seen in the last {timeframes[choice - 1]}: {total_nodes}", sender_id, interface) handle_stats_steps(sender_id, '0', 1, interface, bbs_nodes) - def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes): boards = {0: "General", 1: "Info", 2: "News", 3: "Urgent"} @@ -253,7 +243,6 @@ def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes): state['content'] += message + "\n" update_user_state(sender_id, state) - def handle_mail_steps(sender_id, message, step, state, interface, bbs_nodes): if step == 1: choice = message @@ -276,8 +265,7 @@ def handle_mail_steps(sender_id, message, step, state, interface, bbs_nodes): elif step == 2: mail_id = int(message) - try: - + try: # ERROR: sender_id is not what is stored in the DB sender_node_id = get_node_id_from_num(sender_id, interface) sender, date, subject, content, unique_id = get_mail_content(mail_id, sender_node_id) @@ -357,7 +345,6 @@ def handle_mail_steps(sender_id, message, step, state, interface, bbs_nodes): send_message("Okay, feel free to send another command.", sender_id, interface) update_user_state(sender_id, None) - def handle_wall_of_shame_command(sender_id, interface): response = "Devices with battery levels below 20%:\n" for node_id, node in interface.nodes.items(): @@ -370,13 +357,11 @@ def handle_wall_of_shame_command(sender_id, interface): response = "No devices with battery levels below 20% found." send_message(response, sender_id, interface) - def handle_channel_directory_command(sender_id, interface): response = "📚 CHANNEL DIRECTORY 📚\n\nWhat would you like to do in the Channel Directory?\n\n[0]View\n[1]Post\n[2]Exit" send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'CHANNEL_DIRECTORY', 'step': 1}) - def handle_channel_directory_steps(sender_id, message, step, state, interface): if step == 1: choice = message @@ -415,4 +400,4 @@ def handle_channel_directory_steps(sender_id, message, step, state, interface): channel_name = state['channel_name'] add_channel(channel_name, channel_url) send_message(f"Your channel '{channel_name}' has been added to the directory.", sender_id, interface) - handle_channel_directory_command(sender_id, interface) + handle_channel_directory_command(sender_id, interface) \ No newline at end of file From d799be94147afdfc5fbf8e492ccd5966ef03ed91 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 19:15:43 +0100 Subject: [PATCH 09/12] code fix in post bulletin --- command_handlers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index edbcb75..313f604 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -234,7 +234,8 @@ def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes): update_user_state(sender_id, None) return sender_short_name = node_info['user'].get('shortName', f"Node {sender_id}") - unique_id = add_bulletin(board, sender_short_name, subject, content, bbs_nodes, interface) +# unique_id = add_bulletin(board, sender_short_name, subject, content, bbs_nodes, interface) + add_bulletin(board, sender_short_name, subject, content, bbs_nodes, interface) send_message(f"Your bulletin '{subject}' has been posted to {board}.\n(╯°□°)╯📄📌[{board}]", sender_id, interface) response = f"What would you like to do in the {board} board?\n\n[0]View Bulletins\n[1]Post Bulletin\n[2]Exit" send_message(response, sender_id, interface) From 3b6dd940923efc27291979e06dd15996a8b30a2a Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 19:19:05 +0100 Subject: [PATCH 10/12] Tidy unused code --- command_handlers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 313f604..7d2929b 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -234,7 +234,6 @@ def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes): update_user_state(sender_id, None) return sender_short_name = node_info['user'].get('shortName', f"Node {sender_id}") -# unique_id = add_bulletin(board, sender_short_name, subject, content, bbs_nodes, interface) add_bulletin(board, sender_short_name, subject, content, bbs_nodes, interface) send_message(f"Your bulletin '{subject}' has been posted to {board}.\n(╯°□°)╯📄📌[{board}]", sender_id, interface) response = f"What would you like to do in the {board} board?\n\n[0]View Bulletins\n[1]Post Bulletin\n[2]Exit" From 6a8930cdfd7e16689034c93b3395b48a2aa715a1 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 19:21:10 +0100 Subject: [PATCH 11/12] code fix --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 7d2929b..ff8055d 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -275,7 +275,7 @@ def handle_mail_steps(sender_id, message, step, state, interface, bbs_nodes): except TypeError: # get_main_content returned None. Node tried to access somebody's else mail message logging.info(f"Node {sender_id} tried to access non-existent message") - send_message(f"Mail not found", sender_id, interface) + send_message("Mail not found", sender_id, interface) update_user_state(sender_id, None) elif step == 3: From fc2a8870a21dc2d4af8a424607d55a8be980c2c7 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 19:23:16 +0100 Subject: [PATCH 12/12] trunk fix --- command_handlers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/command_handlers.py b/command_handlers.py index ff8055d..ac30d57 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -84,6 +84,7 @@ def handle_fortune_command(sender_id, interface): if not fortunes: send_message("No fortunes available.", sender_id, interface) return + # trunk-ignore(bandit/B311) fortune = random.choice(fortunes).strip() decorated_fortune = f"🔮 {fortune} 🔮" send_message(decorated_fortune, sender_id, interface)