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 re
import telethon import telethon
@ -91,11 +92,19 @@ class Responder:
async def username(self, response: str, async def username(self, response: str,
event: telethon.events.common.EventBuilder) -> str: event: telethon.events.common.EventBuilder) -> str:
if '<username>' not in response: template = None
return response match response:
case response if '<username>' in response:
template = '<username>'
sender = await event.get_sender() 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) username = self.namegen.get_name(sender)
return response.replace('<username>', username) return response.replace(template, username)
return response
async def respond(self, async def respond(self,
event: telethon.events.common.EventBuilder) -> None: event: telethon.events.common.EventBuilder) -> None: