Fix inline, migrate to new close handlers

pull/1/head
hikariatama 2022-06-12 10:20:45 +00:00
parent 8018cc8a35
commit 966ea0979a
7 changed files with 27 additions and 66 deletions

View File

@ -15,7 +15,6 @@ import asyncio
import io
import json
import logging
import random
import time
from telethon.tl.types import Message
@ -108,8 +107,8 @@ class APIRatelimiterMod(loader.Module):
old_call = self._client._call
async def new_call(
sender: "MTProtoSender", # noqa: F821
request: "TLRequest", # noqa: F821
sender: "MTProtoSender", # type: ignore
request: "TLRequest", # type: ignore
ordered: bool = False,
flood_sleep_threshold: int = None,
):
@ -184,27 +183,11 @@ class APIRatelimiterMod(loader.Module):
message=message,
text=self.strings("u_sure"),
reply_markup=[
{"text": "🚫 No", "callback": self._cancel},
{"text": "🚫 No", "action": "close"},
{"text": "✅ Yes", "callback": self._finish},
],
)
async def _cancel(self, call: InlineCall):
await call.answer("Goodbye!")
await call.delete()
def _generate_silly_markup(
self,
emoji1: str,
emoji2: str,
callback: callable,
) -> list:
markup = [{"text": emoji1, "callback": self._cancel}] * (8**2 - 1) + [
{"text": emoji2, "callback": callback}
]
random.shuffle(markup)
return utils.chunks(markup, 8)
async def _finish(self, call: InlineCall):
state = self.get("disable_protection", True)
self.set("disable_protection", not state)

View File

@ -86,10 +86,6 @@ class HikkaConfigMod(loader.Module):
self._db = db
self._client = client
@staticmethod
async def inline__close(call: InlineCall):
await call.delete()
@staticmethod
def prep_value(value: Any) -> Any:
if isinstance(value, str):
@ -148,7 +144,7 @@ class HikkaConfigMod(loader.Module):
"callback": self.inline__configure,
"args": (mod,),
},
{"text": self.strings("close_btn"), "callback": self.inline__close},
{"text": self.strings("close_btn"), "action": "close"},
]
],
inline_message_id=inline_message_id,
@ -175,7 +171,7 @@ class HikkaConfigMod(loader.Module):
"callback": self.inline__configure,
"args": (mod,),
},
{"text": self.strings("close_btn"), "callback": self.inline__close},
{"text": self.strings("close_btn"), "action": "close"},
]
],
)
@ -267,7 +263,7 @@ class HikkaConfigMod(loader.Module):
"callback": self.inline__configure,
"args": (mod,),
},
{"text": self.strings("close_btn"), "callback": self.inline__close},
{"text": self.strings("close_btn"), "action": "close"},
],
]
@ -320,7 +316,7 @@ class HikkaConfigMod(loader.Module):
"callback": self.inline__configure,
"args": (mod,),
},
{"text": self.strings("close_btn"), "callback": self.inline__close},
{"text": self.strings("close_btn"), "action": "close"},
]
],
inline_message_id=inline_message_id,
@ -390,7 +386,7 @@ class HikkaConfigMod(loader.Module):
"callback": self.inline__configure,
"args": (mod,),
},
{"text": self.strings("close_btn"), "callback": self.inline__close},
{"text": self.strings("close_btn"), "action": "close"},
]
],
inline_message_id=inline_message_id,
@ -446,7 +442,7 @@ class HikkaConfigMod(loader.Module):
"callback": self.inline__configure,
"args": (mod,),
},
{"text": self.strings("close_btn"), "callback": self.inline__close},
{"text": self.strings("close_btn"), "action": "close"},
],
]
@ -558,7 +554,7 @@ class HikkaConfigMod(loader.Module):
"callback": self.inline__configure,
"args": (mod,),
},
{"text": self.strings("close_btn"), "callback": self.inline__close},
{"text": self.strings("close_btn"), "action": "close"},
],
],
)
@ -592,7 +588,7 @@ class HikkaConfigMod(loader.Module):
"text": self.strings("back_btn"),
"callback": self.inline__global_config,
},
{"text": self.strings("close_btn"), "callback": self.inline__close},
{"text": self.strings("close_btn"), "action": "close"},
]
],
)
@ -614,7 +610,7 @@ class HikkaConfigMod(loader.Module):
]
kb += [row]
kb += [[{"text": self.strings("close_btn"), "callback": self.inline__close}]]
kb += [[{"text": self.strings("close_btn"), "action": "close"}]]
if isinstance(call, Message):
await self.inline.form(

View File

@ -218,10 +218,6 @@ class HikkaSecurityMod(loader.Module):
reply_markup=self._build_markup_global(is_inline),
)
@staticmethod
async def inline_close(call: InlineCall):
await call.delete()
def _build_markup(
self,
command: FunctionType,
@ -248,7 +244,7 @@ class HikkaSecurityMod(loader.Module):
[
{
"text": self.strings("close_menu"),
"callback": self.inline_close,
"action": "close",
}
]
]
@ -268,7 +264,7 @@ class HikkaSecurityMod(loader.Module):
for group, level in perms.items()
],
2,
) + [[{"text": self.strings("close_menu"), "callback": self.inline_close}]]
) + [[{"text": self.strings("close_menu"), "action": "close"}]]
def _build_markup_global(self, is_inline: bool = False) -> List[List[dict]]:
perms = self._get_current_bm(is_inline)
@ -282,7 +278,7 @@ class HikkaSecurityMod(loader.Module):
for group, level in perms.items()
],
2,
) + [[{"text": self.strings("close_menu"), "callback": self.inline_close}]]
) + [[{"text": self.strings("close_menu"), "action": "close"}]]
def _get_current_bm(self, is_inline: bool = False) -> dict:
return self._perms_map(
@ -436,7 +432,7 @@ class HikkaSecurityMod(loader.Module):
reply_markup=[
{
"text": self.strings("cancel"),
"callback": self.inline_close,
"action": "close",
},
{
"text": self.strings("confirm"),
@ -468,7 +464,7 @@ class HikkaSecurityMod(loader.Module):
reply_markup=[
{
"text": self.strings("cancel"),
"callback": self.inline_close,
"action": "close",
},
{
"text": self.strings("enable_nonick_btn"),

View File

@ -256,7 +256,7 @@ class HikkaSettingsMod(loader.Module):
*[
{
"text": self.strings(f"deauth_no_{i}"),
"callback": self.inline__close,
"action": "close",
}
for i in range(1, 4)
],
@ -270,7 +270,7 @@ class HikkaSettingsMod(loader.Module):
[
{
"text": self.strings("deauth_cancel"),
"callback": self.inline__close,
"action": "close",
}
]
],
@ -286,7 +286,7 @@ class HikkaSettingsMod(loader.Module):
"text": self.strings("deauth_confirm_btn"),
"callback": self._uninstall_confirm_step_2,
},
{"text": self.strings("deauth_cancel"), "callback": self.inline__close},
{"text": self.strings("deauth_cancel"), "action": "close"},
],
)
@ -612,9 +612,6 @@ class HikkaSettingsMod(loader.Module):
reply_markup=self._get_settings_markup(),
)
async def inline__close(self, call: InlineCall):
await call.delete()
async def inline__update(
self,
call: InlineCall,
@ -625,7 +622,7 @@ class HikkaSettingsMod(loader.Module):
self.strings("confirm_update"),
reply_markup=[
{"text": "🪂 Update", "callback": self.inline__update},
{"text": "🚫 Cancel", "callback": self.inline__close},
{"text": "🚫 Cancel", "action": "close"},
],
)
return
@ -645,7 +642,7 @@ class HikkaSettingsMod(loader.Module):
self.strings("confirm_restart"),
reply_markup=[
{"text": "🔄 Restart", "callback": self.inline__restart},
{"text": "🚫 Cancel", "callback": self.inline__close},
{"text": "🚫 Cancel", "action": "close"},
],
)
return
@ -792,7 +789,7 @@ class HikkaSettingsMod(loader.Module):
"args": (True,),
},
],
[{"text": self.strings("close_menu"), "callback": self.inline__close}],
[{"text": self.strings("close_menu"), "action": "close"}],
]
@loader.owner

