diff --git a/mesh_bot.py b/mesh_bot.py index 059736b..884580d 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -42,7 +42,7 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi response = "" for msgH in msg_history: # check if the message is from the same channel - if msgH[2] == channel_number or msgH[2] == DEFAULT_CHANNEL: + if msgH[2] == channel_number or msgH[2] == publicChannel: # consider message safe to send response += f"\n{msgH[0]}: {msgH[1]}" @@ -163,7 +163,7 @@ def onReceive(packet, interface): if packet.get('channel'): channel_number = packet['channel'] else: - channel_number = DEFAULT_CHANNEL + channel_number = publicChannel msg = bbs_check_dm(message_from_id) if msg: @@ -184,7 +184,7 @@ def onReceive(packet, interface): if packet.get('channel'): channel_number = packet['channel'] else: - channel_number = DEFAULT_CHANNEL + channel_number = publicChannel # check if the packet has a hop count flag use it if packet.get('hopsAway'): @@ -236,12 +236,12 @@ def onReceive(packet, interface): # message is on a channel if messageTrap(message_string): print(f"{log_timestamp()} Received On Device:{rxNode} Channel {channel_number}: {message_string} From: {get_name_from_number(message_from_id)}") - if RESPOND_BY_DM_ONLY: + if useDMForResponse: # respond to channel message via direct message send_message(auto_response(message_string, snr, rssi, hop, message_from_id, channel_number, rxNode), channel_number, message_from_id) else: # or respond to channel message on the channel itself - if channel_number == DEFAULT_CHANNEL: + if channel_number == publicChannel: # warning user spamming default channel print(f"{log_timestamp()} System: Warning spamming default channel not allowed. sending DM to {get_name_from_number(message_from_id)}") diff --git a/modules/settings.py b/modules/settings.py index b8498f3..98ee1eb 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -1,6 +1,20 @@ import configparser -# Read the config file +# Global variables +URL_TIMEOUT = 10 # wait time for URL requests +DAYS_OF_WEATHER = 4 # weather forecast days, the first two rows are today and tonight +ALERT_COUNT = 2 # number of weather alerts to display +STORE_LIMIT = 3 # number of messages to store for Store and Forward +bbs_ban_list = [] # list of banned nodes numbers ex: [2813308004, 4258675309] +bbs_admin_list = [] # list of admin nodes numbers ex: [2813308004, 4258675309] +msg_history = [] # message history for the store and forward feature + +# messages +NO_DATA_NOGPS = "No location data: does your device have GPS?" +ERROR_FETCHING_DATA = "error fetching data" +WELCOME_MSG = 'MeshBot, here for you like a friend who is not. Try sending: ping @foo or, cmd' + +# Read the config file, if it does not exist, create basic config file config = configparser.ConfigParser() config_file = "config.ini" @@ -21,43 +35,32 @@ if config.sections() == []: config.write(open(config_file, 'w')) print (f"System: Config file created, check {config_file} or review the config.template") -# config.ini variables +# interface1 settings interface1_type = config['interface'].get('type', 'serial') port1 = config['interface'].get('port', '') hostname1 = config['interface'].get('hostname', '') mac1 = config['interface'].get('mac', '') -msg_history = [] # message history for the store and forward feature -storeFlimit = config['general'].getint('StoreLimit', 3) # limit of messages to store for Store and Forward -RESPOND_BY_DM_ONLY = config['general'].getboolean('respond_by_dm_only', True) -DEFAULT_CHANNEL = config['general'].getint('defaultChannel', 0) +# interface2 settings +if 'interface2' in config: + interface2_type = config['interface2'].get('type', 'serial') + port2 = config['interface2'].get('port', '') + hostname2 = config['interface2'].get('hostname', '') + mac2 = config['interface2'].get('mac', '') + interface2_enabled = config['interface2'].getboolean('enabled', False) -LATITUDE = config['location'].getfloat('lat', 48.50) -LONGITUDE = config['location'].getfloat('lon', -123.0) - -zuluTime = config['general'].getboolean('zuluTime', False) - -try: - if MOTD == '': - config['general'].get('motd', 'Thanks for using MeshBOT! Have a good day!') -except NameError: - MOTD = config['general'].get('motd', 'Thanks for using MeshBOT! Have a good day!') - -welcome_message = config['general'].get('welcome_message', 'MeshBot, here for you like a friend who is not. Try sending: ping @foo or, cmd') - -solar_conditions_enabled = config['solar'].getboolean('enabled', False) +# variables +storeFlimit = config['general'].getint('StoreLimit', STORE_LIMIT) +useDMForResponse = config['general'].getboolean('respond_by_dm_only', True) +publicChannel = config['general'].getint('defaultChannel', 0) # the meshtastic public channel location_enabled = config['location'].getboolean('enabled', False) +latitudeValue = config['location'].getfloat('lat', 48.50) +longitudeValue = config['location'].getfloat('lon', -123.0) +zuluTime = config['general'].getboolean('zuluTime', False) +welcome_message = config['general'].get('welcome_message', WELCOME_MSG) +solar_conditions_enabled = config['solar'].getboolean('enabled', False) bbs_enabled = config['bbs'].getboolean('enabled', False) bbsdb = config['bbs'].get('bbsdb', 'bbsdb.pkl') dad_jokes_enabled = config['general'].getboolean('DadJokes', False) store_forward_enabled = config['general'].getboolean('StoreForward', False) - -URL_TIMEOUT = 10 # wait time for URL requests -DAYS_OF_WEATHER = 4 # weather forecast days, the first two rows are today and tonight -# error messages -ALERT_COUNT = 2 # number of weather alerts to display -NO_DATA_NOGPS = "No location data: does your device have GPS?" -ERROR_FETCHING_DATA = "error fetching data" - -bbs_ban_list = [] # list of banned nodes numbers ex: [2813308004, 4258675309] -bbs_admin_list = [] # list of admin nodes numbers ex: [2813308004, 4258675309] \ No newline at end of file +config['general'].get('motd', 'Thanks for using MeshBOT! Have a good day!') \ No newline at end of file diff --git a/modules/solarconditions.py b/modules/solarconditions.py index 46e4912..e0256f0 100644 --- a/modules/solarconditions.py +++ b/modules/solarconditions.py @@ -65,8 +65,8 @@ def get_sun(lat=0, lon=0): obs.lat = str(lat) obs.lon = str(lon) else: - obs.lat = str(LATITUDE) - obs.lon = str(LONGITUDE) + obs.lat = str(latitudeValue) + obs.lon = str(longitudeValue) sun.compute(obs) sun_table = {} @@ -101,8 +101,8 @@ def get_moon(lat=0, lon=0): obs.lat = str(lat) obs.lon = str(lon) else: - obs.lat = str(LATITUDE) - obs.lon = str(LONGITUDE) + obs.lat = str(latitudeValue) + obs.lon = str(longitudeValue) obs.date = datetime.now() moon.compute(obs) diff --git a/pong_bot.py b/pong_bot.py index f8b7cd7..5f1777d 100755 --- a/pong_bot.py +++ b/pong_bot.py @@ -81,7 +81,7 @@ def onReceive(packet, interface): if packet.get('channel'): channel_number = packet['channel'] else: - channel_number = DEFAULT_CHANNEL + channel_number = publicChannel # check if the packet has a hop count flag use it if packet.get('hopsAway'): @@ -133,12 +133,12 @@ def onReceive(packet, interface): # message is on a channel if messageTrap(message_string): print(f"{log_timestamp()} Received On Device:{rxNode} Channel {channel_number}: {message_string} From: {get_name_from_number(message_from_id)}") - if RESPOND_BY_DM_ONLY: + if useDMForResponse: # respond to channel message via direct message send_message(auto_response(message_string, snr, rssi, hop, message_from_id, channel_number, rxNode), channel_number, message_from_id) else: # or respond to channel message on the channel itself - if channel_number == DEFAULT_CHANNEL: + if channel_number == publicChannel: # warning user spamming default channel print(f"{log_timestamp()} System: Warning spamming default channel not allowed. sending DM to {get_name_from_number(message_from_id)}")