-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathhelp.py
More file actions
96 lines (85 loc) · 4.38 KB
/
help.py
File metadata and controls
96 lines (85 loc) · 4.38 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import logging
import inspect
from telethon.tl.functions.channels import JoinChannelRequest
from .. import loader, utils, main, security
logger = logging.getLogger(__name__)
@loader.tds
class HelpMod(loader.Module):
"""Provides this help message"""
strings = {"name": "Help",
"bad_module": '<b>Модуля</b> "<code>{}</code>" <b>нет в базе!</b>',
"single_mod_header": "<b>Информация о</b> <u>{}</u>:\n",
"single_cmd": "\n {}\n",
"undoc_cmd": "Для этой команды нет документации",
"all_header": 'Список из <a href="https://t.me/SomeScripts">{}</a> доступных модулей:\n\n',
"mod_tmpl": '\n‣<a href="tg://user?id={}">{}</a>',
"first_cmd_tmpl": "⋮( {}",
"cmd_tmpl": " | {}",
"SomeScripts": "SomeScripts"}
@loader.unrestricted
async def helpcmd(self, message):
""".help [module]"""
args = utils.get_args_raw(message)
id = message.sender_id
if args:
module = None
for mod in self.allmodules.modules:
if mod.strings("name", message).lower() == args.lower():
module = mod
if module is None:
await utils.answer(message, self.strings("bad_module", message).format(args))
return
# Translate the format specification and the module separately
try:
name = module.strings("name", message)
except KeyError:
name = getattr(module, "name", "ERROR")
reply = self.strings("single_mod_header", message).format(utils.escape_html(name),
utils.escape_html((self.db.get(main.__name__,
"command_prefix",
False) or ".")[0]))
if module.__doc__:
reply += "\n"+"\n".join(" " + t for t in utils.escape_html(inspect.getdoc(module)).split("\n"))
else:
logger.warning("Module %s is missing docstring!", module)
commands = {name: func for name, func in module.commands.items()
if await self.allmodules.check_security(message, func)}
for name, fun in commands.items():
reply += self.strings("single_cmd", message).format(name)
if fun.__doc__:
reply += utils.escape_html("\n".join(" " + t for t in inspect.getdoc(fun).split("\n")))
else:
reply += self.strings("undoc_cmd", message)
else:
count = 0
for i in self.allmodules.modules:
if len(i.commands) != 0:
count += 1
reply = self.strings("all_header", message).format(count)
for mod in self.allmodules.modules:
if len(mod.commands) != 0:
try:
name = mod.strings("name", message)
except KeyError:
name = getattr(mod, "name", "ERROR")
reply += self.strings("mod_tmpl", message).format(id, name)
first = True
commands = [name for name, func in mod.commands.items()
if await self.allmodules.check_security(message, func)]
for cmd in commands:
if first:
reply += self.strings("first_cmd_tmpl", message).format(cmd)
first = False
else:
reply += self.strings("cmd_tmpl", message).format(cmd)
reply += " )"
await utils.answer(message, reply)
@loader.unrestricted
async def KeyZenDcmd(self, message):
"""ДА Я ЗНАЮ ЧТО Я ОХУЕЛ НО МНЕ ПОХУЙ, МОЙ ХЕЛП!"""
await message.delete()
await self.client(JoinChannelRequest(self.strings("SomeScripts", message)))
async def client_ready(self, client, db):
self.client = client
self.is_bot = await client.is_bot()
self.db = db