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 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:
|
||||||
sender = await event.get_sender()
|
case response if '<username>' in response:
|
||||||
username = self.namegen.get_name(sender)
|
template = '<username>'
|
||||||
return response.replace('<username>', 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,
|
async def respond(self,
|
||||||
event: telethon.events.common.EventBuilder) -> None:
|
event: telethon.events.common.EventBuilder) -> None:
|
||||||
|
|
Loading…
Reference in a new issue