From 113bde4babeaf3f980af4b37b4f577e963cbcb05 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Fri, 20 Sep 2024 21:30:18 -0700 Subject: [PATCH] Nestpebble Ideas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @Nestpebble here is the changes I did to bring this in thank you for the ideas and enhancements!! 🥔 * whoami new command * enhancing MOTD * new and better icons --- README.md | 3 ++- config.template | 2 ++ mesh_bot.py | 49 ++++++++++++++++++++++++++++++--------------- modules/settings.py | 2 ++ modules/system.py | 8 +++++++- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 17c0d9a..4072695 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Any messages that are over 160 characters are chunked into 160 message bytes to - `bbsdelete` delete a message example use: `bbsdelete #4` - Other functions - `whereami` returns the address of location of sender if known + - `whoami` returns some details of the node asking - `tide` returns the local tides, NOAA data source - `wx` and `wxc` returns local weather forecast, (wxc is metric value), NOAA or Open Meteo for weather forecasting. - `wxa` and `wxalert` return NOAA alerts. Short title or expanded details @@ -256,6 +257,6 @@ Games Ported from.. - https://github.com/Himan10/BlackJack - https://github.com/devtronvarma/Video-Poker-Terminal-Game -GitHub user mrpatrick1991 For Docker configs, PiDiBi looking at test functions and other suggestions like wxc, CPU use, and alerting ideas +GitHub user Nestpebble, for new ideas and enhancments, mrpatrick1991 For Docker configs, PiDiBi looking at test functions and other suggestions like wxc, CPU use, and alerting ideas Discord and Mesh user Cisien, and github Hailo1999, for testing and ideas! Lots of individuals on the Meshtastic discord who have tossed out ideas and tested code! diff --git a/config.template b/config.template index 7fe60d6..35c7c8f 100644 --- a/config.template +++ b/config.template @@ -30,6 +30,8 @@ defaultChannel = 0 # motd is reset to this value on boot motd = Thanks for using MeshBOT! Have a good day! welcome_message = MeshBot, here for you like a friend who is not. Try sending: ping @foo or, cmd +# whoami +whoami = True # enable or disable the Joke module DadJokes = True # enable or disable the Solar module diff --git a/mesh_bot.py b/mesh_bot.py index 17f9cdb..b8b1c17 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -88,22 +88,29 @@ def handle_ping(message, hop, snr, rssi): def handle_motd(message, message_from_id): global MOTD - if "?" in message and not "$": #basic help message - borked - return "Message of the day, set with 'motd $ motd'" - elif "$" in message and str(message_from_id) in str(bbs_admin_list): #access control via bbs admin list - works - motd = message.split("$")[1] - MOTD = motd.rstrip() - logger.debug(f"System: node changed MOTD: ", {message_from_id}) - return "MOTD Set to: " + MOTD - elif "$" in message and not str(bbs_admin_list).strip(): #no names in bbs admin list - borked - motd = message.split("$")[1] - MOTD = motd.rstrip() - return "MOTD Set to: " + MOTD - elif "$" in message and str(bbs_admin_list).strip(''): - logger.debug(f"System: node tried to change MOTD: ", str({message_from_id})) - return "I can't do that for you " + isAdmin = False + msg = "" + # check if the message_from_id is in the bbs_admin_list + if bbs_admin_list != ['']: + for admin in bbs_admin_list: + if str(message_from_id) == admin: + isAdmin = True + break else: - return MOTD + isAdmin = True + + if "$" in message and isAdmin: + motd = message.split("$")[1] + MOTD = motd.rstrip() + logger.debug(f"System: {message_from_id} changed MOTD: {MOTD}") + msg = "MOTD changed to: " + MOTD + elif "?" in message: + msg = "Message of the day, set with 'motd $ HelloWorld!'" + else: + logger.debug(f"System: {message_from_id} requested MOTD: {MOTD} isAdmin: {isAdmin}") + msg = "MOTD: " + MOTD + + return msg def handle_wxalert(message_from_id, deviceID, message): if use_meteo_wxApi: @@ -482,7 +489,17 @@ def handle_testing(message, hop, snr, rssi): return "🎙Testing 1,2,3 " + hop def handle_whoami(message_from_id, deviceID): - return "You are " + str(message_from_id) + " AKA " + str(get_name_from_number(message_from_id, 'long', deviceID)) + loc = [] + msg = "You are " + str(message_from_id) + " AKA " +\ + str(get_name_from_number(message_from_id, 'long', deviceID) + " AKA " +\ + str(get_name_from_number(message_from_id, 'short', deviceID)) + " AKA " +\ + str(decimal_to_hex(message_from_id)) + " AKA " +\ + str(message_from_id) + f"\n") + loc = get_node_location(message_from_id, deviceID) + if loc != [latitudeValue,longitudeValue]: + msg += f"You are at: lat:{loc[0]} lon:{loc[1]}\n" + return msg + def onDisconnect(interface): global retry_int1, retry_int2 diff --git a/modules/settings.py b/modules/settings.py index d8312f7..9bb4b6f 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -96,6 +96,7 @@ try: welcome_message = (f"{welcome_message}").replace('\\n', '\n') # allow for newlines in the welcome message motd_enabled = config['general'].getboolean('motdEnabled', True) MOTD = config['general'].get('motd', MOTD) + whoami_enabled = config['general'].getboolean('whoami', True) dad_jokes_enabled = config['general'].getboolean('DadJokes', False) solar_conditions_enabled = config['general'].getboolean('spaceWeather', True) wikipedia_enabled = config['general'].getboolean('wikipedia', False) @@ -144,6 +145,7 @@ try: blackjack_enabled = config['games'].getboolean('blackjack', True) videoPoker_enabled = config['games'].getboolean('videoPoker', True) + # messaging settings responseDelay = config['messagingSettings'].getfloat('responseDelay', 0.7) # default 0.7 splitDelay = config['messagingSettings'].getfloat('splitDelay', 0) # default 0 MESSAGE_CHUNK_SIZE = config['messagingSettings'].getint('MESSAGE_CHUNK_SIZE', 160) # default 160 diff --git a/modules/system.py b/modules/system.py index 0934571..42ea652 100644 --- a/modules/system.py +++ b/modules/system.py @@ -10,7 +10,7 @@ import contextlib # for suppressing output on watchdog from modules.log import * # Global Variables -trap_list = ("cmd","cmd?","whoami") # default trap list +trap_list = ("cmd","cmd?",) # default trap list help_message = "CMD?:" asyncLoop = asyncio.new_event_loop() games_enabled = False @@ -34,6 +34,12 @@ if motd_enabled: trap_list = trap_list + trap_list_motd help_message = help_message + ", motd" +# whoami Configuration +if whoami_enabled: + trap_list_whoami = ("whoami",) + trap_list = trap_list + trap_list_whoami + help_message = help_message + ", whoami" + # Solar Conditions Configuration if solar_conditions_enabled: from modules.solarconditions import * # from the spudgunman/meshing-around repo