Skip to content

Commit

Permalink
add a simple translator command
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick80835 committed Sep 19, 2020
1 parent 38c233c commit efff817
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ aiohttp
asyncpraw
cchardet
cryptg
googletrans
gtts
hachoir
howdoi
Expand Down
10 changes: 10 additions & 0 deletions ubot/modules/scrapers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pafy
import wikipedia
from googletrans import Translator, constants
from gtts import gTTS
from howdoi import howdoi
from PIL import Image
Expand All @@ -14,6 +15,7 @@

os.environ["HOWDOI_SEARCH_ENGINE"] = "bing"
tts_lang = "EN"
translator = Translator()


@ldr.add("dadjoke", help="Fetches the most funny shit you've ever read.")
Expand Down Expand Up @@ -204,6 +206,14 @@ async def wiki_cmd(event):
await event.edit(text)


@ldr.add("trt", pattern_extra=f"({'|'.join(constants.LANGUAGES.keys())}|)", help="Translates text to the given language code appended to the trt command, defaults to English.")
async def translate(event):
text_arg = await ldr.get_text(event)
lang = event.other_args[0].lower() or "en"
translation = translator.translate(text_arg, dest=lang)
await event.edit(f"Translated from **{constants.LANGUAGES.get(translation.src, 'English').title()}** to **{constants.LANGUAGES.get(translation.dest, 'English').title()}**:\n\n__{translation.text}__")


@ldr.add("corona", help="Fetches Coronavirus stats, takes an optional country name as an argument.")
async def corona(event):
if event.args:
Expand Down

0 comments on commit efff817

Please sign in to comment.