mirror of https://github.com/coddrago/Heroku
Update unit_heta.py
parent
fe39763510
commit
2449f2e4e9
|
@ -342,134 +342,6 @@ class UnitHeta(loader.Module):
|
||||||
int(data["dl_id"]),
|
int(data["dl_id"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
@loader.command()
|
|
||||||
async def mlcmd(self, message: Message):
|
|
||||||
if not (args := utils.get_args_raw(message)):
|
|
||||||
await utils.answer(message, self.strings("args"))
|
|
||||||
return
|
|
||||||
|
|
||||||
exact = True
|
|
||||||
if not (
|
|
||||||
class_name := next(
|
|
||||||
(
|
|
||||||
module.strings("name")
|
|
||||||
for module in self.allmodules.modules
|
|
||||||
if args.lower()
|
|
||||||
in {
|
|
||||||
module.strings("name").lower(),
|
|
||||||
module.__class__.__name__.lower(),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
):
|
|
||||||
if not (
|
|
||||||
class_name := next(
|
|
||||||
reversed(
|
|
||||||
sorted(
|
|
||||||
[
|
|
||||||
module.strings["name"].lower()
|
|
||||||
for module in self.allmodules.modules
|
|
||||||
]
|
|
||||||
+ [
|
|
||||||
module.__class__.__name__.lower()
|
|
||||||
for module in self.allmodules.modules
|
|
||||||
],
|
|
||||||
key=lambda x: difflib.SequenceMatcher(
|
|
||||||
None,
|
|
||||||
args.lower(),
|
|
||||||
x,
|
|
||||||
).ratio(),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
):
|
|
||||||
await utils.answer(message, self.strings("404"))
|
|
||||||
return
|
|
||||||
|
|
||||||
exact = False
|
|
||||||
|
|
||||||
try:
|
|
||||||
module = self.lookup(class_name)
|
|
||||||
sys_module = inspect.getmodule(module)
|
|
||||||
except Exception:
|
|
||||||
await utils.answer(message, self.strings("404"))
|
|
||||||
return
|
|
||||||
|
|
||||||
link = module.__origin__
|
|
||||||
|
|
||||||
text = (
|
|
||||||
f"<b>🧳 {utils.escape_html(class_name)}</b>"
|
|
||||||
if not utils.check_url(link)
|
|
||||||
else (
|
|
||||||
f'📼 <b><a href="{link}">Link</a> for'
|
|
||||||
f" {utils.escape_html(class_name)}:</b>"
|
|
||||||
f' <code>{link}</code>\n\n{self.strings("not_exact") if not exact else ""}'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
text = (
|
|
||||||
self.strings("link").format(
|
|
||||||
class_name=utils.escape_html(class_name),
|
|
||||||
url=link,
|
|
||||||
not_exact=self.strings("not_exact") if not exact else "",
|
|
||||||
prefix=utils.escape_html(self.get_prefix()),
|
|
||||||
)
|
|
||||||
if utils.check_url(link)
|
|
||||||
else self.strings("file").format(
|
|
||||||
class_name=utils.escape_html(class_name),
|
|
||||||
not_exact=self.strings("not_exact") if not exact else "",
|
|
||||||
prefix=utils.escape_html(self.get_prefix()),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
file = io.BytesIO(sys_module.__loader__.data)
|
|
||||||
file.name = f"{class_name}.py"
|
|
||||||
file.seek(0)
|
|
||||||
|
|
||||||
await utils.answer_file(
|
|
||||||
message,
|
|
||||||
file,
|
|
||||||
caption=text,
|
|
||||||
)
|
|
||||||
|
|
||||||
def _format_result(
|
|
||||||
self,
|
|
||||||
result: dict,
|
|
||||||
query: str,
|
|
||||||
no_translate: bool = False,
|
|
||||||
) -> str:
|
|
||||||
commands = "\n".join([
|
|
||||||
f"▫️ <code>{utils.escape_html(self.get_prefix())}{utils.escape_html(cmd)}</code>:"
|
|
||||||
f" <b>{utils.escape_html(cmd_doc)}</b>"
|
|
||||||
for cmd, cmd_doc in result["module"]["commands"].items()
|
|
||||||
])
|
|
||||||
|
|
||||||
kwargs = {
|
|
||||||
"name": utils.escape_html(result["module"]["name"]),
|
|
||||||
"dev": utils.escape_html(result["module"]["dev"]),
|
|
||||||
"commands": commands,
|
|
||||||
"cls_doc": utils.escape_html(result["module"]["cls_doc"]),
|
|
||||||
"mhash": result["module"]["hash"],
|
|
||||||
"query": utils.escape_html(query),
|
|
||||||
"prefix": utils.escape_html(self.get_prefix()),
|
|
||||||
}
|
|
||||||
|
|
||||||
strings = (
|
|
||||||
self.strings.get("result", "en")
|
|
||||||
if self.config["translate"] and not no_translate
|
|
||||||
else self.strings("result")
|
|
||||||
)
|
|
||||||
|
|
||||||
text = strings.format(**kwargs)
|
|
||||||
|
|
||||||
if len(text) > 1980:
|
|
||||||
kwargs["commands"] = "..."
|
|
||||||
text = strings.format(**kwargs)
|
|
||||||
|
|
||||||
return text
|
|
||||||
|
|
||||||
@loader.inline_handler(thumb_url="https://img.icons8.com/color/512/hexa.png")
|
@loader.inline_handler(thumb_url="https://img.icons8.com/color/512/hexa.png")
|
||||||
async def heta(self, query: InlineQuery) -> typing.List[dict]:
|
async def heta(self, query: InlineQuery) -> typing.List[dict]:
|
||||||
if not query.args:
|
if not query.args:
|
||||||
|
|
Loading…
Reference in New Issue