implement support for <randomname> in responses
This commit is contained in:
parent
9eeabd8ae9
commit
4f66fcf958
1 changed files with 14 additions and 5 deletions
|
@ -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
|
||||
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('<username>', username)
|
||||
return response.replace(template, username)
|
||||
return response
|
||||
|
||||
async def respond(self,
|
||||
event: telethon.events.common.EventBuilder) -> None:
|
||||
|
|
Loading…
Reference in a new issue