diff --git a/mesh_bot.py b/mesh_bot.py index 4468c73..6893670 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -44,7 +44,7 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n "golfsim": lambda: handleGolf(message_from_id, message), "hfcond": hf_band_conditions, "history": lambda: handle_history(message, message_from_id, deviceID, isDM), - "joke": tell_joke, + "joke": lambda: tell_joke(message_from_id), "lemonstand": lambda: handleLemonade(message_from_id, message), "lheard": lambda: handle_lheard(message, message_from_id, deviceID, isDM), "mastermind": lambda: handleMmind(message_from_id, deviceID, message), @@ -1001,7 +1001,7 @@ def onReceive(packet, interface): consumeMetadata(packet, rxNode) except KeyError as e: logger.critical(f"System: Error processing packet: {e} Device:{rxNode}") - logger.debug(f"System: Packet: {packet}") + logger.debug(f"System: Error Packet = {packet}") async def start_rx(): print (CustomFormatter.bold_white + f"\nMeshtastic Autoresponder Bot CTL+C to exit\n" + CustomFormatter.reset) diff --git a/modules/games/joke.py b/modules/games/joke.py new file mode 100644 index 0000000..2c58850 --- /dev/null +++ b/modules/games/joke.py @@ -0,0 +1,51 @@ +from dadjokes import Dadjoke # pip install dadjokes +from modules.log import * + +def sendWithEmoji(message): + # this will take a string of text and replace any word or phrase that is in the word list with the corresponding emoji + wordToEmojiMap = { + 'love': 'โค๏ธ', 'heart': 'โค๏ธ', 'happy': '๐Ÿ˜Š', 'smile': '๐Ÿ˜Š', 'sad': '๐Ÿ˜ข', 'angry': '๐Ÿ˜ ', 'mad': '๐Ÿ˜ ', 'cry': '๐Ÿ˜ข', 'laugh': '๐Ÿ˜‚', 'funny': '๐Ÿ˜‚', 'cool': '๐Ÿ˜Ž', + 'joy': '๐Ÿ˜‚', 'kiss': '๐Ÿ˜˜', 'hug': '๐Ÿค—', 'wink': '๐Ÿ˜‰', 'grin': '๐Ÿ˜', 'bored': '๐Ÿ˜', 'tired': '๐Ÿ˜ด', 'sleepy': '๐Ÿ˜ด', 'shocked': '๐Ÿ˜ฒ', 'surprised': '๐Ÿ˜ฒ', + 'confused': '๐Ÿ˜•', 'thinking': '๐Ÿค”', 'sick': '๐Ÿคข', 'party': '๐ŸŽ‰', 'celebrate': '๐ŸŽ‰', 'clap': '๐Ÿ‘', 'thumbs up': '๐Ÿ‘', 'thumbs down': '๐Ÿ‘Ž', + 'ok': '๐Ÿ‘Œ', 'wave': '๐Ÿ‘‹', 'pray': '๐Ÿ™', 'muscle': '๐Ÿ’ช', 'fire': '๐Ÿ”ฅ', 'star': 'โญ', 'sun': 'โ˜€๏ธ', 'moon': '๐ŸŒ™', 'rain': '๐ŸŒง๏ธ', 'snow': 'โ„๏ธ', 'cloud': 'โ˜๏ธ', + 'dog': '๐Ÿถ', 'cat': '๐Ÿฑ', 'mouse': '๐Ÿญ', 'rabbit': '๐Ÿฐ', 'fox': '๐ŸฆŠ', 'bear': '๐Ÿป', 'panda': '๐Ÿผ', 'koala': '๐Ÿจ', 'tiger': '๐Ÿฏ', 'lion': '๐Ÿฆ', 'cow': '๐Ÿฎ', + 'pig': '๐Ÿท', 'frog': '๐Ÿธ', 'monkey': '๐Ÿต', 'chicken': '๐Ÿ”', 'penguin': '๐Ÿง', 'bird': '๐Ÿฆ', 'fish': '๐ŸŸ', 'whale': '๐Ÿ‹', 'dolphin': '๐Ÿฌ', 'octopus': '๐Ÿ™', + 'apple': '๐ŸŽ', 'orange': '๐ŸŠ', 'banana': '๐ŸŒ', 'watermelon': '๐Ÿ‰', 'grape': '๐Ÿ‡', 'strawberry': '๐Ÿ“', 'cherry': '๐Ÿ’', 'peach': '๐Ÿ‘', 'pineapple': '๐Ÿ', 'mango': '๐Ÿฅญ', 'coconut': '๐Ÿฅฅ', + 'tomato': '๐Ÿ…', 'eggplant': '๐Ÿ†', 'avocado': '๐Ÿฅ‘', 'broccoli': '๐Ÿฅฆ', 'cucumber': '๐Ÿฅ’', 'corn': '๐ŸŒฝ', 'carrot': '๐Ÿฅ•', 'potato': '๐Ÿฅ”', 'sweet potato': '๐Ÿ ', 'chili': '๐ŸŒถ๏ธ', 'garlic': '๐Ÿง„', + 'pizza': '๐Ÿ•', 'burger': '๐Ÿ”', 'fries': '๐ŸŸ', 'hotdog': '๐ŸŒญ', 'popcorn': '๐Ÿฟ', 'donut': '๐Ÿฉ', 'cookie': '๐Ÿช', 'cake': '๐ŸŽ‚', 'pie': '๐Ÿฐ', 'cupcake': '๐Ÿง', 'chocolate': '๐Ÿซ', + 'candy': '๐Ÿฌ', 'lollipop': '๐Ÿญ', 'pudding': '๐Ÿฎ', 'honey': '๐Ÿฏ', 'milk': '๐Ÿผ', 'coffee': 'โ˜•', 'tea': '๐Ÿต', 'sake': '๐Ÿถ', 'beer': '๐Ÿบ', 'cheers': '๐Ÿป', 'champagne': '๐Ÿฅ‚', + 'wine': '๐Ÿท', 'whiskey': '๐Ÿฅƒ', 'cocktail': '๐Ÿธ', 'tropical drink': '๐Ÿน', 'bottle': '๐Ÿพ', 'soda': '๐Ÿฅค', 'chopsticks': '๐Ÿฅข', 'fork': '๐Ÿด', 'knife': '๐Ÿ”ช', 'spoon': '๐Ÿฅ„', 'kitchen knife': '๐Ÿ”ช', + 'house': '๐Ÿ ', 'home': '๐Ÿก', 'office': '๐Ÿข', 'post office': '๐Ÿฃ', 'hospital': '๐Ÿฅ', 'bank': '๐Ÿฆ', 'hotel': '๐Ÿจ', 'love hotel': '๐Ÿฉ', 'convenience store': '๐Ÿช', 'school': '๐Ÿซ', 'department store': '๐Ÿฌ', + 'factory': '๐Ÿญ', 'castle': '๐Ÿฏ', 'palace': '๐Ÿฐ', 'church': '๐Ÿ’’', 'tower': '๐Ÿ—ผ', 'statue of liberty': '๐Ÿ—ฝ', 'mosque': '๐Ÿ•Œ', 'synagogue': '๐Ÿ•', 'hindu temple': '๐Ÿ›•', 'kaaba': '๐Ÿ•‹', 'shinto shrine': 'โ›ฉ๏ธ', + 'railway': '๐Ÿ›ค๏ธ', 'highway': '๐Ÿ›ฃ๏ธ', 'map': '๐Ÿ—พ', 'carousel': '๐ŸŽ ', 'ferris wheel': '๐ŸŽก', 'roller coaster': '๐ŸŽข', 'circus': '๐ŸŽช', 'theater': '๐ŸŽญ', 'art': '๐ŸŽจ', 'slot machine': '๐ŸŽฐ', 'dice': '๐ŸŽฒ', + 'bowling': '๐ŸŽณ', 'video game': '๐ŸŽฎ', 'dart': '๐ŸŽฏ', 'billiard': '๐ŸŽฑ', 'medal': '๐ŸŽ–๏ธ', 'trophy': '๐Ÿ†', 'gold medal': '๐Ÿฅ‡', 'silver medal': '๐Ÿฅˆ', 'bronze medal': '๐Ÿฅ‰', 'soccer': 'โšฝ', 'baseball': 'โšพ', + 'basketball': '๐Ÿ€', 'volleyball': '๐Ÿ', 'football': '๐Ÿˆ', 'rugby': '๐Ÿ‰', 'tennis': '๐ŸŽพ', 'frisbee': '๐Ÿฅ', 'ping pong': '๐Ÿ“', 'badminton': '๐Ÿธ', 'boxing': '๐ŸฅŠ', 'martial arts': '๐Ÿฅ‹', + 'goal': '๐Ÿฅ…', 'golf': 'โ›ณ', 'skating': 'โ›ธ๏ธ', 'fishing': '๐ŸŽฃ', 'diving': '๐Ÿคฟ', 'running': '๐ŸŽฝ', 'skiing': '๐ŸŽฟ', 'sledding': '๐Ÿ›ท', 'curling': '๐ŸฅŒ', 'climbing': '๐Ÿง—', 'yoga': '๐Ÿง˜', + 'surfing': '๐Ÿ„', 'swimming': '๐ŸŠ', 'water polo': '๐Ÿคฝ', 'cycling': '๐Ÿšด', 'mountain biking': '๐Ÿšต', 'horse riding': '๐Ÿ‡', 'kneeling': '๐ŸงŽ', 'weightlifting': '๐Ÿ‹๏ธ', 'gymnastics': '๐Ÿคธ', 'wrestling': '๐Ÿคผ', 'handball': '๐Ÿคพ', + 'juggling': '๐Ÿคน', 'meditation': '๐Ÿง˜', 'sauna': '๐Ÿง–', 'rock climbing': '๐Ÿง—', 'stop': '๐Ÿ›‘' + } + + words = message.split() + i = 0 + while i < len(words): + for phrase in sorted(wordToEmojiMap.keys(), key=len, reverse=True): + phrase_words = phrase.split() + if words[i:i+len(phrase_words)] == phrase_words: + logger.debug(f"System: Replaced the phrase '{phrase}' with '{wordToEmojiMap[phrase]}'") + words[i:i+len(phrase_words)] = [wordToEmojiMap[phrase]] + i += len(phrase_words) - 1 + break + # Check for plural forms + elif words[i:i+len(phrase_words)] == [word + 's' for word in phrase_words]: + logger.debug(f"System: Replaced the plural phrase '{' '.join([word + 's' for word in phrase_words])}' with '{wordToEmojiMap[phrase]}'") + words[i:i+len(phrase_words)] = [wordToEmojiMap[phrase]] + i += len(phrase_words) - 1 + break + i += 1 + return ' '.join(words) + +def tell_joke(nodeID=0): + dadjoke = Dadjoke() + renderedLaugh = sendWithEmoji(dadjoke.joke) + return renderedLaugh + diff --git a/modules/system.py b/modules/system.py index cac8b8b..45e3f2d 100644 --- a/modules/system.py +++ b/modules/system.py @@ -78,10 +78,9 @@ else: bbs_help = False bbs_list_messages = False - # Dad Jokes Configuration if dad_jokes_enabled: - from dadjokes import Dadjoke # pip install dadjokes + from modules.games.joke import * # from the spudgunman/meshing-around repo trap_list = trap_list + ("joke",) help_message = help_message + ", joke" @@ -507,14 +506,6 @@ def send_message(message, ch, nodeid=0, nodeInt=1): interface.sendText(text=message, channelIndex=ch, destinationId=nodeid) return True -def tell_joke(): - # tell a dad joke, does it need an explanationn :) - if dad_jokes_enabled: - dadjoke = Dadjoke() - return dadjoke.joke - else: - return '' - def get_wikipedia_summary(search_term): wikipedia_search = wikipedia.search(search_term, results=3) wikipedia_suggest = wikipedia.suggest(search_term) @@ -732,7 +723,7 @@ def displayNodeTelemetry(nodeID=0, rxNode=0): logger.critical(f"System: Critical Battery Level: {batteryLevel}{emji} on Device: {rxNode}") return dataResponse -positionMetadata = {} +positionMetadata = [{}] def consumeMetadata(packet, rxNode=0): # keep records of recent telemetry data debugMetadata = False @@ -774,15 +765,15 @@ def consumeMetadata(packet, rxNode=0): # get the position data if packet['decoded']['position']['altitude'] is not None: altitude = packet['decoded']['position']['altitude'] - if packet['decoded']['position']['ground_speed'] is not None: - ground_speed = packet['decoded']['position']['groundSpeed'] - if packet['decoded']['position']['precision_bits'] is not None: - precision_bits = packet['decoded']['position']['precisionBits'] + if packet['decoded']['position']['groundSpeed'] is not None: + groundSpeed = packet['decoded']['position']['groundSpeed'] + if packet['decoded']['position']['precisionBits'] is not None: + precisionBits = packet['decoded']['position']['precisionBits'] # put data into positionMetadata and keep it at 5 records if len(positionMetadata) > 5: positionMetadata.pop(0) - positionMetadata.append({'nodeID': nodeID, 'altitude': altitude, 'ground_speed': ground_speed, 'precision_bits': precision_bits}) - + positionMetadata.append({'nodeID': nodeID, 'altitude': altitude, 'groundSpeed': groundSpeed, 'precisionBits': precisionBits}) + print(f"DEBUG POSITION_METADATA: {positionMetadata}\n\n") # WAYPOINT_APP packets if packet_type == 'WAYPOINT_APP':