Add person's name when replying

This commit is contained in:
Tanner Collin 2021-05-17 21:01:38 +00:00
parent 59aa6c56ca
commit 4baa7d3194

View File

@ -20,6 +20,7 @@ logging.info('Bridge initialized')
async def new_message(event):
text = event.raw_text
sender = await event.get_sender()
reply_name = ''
if event.chat.id != settings.CHAT_ID:
logging.info('Wrong chat ID')
@ -29,6 +30,22 @@ async def new_message(event):
logging.info('No text found')
return
if event.message.is_reply:
reply_msg = await event.get_reply_message()
reply_text = reply_msg.text
reply_name = reply_msg.sender.first_name
if reply_name == 'protospace_mc_bot':
match = re.search(r'<(\w+)>.*', reply_text)
if match:
reply_name, = match.groups()
else:
reply_name = ''
if reply_name:
reply_name = settings.CUSTOM_NAMES.get(reply_name, reply_name)
text = reply_name + ': ' + text
name = re.sub(r'\W+', '', sender.first_name)
name = '[TG] ' + settings.CUSTOM_NAMES.get(name, name)