-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
Copy pathautocorrect.py
59 lines (47 loc) · 1.56 KB
/
autocorrect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
from . import get_help
__doc__ = get_help("help_autocorrect")
import string
from . import HNDLR, LOGS, get_string, udB, ultroid_bot, ultroid_cmd # ignore: pylint
try:
from gingerit.gingerit import GingerIt
except ImportError:
LOGS.info("GingerIt not found")
GingerIt = None
from google_trans_new import google_translator
from telethon import events
@ultroid_cmd(pattern="autocorrect", fullsudo=True)
async def acc(e):
if not udB.get_key("AUTOCORRECT"):
udB.set_key("AUTOCORRECT", "True")
ultroid_bot.add_handler(
gramme, events.NewMessage(outgoing=True, func=lambda x: x.text)
)
return await e.eor(get_string("act_1"), time=5)
udB.del_key("AUTOCORRECT")
await e.eor(get_string("act_2"), time=5)
async def gramme(event):
if not udB.get_key("AUTOCORRECT"):
return
t = event.text
if t[0] == HNDLR or t[0].lower() not in string.ascii_lowercase or t.endswith(".."):
return
tt = google_translator().detect(t)
if tt[0] != "en":
return
xx = GingerIt()
x = xx.parse(t)
res = x["result"]
try:
await event.edit(res)
except BaseException:
pass
if GingerIt and udB.get_key("AUTOCORRECT"):
ultroid_bot.add_handler(
gramme, events.NewMessage(outgoing=True, func=lambda x: x.text)
)