Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit 0534bfa

Browse files
KenHVMr.Miss
authored and
MoveAngel
committed
scrapers: temporary workaround for translate module
Change-Id: Ifefc524bf649c07f97853ec7c2287a09609589c0 Co-authored-by: KenHV <[email protected]> Co-authored-by: Mr.Miss <[email protected]> Signed-off-by: MoveAngel <[email protected]>
1 parent 359798d commit 0534bfa

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ glitch_this
1515
google-api-python-client
1616
google-auth-httplib2
1717
google-auth-oauthlib
18-
googletrans
1918
google_images_download
19+
google_trans_new
2020
gTTS
2121
gTTS-token
2222
hachoir

userbot/modules/scrapers.py

+24-22
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from bs4 import BeautifulSoup
2121
from emoji import get_emoji_regexp
22-
from googletrans import LANGUAGES, Translator
22+
from googletrans import LANGUAGES, google_translator
2323
from gtts import gTTS
2424
from gtts.lang import tts_langs
2525
from requests import get
@@ -442,36 +442,38 @@ async def imdb(e):
442442
await e.edit("Plox enter **Valid movie name** kthx")
443443

444444

445-
@register(outgoing=True, pattern=r"^.trt(?: |$)([\s\S]*)")
445+
@register(outgoing=True, pattern=r"^\.trt(?: |$)([\s\S]*)")
446446
async def translateme(trans):
447447
""" For .trt command, translate the given text using Google Translate. """
448-
translator = Translator()
449-
textx = await trans.get_reply_message()
450-
message = trans.pattern_match.group(1)
451-
if message:
452-
pass
453-
elif textx:
454-
message = textx.text
448+
449+
if trans.is_reply and not trans.pattern_match.group(1):
450+
message = await trans.get_reply_message()
451+
message = str(message.message)
455452
else:
456-
await trans.edit("`Give a text or reply to a message to translate!`")
457-
return
453+
message = str(trans.pattern_match.group(1))
454+
455+
if not message:
456+
return await trans.edit(
457+
"**Give some text or reply to a message to translate!**")
458458

459+
await trans.edit("**Processing...**")
460+
translator = google_translator()
459461
try:
460-
reply_text = translator.translate(deEmojify(message), dest=TRT_LANG)
462+
reply_text = translator.translate(deEmojify(message),
463+
lang_tgt=TRT_LANG)
461464
except ValueError:
462-
await trans.edit("Invalid destination language.")
463-
return
465+
return await trans.edit(
466+
"**Invalid language selected, use **`.lang tts <language code>`**.**"
467+
)
468+
469+
try:
470+
source_lan = translator.detect(deEmojify(message))[1].title()
471+
except:
472+
source_lan = "(Google didn't provide this info)"
464473

465-
source_lan = LANGUAGES[f"{reply_text.src.lower()}"]
466-
transl_lan = LANGUAGES[f"{reply_text.dest.lower()}"]
467-
reply_text = f"From **{source_lan.title()}**\nTo **{transl_lan.title()}:**\n\n{reply_text.text}"
474+
reply_text = f"From: **{source_lan}**\nTo: **{LANGUAGES.get(TRT_LANG).title()}**\n\n{reply_text}"
468475

469476
await trans.edit(reply_text)
470-
if BOTLOG:
471-
await trans.client.send_message(
472-
BOTLOG_CHATID,
473-
f"Translated some {source_lan.title()} stuff to {transl_lan.title()} just now.",
474-
)
475477

476478

477479
@register(pattern=".lang (trt|tts) (.*)", outgoing=True)

0 commit comments

Comments
 (0)