mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-08-09 10:22:54 +02:00
DadJokes Enhanced!
added word2Emoji
This commit is contained in:
+2
-2
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+8
-17
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user