View File

@ -45,10 +45,6 @@ class InlineStuffMod(loader.Module):
async def client_ready(self, client, db):
self._db = db
self._client = client
self._bot_id = (await self.inline.bot.get_me()).id
async def inline__close(self, call: InlineCall):
await call.delete()
async def watcher(self, message: Message):
if (
@ -64,7 +60,7 @@ class InlineStuffMod(loader.Module):
if (
not getattr(message, "out", False)
or not getattr(message, "via_bot_id", False)
or message.via_bot_id != self._bot_id
or message.via_bot_id != self.inline.bot_id
or "Loading Hikka gallery..." not in getattr(message, "raw_text", "")
):
return

View File

@ -78,10 +78,6 @@ class PythonMod(loader.Module):
"""Alias for .e command"""
await self.ecmd(message)
async def inline__close(self, call: InlineCall):
await call.answer("Operation cancelled")
await call.delete()
async def inline__allow(self, call: InlineCall):
await call.answer("Now you can access db through .e command", show_alert=True)
self._db.set(main.__name__, "enable_db_eval", True)
@ -107,7 +103,7 @@ class PythonMod(loader.Module):
"text": "✅ Allow",
"callback": self.inline__allow,
},
{"text": "🚫 Cancel", "callback": self.inline__close},
{"text": "🚫 Cancel", "action": "close"},
]
],
)

View File

@ -137,7 +137,7 @@ class UpdaterMod(loader.Module):
"text": self.strings("btn_restart"),
"callback": self.inline_restart,
},
{"text": self.strings("cancel"), "callback": self.inline_close},
{"text": self.strings("cancel"), "action": "close"},
],
)
):
@ -148,9 +148,6 @@ class UpdaterMod(loader.Module):
async def inline_restart(self, call: InlineCall):
await self.restart_common(call)
async def inline_close(self, call: InlineCall):
await call.delete()
async def process_restart_message(self, msg_obj: Union[InlineCall, Message]):
self.set(
"selfupdatemsg",
@ -281,7 +278,7 @@ class UpdaterMod(loader.Module):
"text": self.strings("btn_update"),
"callback": self.inline_update,
},
{"text": self.strings("cancel"), "callback": self.inline_close},
{"text": self.strings("cancel"), "action": "close"},
],
)
):