Skip to content

Commit

Permalink
Prepare custom modules to 4.0 (#63)
Browse files Browse the repository at this point in the history
WARNING: This commit prevent some modules to be installed by user.
If you are developer, you know, what need to be done for loading it.
  • Loading branch information
fuccsoc authored Sep 18, 2023
1 parent f985932 commit 1d3ffa8
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 219 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
2 changes: 1 addition & 1 deletion auto_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from utils.db import db


@Client.on_message(filters.channel & ~filters.edited)
@Client.on_edited_message(filters.channel)
async def send_comment(client: Client, message: Message):
enabled = db.get("custom.auto_comment", "enabled", False)
with suppress(MsgIdInvalid):
Expand Down
17 changes: 0 additions & 17 deletions modules_hashes.txt

This file was deleted.

135 changes: 71 additions & 64 deletions translator.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,79 @@
from utils.scripts import import_library
from utils.misc import modules_help, prefix
from pyrogram import Client, filters
# TODO
# WARNING! IT COMMENTED FULLY SINCE INSTALL PACKAGES FROM THIS MODULE WILL
# BROKE ALL FUCKING DRAGON, NOT JUST THIS MODULE
# THIS MODULE IS INCOMPATIBLE WITH LAST DRAGON VERSION
# SINCE IT USE OUTDATED PACKAGE WITH BROKEN DEPENDENCIES
# IT NEEDS TO BE REWRITED

googletrans = import_library("googletrans", "googletrans==4.0.0rc1")
from googletrans import Translator
# from utils.scripts import import_library
# from utils.misc import modules_help, prefix
# from pyrogram import Client, filters

trl = Translator()
# googletrans = import_library("googletrans", "googletrans==4.0.0rc1")
# from googletrans import Translator

# trl = Translator()

@Client.on_message(filters.command(["tr", "trans"], prefix) & filters.me)
async def translate(_client, message):
await message.edit_text("<b>Translating text...</b>")
if message.reply_to_message and (
message.reply_to_message.text or message.reply_to_message.caption
):
if len(message.text.split()) == 1:
await message.edit(
f"<b>Usage: Reply to a message, then <code>{prefix}tr [lang]*</code></b>"
)
return
target = message.text.split()[1]
if message.reply_to_message.text:
text = message.reply_to_message.text
else:
text = message.reply_to_message.caption
detectlang = trl.detect(text)
try:
tekstr = trl.translate(text, dest=target)
except ValueError as err:
await message.edit("Error: <code>{}</code>".format(str(err)))
return
await message.edit(
"<b>Translated from <code>{}</code> to <code>{}</code></b>:\n\n<code>{}</code>".format(
detectlang.lang, target, tekstr.text
)
)
else:
if len(message.text.split()) <= 2:
await message.edit(f"<b>Usage: <code>{prefix}tr [lang]* [text]*</code></b>")
return
target = message.text.split(None, 2)[1]
text = message.text.split(None, 2)[2]
detectlang = trl.detect(text)
try:
tekstr = trl.translate(text, dest=target)
except ValueError as err:
await message.edit("Error: <code>{}</code>".format(str(err)))
return
await message.edit(
"<b>Translated from <code>{}</code> to <code>{}</code></b>:\n\n<code>{}</code>".format(
detectlang.lang, target, tekstr.text
)
)

# @Client.on_message(filters.command(["tr", "trans"], prefix) & filters.me)
# async def translate(_client, message):
# await message.edit_text("<b>Translating text...</b>")
# if message.reply_to_message and (
# message.reply_to_message.text or message.reply_to_message.caption
# ):
# if len(message.text.split()) == 1:
# await message.edit(
# f"<b>Usage: Reply to a message, then <code>{prefix}tr [lang]*</code></b>"
# )
# return
# target = message.text.split()[1]
# if message.reply_to_message.text:
# text = message.reply_to_message.text
# else:
# text = message.reply_to_message.caption
# detectlang = trl.detect(text)
# try:
# tekstr = trl.translate(text, dest=target)
# except ValueError as err:
# await message.edit("Error: <code>{}</code>".format(str(err)))
# return
# await message.edit(
# "<b>Translated from <code>{}</code> to <code>{}</code></b>:\n\n<code>{}</code>".format(
# detectlang.lang, target, tekstr.text
# )
# )
# else:
# if len(message.text.split()) <= 2:
# await message.edit(f"<b>Usage: <code>{prefix}tr [lang]* [text]*</code></b>")
# return
# target = message.text.split(None, 2)[1]
# text = message.text.split(None, 2)[2]
# detectlang = trl.detect(text)
# try:
# tekstr = trl.translate(text, dest=target)
# except ValueError as err:
# await message.edit("Error: <code>{}</code>".format(str(err)))
# return
# await message.edit(
# "<b>Translated from <code>{}</code> to <code>{}</code></b>:\n\n<code>{}</code>".format(
# detectlang.lang, target, tekstr.text
# )
# )

@Client.on_message(filters.command(["transdl", "trdl"], prefix) & filters.me)
async def translatedl(_client, message):
dtarget = message.text.split(None, 2)[1]
dtext = message.text.split(None, 2)[2]
try:
dtekstr = trl.translate(dtext, dest=dtarget)
except ValueError as err:
await message.edit("Error: <code>{}</code>".format(str(err)))
return
await message.edit("{}".format(dtekstr.text))

# @Client.on_message(filters.command(["transdl", "trdl"], prefix) & filters.me)
# async def translatedl(_client, message):
# dtarget = message.text.split(None, 2)[1]
# dtext = message.text.split(None, 2)[2]
# try:
# dtekstr = trl.translate(dtext, dest=dtarget)
# except ValueError as err:
# await message.edit("Error: <code>{}</code>".format(str(err)))
# return
# await message.edit("{}".format(dtekstr.text))

modules_help["translator"] = {
"tr": "[lang]* [text/reply]* translate message",
"trdl": f"[lang]* [your text]* short variant of {prefix}tr",
}

# modules_help["translator"] = {
# "tr": "[lang]* [text/reply]* translate message",
# "trdl": f"[lang]* [your text]* short variant of {prefix}tr",
# }
Loading

0 comments on commit 1d3ffa8

Please sign in to comment.