Skip to content
Snippets Groups Projects
Commit 382346ac authored by Frederic Aust's avatar Frederic Aust
Browse files

betterhelp erweitert; deepl Api try-catch ergänzt

parent eb90f5e4
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,13 @@ ...@@ -43,6 +43,13 @@
], ],
"Description": "Get a list of all important links for various signal groups and community discords. Password protected. Type .links <password>.", "Description": "Get a list of all important links for various signal groups and community discords. Password protected. Type .links <password>.",
"_Func": "echo" "_Func": "echo"
},
{
"Names": [
".trueamerican"
],
"Description": "True American Rules: How to play the game from New Girl",
"_Func": "echo"
} }
], ],
"APIs": [ "APIs": [
...@@ -60,6 +67,13 @@ ...@@ -60,6 +67,13 @@
], ],
"Description": "Make a really good pun", "Description": "Make a really good pun",
"_Func": "yesno" "_Func": "yesno"
},
{
"Names": [
".deepl"
],
"Description": "Syntax: .deepl <Language>, <String>. Translate a word, sentence or even small texts with DeepL translator. Type: .deepl ES, Where is the library?",
"_Func": "yesno"
} }
], ],
"Crawlers": [ "Crawlers": [
...@@ -178,13 +192,6 @@ ...@@ -178,13 +192,6 @@
], ],
"Description": "Syntax: .request <String>. Do you wish for anything else? Request it!", "Description": "Syntax: .request <String>. Do you wish for anything else? Request it!",
"_Func": "yesno" "_Func": "yesno"
},
{
"Names": [
".deepl"
],
"Description": "Syntax: .deepl <Language>, <String>. Translate a word, sentence or even small texts with DeepL translator. Type: .deepl ES, Where is the library?",
"_Func": "yesno"
} }
] ]
} }
\ No newline at end of file
...@@ -112,6 +112,7 @@ def load_config(filename): ...@@ -112,6 +112,7 @@ def load_config(filename):
if "GROUPS" in CONFIG: if "GROUPS" in CONFIG:
GROUPS = CONFIG["GROUPS"] GROUPS = CONFIG["GROUPS"]
if "DEEPLAPI" in CONFIG: if "DEEPLAPI" in CONFIG:
if CONFIG["DEEPLAPI"] != "API-Key":
translator = deepl.Translator(CONFIG["DEEPLAPI"]) translator = deepl.Translator(CONFIG["DEEPLAPI"])
except FileNotFoundError: except FileNotFoundError:
log.error(f"File:'{filename}' not accessible. Running in reduced mode.") log.error(f"File:'{filename}' not accessible. Running in reduced mode.")
...@@ -436,10 +437,20 @@ def get_tex_formula(receiver, message): ...@@ -436,10 +437,20 @@ 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:
send("There is no translator available!",receiver )
return
splitted = message.strip().split(",") splitted = message.strip().split(",")
lang = splitted[0].upper() lang = splitted[0].upper()
text = ",".join(str(x) for x in splitted[1:]).strip() text = ",".join(str(x) for x in splitted[1:]).strip()
try:
result = translator.translate_text(text, target_lang=lang) result = translator.translate_text(text, target_lang=lang)
except Exception as ex:
send(f'{ex}', receiver)
return
answer = "Computer says no" answer = "Computer says no"
if result : if result :
answer = str(result.detected_source_lang)+"" +str(lang)+"\n" answer = str(result.detected_source_lang)+"" +str(lang)+"\n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment