Minor bug fixes. Base for okteto pinger support

pull/1/head
hikari.ftg 2022-03-27 12:40:52 +00:00
parent 114fc76b6d
commit bf80acb0d1
10 changed files with 94 additions and 26 deletions

View File

@ -56,7 +56,7 @@ from .translations.core import Translator
from math import ceil
__version__ = (1, 0, 2)
__version__ = (1, 0, 3)
try:
from .web import core
except ImportError:

View File

@ -85,8 +85,7 @@ class CoreMod(loader.Module):
await utils.answer(message, self.strings("hikka").format(*ver))
async def blacklistcmd(self, message: Message) -> None:
""".blacklist [id]
Blacklist the bot from operating somewhere"""
"""Blacklist the bot from operating somewhere"""
chatid = await self.blacklistcommon(message)
self._db.set(
@ -98,8 +97,7 @@ class CoreMod(loader.Module):
await utils.answer(message, self.strings("blacklisted", message).format(chatid))
async def unblacklistcmd(self, message: Message) -> None:
""".unblacklist [id]
Unblacklist the bot from operating somewhere"""
"""Unblacklist the bot from operating somewhere"""
chatid = await self.blacklistcommon(message)
self._db.set(
@ -130,8 +128,7 @@ class CoreMod(loader.Module):
return
async def blacklistusercmd(self, message: Message) -> None:
""".blacklistuser [id]
Prevent this user from running any commands"""
"""Prevent this user from running any commands"""
user = await self.getuser(message)
self._db.set(
@ -145,8 +142,7 @@ class CoreMod(loader.Module):
)
async def unblacklistusercmd(self, message: Message) -> None:
""".unblacklistuser [id]
Allow this user to run permitted commands"""
"""Allow this user to run permitted commands"""
user = await self.getuser(message)
self._db.set(
@ -280,8 +276,6 @@ class CoreMod(loader.Module):
async def setlangcmd(self, message: Message) -> None:
"""Change the preferred language used for translations
Specify the language as space separated list of ISO 639-1 language codes in order of preference (e.g. fr en)
With no parameters, all translations are disabled
Restart required after use"""
langs = utils.get_args(message)
self._db.set(main.__name__, "language", langs)

View File

@ -64,7 +64,7 @@ class HelpMod(loader.Module):
*Split modules by spaces"""
modules = utils.get_args(message)
if not modules:
await utils.answer(message, self.strings("no_mod"))
await utils.answer(message, self.strings("no_mod", message))
return
mods = [
@ -88,7 +88,7 @@ class HelpMod(loader.Module):
await utils.answer(
message,
self.strings("hidden_shown").format(
self.strings("hidden_shown", message).format(
len(hidden),
len(shown),
"\n".join([f"👁‍🗨 <i>{m}</i>" for m in hidden]),
@ -121,7 +121,7 @@ class HelpMod(loader.Module):
if args in self.allmodules.commands:
module = self.allmodules.commands[args].__self__
else:
await utils.answer(message, self.strings("bad_module").format(args))
await utils.answer(message, self.strings("bad_module", message).format(args))
return
try:
@ -129,7 +129,7 @@ class HelpMod(loader.Module):
except KeyError:
name = getattr(module, "name", "ERROR")
reply = self.strings("single_mod_header").format(utils.escape_html(name))
reply = self.strings("single_mod_header", message).format(utils.escape_html(name))
if module.__doc__:
reply += (
"<i>\n " + utils.escape_html(inspect.getdoc(module)) + "\n</i>"
@ -161,11 +161,11 @@ class HelpMod(loader.Module):
reply += self.strings("undoc_ihandler", message)
for name, fun in commands.items():
reply += self.strings("single_cmd").format(prefix, name)
reply += self.strings("single_cmd", message).format(prefix, name)
if fun.__doc__:
reply += utils.escape_html(inspect.getdoc(fun))
else:
reply += self.strings("undoc_cmd")
reply += self.strings("undoc_cmd", message)
await utils.answer(message, reply)
return
@ -187,7 +187,7 @@ class HelpMod(loader.Module):
hidden = list(filter(lambda module: module in mods, self.get("hide", [])))
self.set("hide", hidden)
reply = self.strings("all_header").format(count, len(hidden) if not force else 0)
reply = self.strings("all_header", message).format(count, len(hidden) if not force else 0)
shown_warn = False
plain_ = []
@ -231,7 +231,7 @@ class HelpMod(loader.Module):
else:
emoji = self.config['plain_emoji']
tmp += self.strings("mod_tmpl").format(emoji, name)
tmp += self.strings("mod_tmpl", message).format(emoji, name)
first = True
@ -243,10 +243,10 @@ class HelpMod(loader.Module):
for cmd in commands:
if first:
tmp += self.strings("first_cmd_tmpl").format(cmd)
tmp += self.strings("first_cmd_tmpl", message).format(cmd)
first = False
else:
tmp += self.strings("cmd_tmpl").format(cmd)
tmp += self.strings("cmd_tmpl", message).format(cmd)
icommands = [
name
@ -256,10 +256,10 @@ class HelpMod(loader.Module):
for cmd in icommands:
if first:
tmp += self.strings("first_cmd_tmpl").format(f"🎹 {cmd}")
tmp += self.strings("first_cmd_tmpl", message).format(f"🎹 {cmd}")
first = False
else:
tmp += self.strings("cmd_tmpl").format(f"🎹 {cmd}")
tmp += self.strings("cmd_tmpl", message).format(f"🎹 {cmd}")
if commands or icommands:
tmp += " )"

View File

@ -192,6 +192,7 @@ class HikkaSettingsMod(loader.Module):
self._db.set(main.__name__, "nonickusers", nn)
async def nonickcmdcmd(self, message: Message) -> None:
"""Allow certain command to be executed without nickname"""
args = utils.get_args_raw(message)
if not args:
return await utils.answer(message, self.strings("no_cmd"))

View File

@ -207,8 +207,7 @@ class TestMod(loader.Module):
@loader.owner
async def suspendcmd(self, message: Message) -> None:
""".suspend <time>
Suspends the bot for N seconds"""
"""<time> - Suspends the bot for N seconds"""
try:
time_sleep = float(utils.get_args_raw(message))
await utils.answer(

View File

@ -0,0 +1,49 @@
import os
import re
result = "{\n"
for mod in os.scandir("."):
if not mod.path.endswith(".py") or mod.path.endswith("checker.py"):
continue
with open(mod.path, "r") as f:
code = f.read()
print(mod.path)
try:
strings = re.search("strings = {(.*?) }", code, flags=re.S).group(1)
except AttributeError:
continue
strs = [
(
re.search('"(.*?)": "(.*?)"', line).group(1),
re.search('"(.*?)": "(.*?)"', line).group(2),
)
for line in strings.splitlines()
if re.search('"(.*?)": "(.*?)"', line) is not None
]
for st, tr in strs:
if st == "name":
continue
result += f" \"hikka.modules.{mod.path.split('/')[-1].split('.')[0]}.{st}\": \"{tr}\",\n"
cmds = re.findall(r" +async def ([a-zA-Zа-яА-Я]*?)cmd\(.*?\).*?:.*?\"\"\"(.*?)\"\"\"", code, flags=re.S)
for cmd, doc in cmds:
doc = doc.replace('\n', '\\n')
result += f" \"hikka.modules.{mod.path.split('/')[-1].split('.')[0]}_cmd_doc_{cmd}\": \"{doc}\",\n"
cls_ = re.search(r"@loader\.tds.*?class .*?Mod\(loader\.Module\):.*?\"\"\"(.*?)\"\"\"", code, flags=re.S)
if cls_ is None:
print("BRUH")
continue
result += f" \"hikka.modules.{mod.path.split('/')[-1].split('.')[0]}_cls_doc\": \"{cls_.group(1)}\",\n"
result += "}"
print(result)

View File

@ -54,6 +54,7 @@ class Web:
self.app.router.add_post("/sendTgCode", self.send_tg_code)
self.app.router.add_post("/check_session", self.check_session)
self.app.router.add_post("/web_auth", self.web_auth)
self.app.router.add_post("/okteto", self.okteto)
self.app.router.add_post("/tgCode", self.tg_code)
self.app.router.add_post("/finishLogin", self.finish_login)
self.api_set = asyncio.Event()
@ -132,6 +133,14 @@ class Web:
self.sign_in_clients[phone] = client
return web.Response()
async def okteto(self, request):
if not self._check_session(request):
return web.Response(body="WAIT")
text = await request.text()
main.hikka.okteto_uri = text
return web.Response(body="URI_SAVED")
async def tg_code(self, request):
if not self._check_session(request):
return web.Response(status=401)

View File

@ -170,4 +170,7 @@
</script>
<script src="{{ static("root.js") }}"></script>
<script src="{{ static("blackhole.js") }}"></script>
{% if okteto %}
<script src="{{ static("okteto.js") }}"></script>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,13 @@
function okteto() {
fetch("/okteto", {
method: "POST",
credentials: "include",
body: window.location.href
})
.then(response => response.text())
.then((response) => {
if(response == "WAIT") {
setTimeout(() => {okteto();}, 5000);
}
})
}

View File

@ -14,7 +14,7 @@ function auth(callback) {
fetch("/web_auth", {
method: "POST",
credentials: "include",
timeout: 5000
timeout: 300000
})
.then(response => response.text())
.then((response) => {