implement support for <randomname> in responses

This commit is contained in:
Von Random 2024-11-21 15:23:02 +02:00
parent 9eeabd8ae9
commit 4f66fcf958

View file

@ -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 '<username>' not in response:
return response
sender = await event.get_sender()
username = self.namegen.get_name(sender)
return response.replace('<username>', username)
template = None
match response:
case response if '<username>' in response:
template = '<username>'
sender = await event.get_sender()
case response if '<randomname>' in response:
template = '<randomname>'
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: