1.1.9: Fix `_generate_markup` (hooks setup), add `switch_inline_query|current_chat` parsers

pull/1/head
Hikari 2022-04-26 13:40:40 +00:00
parent f56a380fc6
commit 8c02fd5b1d
No known key found for this signature in database
GPG Key ID: 5FA52ACBB2AD964D
7 changed files with 29 additions and 14 deletions

View File

@ -114,8 +114,7 @@ class Events(InlineUnit):
thumb_width=128,
thumb_height=128,
reply_markup=self._generate_markup(
res.get("reply_markup", None),
prepare_callbacks=True,
res.get("reply_markup", None)
),
)
]

View File

@ -29,8 +29,6 @@ class Utils(InlineUnit):
def _generate_markup(
self,
form_uid: Union[str, list],
/,
prepare_callbacks: bool = False,
) -> Union[None, InlineKeyboardMarkup]:
"""Generate markup for form or list of `dict`s"""
if not form_uid:
@ -44,6 +42,8 @@ class Utils(InlineUnit):
map_ = self._normalize_markup(map_)
setup_callbacks = False
for row in map_:
for button in row:
if not isinstance(button, dict):
@ -52,6 +52,7 @@ class Utils(InlineUnit):
if "callback" in button and "_callback_data" not in button:
button["_callback_data"] = utils.rand(30)
setup_callbacks = True
if "input" in button and "_switch_query" not in button:
button["_switch_query"] = utils.rand(10)
@ -81,7 +82,7 @@ class Utils(InlineUnit):
callback_data=button["_callback_data"],
)
]
if prepare_callbacks:
if setup_callbacks:
self._custom_map[button["_callback_data"]] = {
"handler": button["callback"],
**(
@ -124,6 +125,20 @@ class Utils(InlineUnit):
callback_data=button["data"],
)
]
elif "switch_inline_query_current_chat" in button:
line += [
InlineKeyboardButton(
button["text"],
switch_inline_query_current_chat=button["switch_inline_query_current_chat"]
)
]
elif "switch_inline_query" in button:
line += [
InlineKeyboardButton(
button["text"],
switch_inline_query_current_chat=button["switch_inline_query"]
)
]
else:
logger.warning(
"Button have not been added to "

View File

@ -816,5 +816,7 @@
"hikka.modules.hikka_info.prefix": "Префикс команд",
"hikka.modules.hikka_info.send_info": "Отправить информацию о юзерботе",
"hikka.modules.hikka_info.description": " Это не раскроет никакой личной информации",
"hikka.modules.hikka_info._ihandle_doc_info": "Отправить информацию о юзерботе"
"hikka.modules.hikka_info._ihandle_doc_info": "Отправить информацию о юзерботе",
"hikka.modules.hikka_info.up-to-date": "✅ Актуальная версия",
"hikka.modules.hikka_info.update_required": "⚠️ Требуется обновление </b><code>.update</code><b>"
}

View File

@ -14,7 +14,6 @@
from .. import loader
import logging
import asyncio
from .._types import LoadError
import json
import re
import websockets
@ -119,7 +118,7 @@ class HikkaDLMod(loader.Module):
await r.delete()
if not token.startswith("kirito_") and not token.startswith("asuna_"):
raise LoadError("Can't get token")
raise loader.LoadError("Can't get token")
self.set("token", token)

View File

@ -33,6 +33,8 @@ class HikkaInfoMod(loader.Module):
"prefix": "Command prefix",
"send_info": "Send userbot info",
"description": " This will not compromise any sensitive info",
"up-to-date": "✅ Up-to-date",
"update_required": "⚠️ Update required </b><code>.update</code><b>",
}
async def client_ready(self, client, db):
@ -48,9 +50,9 @@ class HikkaInfoMod(loader.Module):
repo = git.Repo()
diff = repo.git.log(["HEAD..origin/master", "--oneline"])
upd = (
"⚠️ Update required </b><code>.update</code><b>"
self.strings("update_required")
if diff
else "✅ Up-to-date"
else self.strings("up-to-date")
)
except Exception:
upd = ""

View File

@ -19,8 +19,6 @@ import logging
import git
from typing import Union
from .._types import LoadError
logger = logging.getLogger(__name__)
@ -77,7 +75,7 @@ class UpdateNotifierMod(loader.Module):
try:
git.Repo()
except Exception as e:
raise LoadError("Can't load due to repo init error") from e
raise loader.LoadError("Can't load due to repo init error") from e
self._markup = self.inline._generate_markup(
[

View File

@ -1 +1 @@
__version__ = (1, 1, 8)
__version__ = (1, 1, 9)