Skip to content
Snippets Groups Projects
Commit bdef8a02 authored by maa's avatar maa
Browse files

Reformatation and first Implementation of .today

parent fc0803d8
No related branches found
No related tags found
No related merge requests found
...@@ -139,8 +139,6 @@ def handle_action(timestamp, source, groupID, message, attachments): ...@@ -139,8 +139,6 @@ def handle_action(timestamp, source, groupID, message, attachments):
groupInfo = group groupInfo = group
break break
try: try:
message = message[1:].strip() message = message[1:].strip()
msg_splitted = message.split(" ") msg_splitted = message.split(" ")
...@@ -161,7 +159,8 @@ def handle_action(timestamp, source, groupID, message, attachments): ...@@ -161,7 +159,8 @@ def handle_action(timestamp, source, groupID, message, attachments):
links(receiver, groupInfo) links(receiver, groupInfo)
elif action in FUN_DICT: elif action in FUN_DICT:
send(FUN_DICT[action], receiver) send(FUN_DICT[action], receiver)
elif (action in ["savequote", "addquote", "createquote"]) and (groupInfo is not None and action in groupInfo["COMMANDS"]): elif (action in ["savequote", "addquote", "createquote"]) and (
groupInfo is not None and action in groupInfo["COMMANDS"]):
save_quote(receiver, " ".join(str(x) for x in msg_splitted[1:]), groupInfo) save_quote(receiver, " ".join(str(x) for x in msg_splitted[1:]), groupInfo)
elif action == "randomquote" and (groupInfo is not None and action in groupInfo["COMMANDS"]): elif action == "randomquote" and (groupInfo is not None and action in groupInfo["COMMANDS"]):
random_quote(receiver, groupInfo) random_quote(receiver, groupInfo)
...@@ -179,13 +178,15 @@ def handle_action(timestamp, source, groupID, message, attachments): ...@@ -179,13 +178,15 @@ def handle_action(timestamp, source, groupID, message, attachments):
request(receiver, " ".join(str(x) for x in msg_splitted[1:])) request(receiver, " ".join(str(x) for x in msg_splitted[1:]))
elif action == "challenge" and (groupInfo is None or action in groupInfo["COMMANDS"]): elif action == "challenge" and (groupInfo is None or action in groupInfo["COMMANDS"]):
get_random_challenge(receiver) get_random_challenge(receiver)
elif action in ["savebirthday", "addbirthday", "createbirthday"] and (groupInfo is not None and action in groupInfo["COMMANDS"]): elif action in ["savebirthday", "addbirthday", "createbirthday"] and (
groupInfo is not None and action in groupInfo["COMMANDS"]):
save_birthday(receiver, " ".join(str(x) for x in msg_splitted[1:]), groupInfo) save_birthday(receiver, " ".join(str(x) for x in msg_splitted[1:]), groupInfo)
elif action == "allbirthdays" and (groupInfo is not None and action in groupInfo["COMMANDS"]): elif action == "allbirthdays" and (groupInfo is not None and action in groupInfo["COMMANDS"]):
get_all_birthdays(receiver, groupInfo) get_all_birthdays(receiver, groupInfo)
elif action == "nextbirthday" and (groupInfo is not None and action in groupInfo["COMMANDS"]): elif action == "nextbirthday" and (groupInfo is not None and action in groupInfo["COMMANDS"]):
get_next_birthday(receiver, groupInfo) get_next_birthday(receiver, groupInfo)
elif action in ["saveevent", "addevent", "createevent"] and (groupInfo is not None and action in groupInfo["COMMANDS"]): elif action in ["saveevent", "addevent", "createevent"] and (
groupInfo is not None and action in groupInfo["COMMANDS"]):
save_event(receiver, " ".join(str(x) for x in msg_splitted[1:]), groupInfo) save_event(receiver, " ".join(str(x) for x in msg_splitted[1:]), groupInfo)
elif action == "allevents" and (groupInfo is not None and action in groupInfo["COMMANDS"]): elif action == "allevents" and (groupInfo is not None and action in groupInfo["COMMANDS"]):
get_all_events(receiver, groupInfo) get_all_events(receiver, groupInfo)
...@@ -196,7 +197,8 @@ def handle_action(timestamp, source, groupID, message, attachments): ...@@ -196,7 +197,8 @@ def handle_action(timestamp, source, groupID, message, attachments):
elif action == "deepl" and (groupInfo is None or action in groupInfo["COMMANDS"]): elif action == "deepl" and (groupInfo is None or action in groupInfo["COMMANDS"]):
get_deepl_translation(receiver, " ".join(str(x) for x in msg_splitted[1:])) get_deepl_translation(receiver, " ".join(str(x) for x in msg_splitted[1:]))
else: else:
unknown_command(receiver, message) # wenn nicht berechtigt, dann "ich seh nix, ich weiss nix, ich hör nix" => unbekannter befehl unknown_command(receiver,
message) # wenn nicht berechtigt, dann "ich seh nix, ich weiss nix, ich hör nix" => unbekannter befehl
except Exception as ex: except Exception as ex:
log.critical(f'Unknown error:"{ex}", timestamp="{timestamp}", source="{source}", groupID="{groupID}", ' log.critical(f'Unknown error:"{ex}", timestamp="{timestamp}", source="{source}", groupID="{groupID}", '
f'message="{message}", attachments="{attachments}"') f'message="{message}", attachments="{attachments}"')
...@@ -223,7 +225,8 @@ def send_a(message, receiver, attachment): ...@@ -223,7 +225,8 @@ def send_a(message, receiver, attachment):
elif type(receiver) is list: elif type(receiver) is list:
signal.sendGroupMessage(message, [attachment], receiver) signal.sendGroupMessage(message, [attachment], receiver)
except Exception as ex: except Exception as ex:
log.error(f'Send Message with attachment Exception:"{ex}"", message="{message}", receiver="{receiver}", attachments="{attachment}"') log.error(
f'Send Message with attachment Exception:"{ex}"", message="{message}", receiver="{receiver}", attachments="{attachment}"')
def help_func(receiver, message, groupInfo): def help_func(receiver, message, groupInfo):
...@@ -246,6 +249,7 @@ def remus_feinste(receiver): ...@@ -246,6 +249,7 @@ def remus_feinste(receiver):
"Originalrezept von Onkel Remus\n" "Originalrezept von Onkel Remus\n"
send(message, receiver) send(message, receiver)
def true_american(receiver): def true_american(receiver):
message = "True American Regeln: So funktioniert das Spiel aus New Girl\n\n" \ message = "True American Regeln: So funktioniert das Spiel aus New Girl\n\n" \
"- Sie nun folgende Utensilien: Mindestens zwei weitere Mitspieler, drei Dosen Bier pro Spieler, eine Flasche Schnaps, einen Mülleimer, sowie einen Raum mit Möbeln und einem großen Tisch, den Sie am nächsten Tag mit Sicherheit putzen müssen. \n\n" \ "- Sie nun folgende Utensilien: Mindestens zwei weitere Mitspieler, drei Dosen Bier pro Spieler, eine Flasche Schnaps, einen Mülleimer, sowie einen Raum mit Möbeln und einem großen Tisch, den Sie am nächsten Tag mit Sicherheit putzen müssen. \n\n" \
...@@ -292,7 +296,6 @@ def links(receiver, groupInfo): ...@@ -292,7 +296,6 @@ def links(receiver, groupInfo):
if groupInfo is not None and "LINKS" in groupInfo: if groupInfo is not None and "LINKS" in groupInfo:
links = groupInfo["LINKS"] links = groupInfo["LINKS"]
if len(links) == 0: if len(links) == 0:
message = "Keine Links hinterlegt!" message = "Keine Links hinterlegt!"
else: else:
...@@ -436,6 +439,7 @@ def unknown_command(receiver, message): ...@@ -436,6 +439,7 @@ def unknown_command(receiver, message):
def get_tex_formula(receiver, message): def get_tex_formula(receiver, message):
send_a(message, receiver, tex.create_formula(message)) send_a(message, receiver, tex.create_formula(message))
def get_deepl_translation(receiver, message): def get_deepl_translation(receiver, message):
if translator is None: if translator is None:
send("There is no translator available!", receiver) send("There is no translator available!", receiver)
...@@ -459,6 +463,7 @@ def get_deepl_translation(receiver, message): ...@@ -459,6 +463,7 @@ def get_deepl_translation(receiver, message):
send(answer, receiver) send(answer, receiver)
def on_mqtt_message(client, userdata, msg): def on_mqtt_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload)) print(msg.topic + " " + str(msg.payload))
send(msg.topic + " " + str(msg.payload), CONFIG['Admins']['Fred']) send(msg.topic + " " + str(msg.payload), CONFIG['Admins']['Fred'])
...@@ -497,6 +502,7 @@ def gg_remind_schichten(): ...@@ -497,6 +502,7 @@ def gg_remind_schichten():
send(f'Bitte tragt euch in die Planung ein:\n {group["LINKS"]["Planung"]}', group["ID"]) send(f'Bitte tragt euch in die Planung ein:\n {group["LINKS"]["Planung"]}', group["ID"])
break break
def gg_remind_stundenzettel(): def gg_remind_stundenzettel():
today = date.today().day today = date.today().day
gg_group = None gg_group = None
...@@ -510,6 +516,7 @@ def gg_remind_stundenzettel(): ...@@ -510,6 +516,7 @@ def gg_remind_stundenzettel():
elif today == 30: elif today == 30:
send("too late suckaaa", gg_group["ID"]) send("too late suckaaa", gg_group["ID"])
def start_schedule(): def start_schedule():
while True: while True:
schedule.run_pending() schedule.run_pending()
...@@ -548,5 +555,4 @@ if __name__ == "__main__": ...@@ -548,5 +555,4 @@ if __name__ == "__main__":
schedule_thread.start() schedule_thread.start()
print("schedule_thread started") print("schedule_thread started")
loop.run() loop.run()
import requests # Apache 2.0
import numpy as np
callbacktable = {"myFunc": "hello_world"} callbacktable = {"myFunc": "hello_world"}
def hello_world(): def hello_world():
print('Hello World!') print('Hello World!')
if __name__ == '__main__': if __name__ == '__main__':
globals()[callbacktable["myFunc"]]() globals()[callbacktable["myFunc"]]()
response = requests.get(f"https://history.muffinlabs.com/date", headers={"Accept": "application/json"})
result = response.json()
print('Done')
facts = np.random.choice(result['data']['Events'], 5)
print('5 Random History Facts about today:')
for fact in facts:
print(f'In {fact["year"]}: {fact["text"]}')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment