diff --git a/mesh_bot.py b/mesh_bot.py index 069a0c9..fbd3e1d 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -5,6 +5,7 @@ import asyncio # for the event loop import time # for sleep, get some when you can :) from pubsub import pub # pip install pubsub +from modules.settings import * from modules.system import * def auto_response(message, snr, rssi, hop, message_from_id, channel_number): diff --git a/modules/bbstools.py b/modules/bbstools.py index 336c110..5795ec8 100644 --- a/modules/bbstools.py +++ b/modules/bbstools.py @@ -3,9 +3,6 @@ import pickle # pip install pickle -bbs_ban_list = [] # list of banned nodes numbers ex: [2813308004, 4258675309] -bbs_admin_list = [] # list of admin nodes numbers ex: [2813308004, 4258675309] - trap_list_bbs = ("bbslist", "bbspost", "bbsread", "bbsdelete", "bbshelp") # global message list, later we will use a pickle on disk diff --git a/modules/locationdata.py b/modules/locationdata.py index 42c293e..8a5cd45 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -7,13 +7,7 @@ import maidenhead as mh # pip install maidenhead import requests # pip install requests import bs4 as bs # pip install beautifulsoup4 import xml.dom.minidom - -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" +from modules.settings import * trap_list_location = ("whereami", "tide", "moon", "wx", "wxc", "wxa", "wxalert") diff --git a/modules/settings.py b/modules/settings.py new file mode 100644 index 0000000..e934641 --- /dev/null +++ b/modules/settings.py @@ -0,0 +1,61 @@ +import configparser + +# Read the config file +config = configparser.ConfigParser() +config_file = "config.ini" + +try: + config.read(config_file) +except Exception as e: + print(f"System: Error reading config file: {e}") + +if config.sections() == []: + print(f"System: Error reading config file: {config_file} is empty or does not exist.") + config['interface'] = {'type': 'serial', 'port': "/dev/ttyACM0", 'hostname': '', 'mac': ''} + config['general'] = {'respond_by_dm_only': 'True', 'defaultChannel': '0', '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', + 'DadJokes': 'True', 'StoreForward': 'True', 'StoreLimit': '3'} + config['bbs'] = {'enabled': 'True', 'bbsdb': 'bbsdb.pkl'} + config['location'] = {'enabled': 'True','lat': '48.50', 'lon': '-123.0'} + config['solar'] = {'enabled': 'True'} + config.write(open(config_file, 'w')) + print (f"System: Config file created, check {config_file} or review the config.template") + +# config.ini variables +interface_type = config['interface'].get('type', 'serial') +port = config['interface'].get('port', '') +hostname = config['interface'].get('hostname', '') +mac = 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) + +LATITUDE = config['location'].getfloat('lat', 48.50) +LONGITUDE = config['location'].getfloat('lon', -123.0) + +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) +location_enabled = config['location'].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 diff --git a/modules/solarconditions.py b/modules/solarconditions.py index 9f2c944..0b7bf16 100644 --- a/modules/solarconditions.py +++ b/modules/solarconditions.py @@ -7,8 +7,7 @@ import xml.dom.minidom from datetime import datetime import ephem # pip install pyephem from datetime import timedelta - -URL_TIMEOUT = 10 # wait time for URL requests +from modules.settings import * trap_list_solarconditions = ("sun", "solar", "hfcond") diff --git a/modules/system.py b/modules/system.py index d6aa7ac..c13afce 100644 --- a/modules/system.py +++ b/modules/system.py @@ -5,81 +5,37 @@ import meshtastic.serial_interface #pip install meshtastic import meshtastic.tcp_interface import meshtastic.ble_interface from datetime import datetime -import configparser +from modules.settings import * # Global Variables trap_list = ("ping", "pinging", "ack", "testing", "test", "pong", "motd", "cmd", "lheard", "sitrep") help_message = "CMD?: ping, motd, sitrep" -# Read the config file -config = configparser.ConfigParser() -config_file = "config.ini" - -try: - config.read(config_file) -except Exception as e: - print(f"System: Error reading config file: {e}") - -if config.sections() == []: - print(f"System: Error reading config file: {config_file} is empty or does not exist.") - config['interface'] = {'type': 'serial', 'port': "/dev/ttyACM0", 'hostname': '', 'mac': ''} - config['general'] = {'respond_by_dm_only': 'True', 'defaultChannel': '0', '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', - 'DadJokes': 'True', 'StoreForward': 'True', 'StoreLimit': '3'} - config['bbs'] = {'enabled': 'True', 'bbsdb': 'bbsdb.pkl'} - config['location'] = {'enabled': 'True','lat': '48.50', 'lon': '-123.0'} - config['solar'] = {'enabled': 'True'} - config.write(open(config_file, 'w')) - print (f"System: Config file created, check {config_file} or review the config.template") - -# config.ini variables -interface_type = config['interface'].get('type', 'serial') -port = config['interface'].get('port', '') -hostname = config['interface'].get('hostname', '') -mac = 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) - -LATITUDE = config['location'].getfloat('lat', 48.50) -LONGITUDE = config['location'].getfloat('lon', -123.0) - -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 Configuration -solar_conditions_enabled = config['solar'].getboolean('enabled', False) if solar_conditions_enabled: from modules.solarconditions import * # from the spudgunman/meshing-around repo trap_list = trap_list + trap_list_solarconditions # items hfcond, solar, sun, moon help_message = help_message + ", sun, hfcond, solar, moon, tide" # Location Configuration -location_enabled = config['location'].getboolean('enabled', False) if location_enabled: from modules.locationdata import * # from the spudgunman/meshing-around repo trap_list = trap_list + trap_list_location # items tide, whereami, wxc, wx help_message = help_message + ", whereami, wx, wxc, wxa" # BBS Configuration -bbs_enabled = config['bbs'].getboolean('enabled', False) -bbsdb = config['bbs'].get('bbsdb', 'bbsdb.pkl') if bbs_enabled: from modules.bbstools import * # from the spudgunman/meshing-around repo trap_list = trap_list + trap_list_bbs # items bbslist, bbspost, bbsread, bbsdelete, bbshelp help_message = help_message + ", bbslist, bbshelp" # Dad Jokes Configuration -dad_jokes_enabled = config['general'].getboolean('DadJokes', False) if dad_jokes_enabled: from dadjokes import Dadjoke # pip install dadjokes trap_list = trap_list + ("joke",) help_message = help_message + ", joke" # Store and Forward Configuration -store_forward_enabled = config['general'].getboolean('StoreForward', False) if store_forward_enabled: trap_list = trap_list + ("messages",) help_message = help_message + ", messages" diff --git a/pong_bot.py b/pong_bot.py index 2b81451..bad2441 100755 --- a/pong_bot.py +++ b/pong_bot.py @@ -5,6 +5,7 @@ import asyncio # for the event loop import time # for sleep, get some when you can :) from pubsub import pub # pip install pubsub +from modules.settings import * from modules.system import * def auto_response(message, snr, rssi, hop, message_from_id, channel_number):