diff --git a/pgbotlib/response.py b/pgbotlib/response.py index 901ab48..010cf69 100644 --- a/pgbotlib/response.py +++ b/pgbotlib/response.py @@ -90,22 +90,21 @@ class Responder: api_spec = match.groups() return self.api.call(*api_spec, message) - async def username(self, response: str, + async def template(self, response: str, event: telethon.events.common.EventBuilder) -> str: template = None - match response: - case response if '' in response: - template = '' - sender = await event.get_sender() - case response if '' in response: - template = '' - peer_id = event.message.peer_id - 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 + result = response + if '' in response: + template = '' + sender = await event.get_sender() + result = result.replace(template, username) + if '' in response: + template = '' + peer_id = event.message.peer_id + users = await self.client.get_participants(entity=peer_id) + sender = random.choice(users)[0] + result = result.replace(template, username) + return result async def respond(self, event: telethon.events.common.EventBuilder) -> None: @@ -120,5 +119,5 @@ class Responder: if not response: return None response = self.api_match(response, message) - response = await self.username(response, event) + response = await self.template(response, event) await self.client.send_message(event.message.peer_id, response)