Compare commits
4 commits
85d0fa4335
...
6a27b369af
Author | SHA1 | Date | |
---|---|---|---|
6a27b369af | |||
1713a5180d | |||
3beb10075f | |||
c239dcf489 |
2 changed files with 17 additions and 5 deletions
|
@ -17,6 +17,7 @@
|
|||
- !shrug: Add `¯\_(ツ)_/¯` to the end of your message
|
||||
- !emoji_size: Set the default size for custom emojis
|
||||
- !emoji_list: Get a list of available emojis
|
||||
|
||||
#### Ratelimit
|
||||
Commands activated by users that aren't from the user itself are ratelimited, with a default of 1 command every 10 seconds. Commands activated by the user running the bot are not ratelimited.
|
||||
|
||||
|
@ -32,6 +33,11 @@ By default, some kaomojis are added to `data/textreplace.json`. This json file c
|
|||
- Example config: `{"glasses": "(⌐■_■)"}`
|
||||
- Example usage: `;glasses;` which gets replaced with `(⌐■_■)`
|
||||
|
||||
### Automatic translation
|
||||
If libretranslatepy is installed (the bindings module, not libretranslate itself), reacting to a message with either a US or UK flag will attempt to translate that message to English.
|
||||
- libretranslatepy currently has a small issue, causing it to stop working on self hosted instances. Add `method="GET"` to line 63 in api.py to fix.
|
||||
- If autodetecting languages does not work, react with the flag of the language you want to translate from.
|
||||
|
||||
### Encrypted rooms
|
||||
By default, the bot's session is not verified. Verification is required to view and participate in encrypted rooms. To verify it's session, any other verified client with the "Manually verify by text" feature can be used. Element Android (and possibly iOS) is the only client I have found to support manual verification by choice instead of defaulting to verifying by emoji.
|
||||
|
||||
|
|
16
main.py
16
main.py
|
@ -364,14 +364,20 @@ async def reaction_callback(room: nio.MatrixRoom, event: nio.UnknownEvent, react
|
|||
|
||||
lt = LibreTranslateAPI(settings["libretranslate_api"], settings["libretranslate_api_key"] if "libretranslate_api_key" in settings.keys() and settings["libretranslate_api_key"] else None)
|
||||
# If the language is not supported
|
||||
if from_lang not in [x["code"] for x in lt.languages()] and from_lang != "auto":
|
||||
return await send_text(room.room_id, "Language " + from_lang + " is not supported!")
|
||||
try:
|
||||
if from_lang not in [x["code"] for x in lt.languages()] and from_lang != "auto":
|
||||
return await send_text(room.room_id, "Language " + from_lang + " is not supported!")
|
||||
except Exception:
|
||||
return await send_text(room.room_id, "Something went wrong connecting to the LibreTranslate server!")
|
||||
original_body = reacted_to_event.body
|
||||
# If the message was a reply
|
||||
if reacted_to_event.source.get("content", {}).get("m.relates_to", {}).get("m.in_reply_to", {}).get("event_id"):
|
||||
original_body = "\n\n".join(reacted_to_event.split("\n\n")[1:]) # Remove the in reply to part
|
||||
translated = lt.translate(original_body, from_lang, "en")
|
||||
lang = lt.detect(reacted_to_event.body)[0]["language"].upper() if from_lang == "auto" else from_lang.upper()
|
||||
original_body = "\n\n".join(reacted_to_event.body.split("\n\n")[1:]) # Remove the in reply to part
|
||||
try:
|
||||
translated = lt.translate(original_body, from_lang, "en")
|
||||
except Exception:
|
||||
return await send_text(room.room_id, "Something went wrong translating the message!")
|
||||
lang = lt.detect(original_body)[0]["language"].upper() if from_lang == "auto" else from_lang.upper()
|
||||
return await send_reply(room.room_id, reacted_to_event, "Translated from " + lang + " (" + flag_emoji("US" if lang == "EN" else lang) + "):\n" + translated + "\n")
|
||||
|
||||
async def message_callback(room: nio.MatrixRoom, event: nio.RoomMessageText) -> None:
|
||||
|
|
Loading…
Reference in a new issue