Skip to content

Commit

Permalink
Fix unwanted message logs
Browse files Browse the repository at this point in the history
  • Loading branch information
SyberiaK committed Apr 17, 2024
1 parent 9b5336b commit 986ef42
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bottypes/botclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ async def handle_message(self, message: Message):
return

if message.chat.type != ChatType.PRIVATE:
if message.text.startswith(self.commands_prefix):
text = message.text
if text.startswith(self.commands_prefix) and self.has_a_command(text):
session = await self.register_session(user, message) # early command handling in group chats
await self.log_message(session, message) # since we don't want to store data
return await self.handle_command(session, message) # of every single user of these
return

Expand All @@ -267,17 +267,23 @@ async def handle_message(self, message: Message):
async def handle_command(self, session: UserSession, message: Message):
prompt = message.text

if not self.has_a_command(prompt):
return
if '@' in prompt:
prompt, username = prompt.split('@', 2)
if username != self.me.username:
return
if prompt not in self._commands:
return

func, args, kwargs = self.get_func_by_command(prompt)
await message.reply_chat_action(ChatAction.TYPING)
return await func(self, session, message, *args, **kwargs)

def has_a_command(self, prompt: str):
if '@' in prompt:
prompt, _ = prompt.split('@', 2)

return prompt in self._commands

async def handle_callback(self, callback_query: CallbackQuery):
if callback_query.message.chat.type != ChatType.PRIVATE:
return
Expand Down

0 comments on commit 986ef42

Please sign in to comment.