Skip to content

Commit

Permalink
Wrong command filter
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaGusev committed Jul 8, 2024
1 parent 949750e commit 942ea34
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import traceback
import base64
import io
import re
from email.utils import parseaddr
from typing import cast, List, Dict, Any, Optional, Union, Callable, Coroutine, Tuple, BinaryIO

Expand Down Expand Up @@ -149,7 +150,7 @@ def __init__(
]
for command, func in commands:
self.dp.message.register(func, Command(command))
self.dp.message.register(self.wrong_command, lambda m: m.text and m.text.startswith("/"))
self.dp.message.register(self.wrong_command, Command(re.compile(r"\S+")))
self.dp.message.register(
self.successful_payment_handler, lambda m: m.content_type == ContentType.SUCCESSFUL_PAYMENT
)
Expand Down Expand Up @@ -204,7 +205,11 @@ async def start(self, message: Message) -> None:
await message.reply(content, parse_mode=ParseMode.MARKDOWN)

async def wrong_command(self, message: Message) -> None:
await message.reply(self.localization.WRONG_COMMAND)
chat_id = message.chat.id
assert message.from_user
is_chat = chat_id != message.from_user.id
if not is_chat:
await message.reply(self.localization.WRONG_COMMAND)

#
# History management
Expand Down

0 comments on commit 942ea34

Please sign in to comment.