diff --git a/README.md b/README.md index 113d52c..f9dcbfa 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ pip install requests pip install geopy pip install maidenhead pip install beautifulsoup4 +pip install dadjokes ``` # Recognition diff --git a/bbstools.py b/bbstools.py new file mode 100644 index 0000000..c9e3b95 --- /dev/null +++ b/bbstools.py @@ -0,0 +1,9 @@ +# helper functions for various BBS messaging tasks +# K7MHI Kelly Keeton 2024 + +from dadjokes import Dadjoke + +def tell_joke(): + # tell a dad joke, does it need an explanationn :) + dadjoke = Dadjoke() + return dadjoke.joke \ No newline at end of file diff --git a/mesh-bot.py b/mesh-bot.py index abf019f..a2e4bb4 100755 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -11,18 +11,22 @@ from datetime import datetime from solarconditions import * # from the spudgunman/meshing-around repo from locationdata import * # from the spudgunman/meshing-around repo +from bbstools import * # from the spudgunman/meshing-around repo # Uncomment the interface you want to use depending on your device connection interface = meshtastic.serial_interface.SerialInterface() #serial interface #interface=meshtastic.tcp_interface.TCPInterface(hostname="192.168.0.1") # IP of your device #interface=meshtastic.ble_interface.BLEInterface("AA:BB:CC:DD:EE:FF") # BLE interface -trap_list = ("ping","ack","testing","pong","motd","help","sun","solar","hfcond","lheard","whereami","tide","moon","wx") #A list of strings to trap and respond to +#A list of strings to trap and respond to +trap_list = ("ping","ack","testing","pong","motd","help","sun","solar","hfcond","lheard","whereami","tide","moon","wx","joke") + welcome_message = "MeshBot, here for you like a friend who is not. Try sending: ping @foo or, help" help_message = "Commands are: ping, ack, motd, sun, solar, hfcond, Lheard, whereami, tide, moon, wx" -RESPOND_BY_DM_ONLY = True # Set to True to respond messages via DM only (keeps the channel clean) MOTD = "Thanks for using PongBOT! Have a good day!" # Message of the Day +RESPOND_BY_DM_ONLY = True # Set to True to respond messages via DM only (keeps the channel clean) +#Get the node number of the device, check if the device is connected try: myinfo = interface.getMyNodeInfo() myNodeNum = myinfo['num'] @@ -89,6 +93,8 @@ def auto_response(message,snr,rssi,hop,message_from_id): location = get_node_location(message_from_id) weather = get_weather(str(location[0]),str(location[1])) bot_response = weather + elif "joke" in message.lower(): + bot_response = tell_joke() else: bot_response = "I'm sorry, I'm afraid I can't do that." @@ -98,6 +104,12 @@ def log_timestamp(): return datetime.now().strftime("%Y-%m-%d %H:%M:%S") def onReceive(packet, interface): + # receive a packet and process it, main instruction loop + + # print the packet for debugging + #print("Packet Received") + #print(packet) # print the packet for debugging + #print("END of packet \n") message_from_id = 0 snr = 0 rssi = 0 @@ -170,6 +182,7 @@ def onReceive(packet, interface): print("END of packet \n") def messageTrap(msg): + #Check if the message contains a trap word message_list=msg.split(" ") for m in message_list: for t in trap_list: @@ -197,6 +210,7 @@ def get_name_from_number(number, type='long'): return name def get_node_list(): + #checks nodeDB on device and returns a list of the last 5 nodes heard node_list = [] if interface.nodes: for node in interface.nodes.values(): @@ -222,6 +236,7 @@ def get_node_list(): return node_list def get_node_location(number): + #Get the location of a node by its number from nodeDB on device latitude = 0 longitude = 0 position = [0,0] @@ -262,5 +277,8 @@ pub.subscribe(onReceive, 'meshtastic.receive') print (f"System: Autoresponder Started for device {get_name_from_number(myNodeNum)}") while True: + # Catch CTL+C to exit signal.signal(signal.SIGINT, exit_handler) pass + +# EOF diff --git a/requirements.txt b/requirements.txt index 124db3c..370a21d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ pyephem requests geopy maidenhead -beautifulsoup4 \ No newline at end of file +beautifulsoup4 +dadjokes