Add `.nonickchat` command to HikkaSettings

You can enable NoNick for certain chat in order to avoid userbot spam in not-needed chats
pull/1/head
Hikari 2022-04-15 08:01:58 +00:00
parent a930e85678
commit 22c260492a
No known key found for this signature in database
GPG Key ID: 5FA52ACBB2AD964D
2 changed files with 48 additions and 4 deletions

View File

@ -293,6 +293,7 @@ class CommandDispatcher:
and not self._db.get(main.__name__, "no_nickname", False)
and command not in self._db.get(main.__name__, "nonickcmds", [])
and initiator not in self._db.get(main.__name__, "nonickusers", [])
and utils.get_chat_id(event) not in self._db.get(main.__name__, "nonickchats", [])
):
logging.debug("Ignoring message without nickname")
return False

View File

@ -45,6 +45,7 @@ class HikkaSettingsMod(loader.Module):
"close_menu": "😌 Close menu",
"download_btn": "✅ Download via button",
"no_download_btn": "🚫 Download via button",
"private_not_allowed": "🚫 <b>This command must be executed in chat</b>",
}
def get_watchers(self) -> tuple:
@ -183,7 +184,7 @@ class HikkaSettingsMod(loader.Module):
await utils.answer(message, self.strings("disabled").format(args))
async def nonickusercmd(self, message: Message) -> None:
"""Allow certain command to be executed without nickname"""
"""Allow no nickname for certain user"""
reply = await message.get_reply_message()
u = reply.sender_id
if not isinstance(u, int):
@ -200,6 +201,37 @@ class HikkaSettingsMod(loader.Module):
self._db.set(main.__name__, "nonickusers", nn)
async def nonickchatcmd(self, message: Message) -> None:
"""Allow no nickname in certain chat"""
if message.is_private:
await utils.answer(message, self.strings("private_not_allowed"))
return
chat = utils.get_chat_id(message)
nn = self._db.get(main.__name__, "nonickchats", [])
if chat not in nn:
nn += [chat]
nn = list(set(nn)) # skipcq: PTC-W0018
await utils.answer(
message,
self.strings("cmd_nn").format(
utils.escape_html((await message.get_chat()).title),
"on",
),
)
else:
nn = list(set(nn) - set([chat])) # skipcq: PTC-W0018
await utils.answer(
message,
self.strings("cmd_nn").format(
utils.escape_html((await message.get_chat()).title),
"off",
),
)
self._db.set(main.__name__, "nonickchats", nn)
async def nonickcmdcmd(self, message: Message) -> None:
"""Allow certain command to be executed without nickname"""
args = utils.get_args_raw(message)
@ -234,8 +266,15 @@ class HikkaSettingsMod(loader.Module):
async def inline__setting(self, call: CallbackQuery, key: str, state: bool) -> None:
self._db.set(main.__name__, key, state)
if key == "no_nickname" and state and self._db.get(main.__name__, "command_prefix", ".") == ".":
await call.answer("Warning! You enabled NoNick with default prefix! You may get muted in Hikka chats. Change prefix or disable NoNick!", show_alert=True)
if (
key == "no_nickname"
and state
and self._db.get(main.__name__, "command_prefix", ".") == "."
):
await call.answer(
"Warning! You enabled NoNick with default prefix! You may get muted in Hikka chats. Change prefix or disable NoNick!",
show_alert=True,
)
else:
await call.answer("Configuration value saved!")
@ -420,7 +459,11 @@ class HikkaSettingsMod(loader.Module):
"callback": self.inline__restart,
"args": (True,),
},
{"text": self.strings("btn_update"), "callback": self.inline__update, "args": (True,)},
{
"text": self.strings("btn_update"),
"callback": self.inline__update,
"args": (True,),
},
],
[{"text": self.strings("close_menu"), "callback": self.inline__close}],
]