Files
Ultroid-fork/plugins/autocorrect.py
Devesh Pal 90ad5646ff Ultroid v0.5 Updates
Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com>
Co-authored-by: Aditya <xditya@ultroid.tech>
Co-authored-by: Kaif <88398455+kaif-00z@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
Co-authored-by: 1Danish-00 <danish@ultroid.tech>
Co-authored-by: smartman_ru <bblkovo@gmail.com>
2022-03-20 00:57:54 +05:30

62 lines
1.6 KiB
Python

# 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/>.
"""
✘ Commands Available
• `{i}autocorrect`
To on/off Autocorrect Feature.
"""
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)
)