diff --git a/pgbotlib/response.py b/pgbotlib/response.py index 9e25b23..f62d373 100644 --- a/pgbotlib/response.py +++ b/pgbotlib/response.py @@ -1,3 +1,4 @@ +import random import re import telethon @@ -91,11 +92,19 @@ class Responder: async def username(self, response: str, event: telethon.events.common.EventBuilder) -> str: - if '' not in response: - return response - sender = await event.get_sender() - username = self.namegen.get_name(sender) - return response.replace('', username) + template = None + match response: + case response if '' in response: + template = '' + sender = await event.get_sender() + case response if '' in response: + template = '' + users = await self.client.get_participants(entity=peer_id) + sender = random.choice(users)[0] + if template: + username = self.namegen.get_name(sender) + return response.replace(template, username) + return response async def respond(self, event: telethon.events.common.EventBuilder) -> None: