Browse Source

replace command

master
Hendrik Langer 2 years ago
parent
commit
bd7d775990
  1. 18
      matrix_pygmalion_bot/core.py

18
matrix_pygmalion_bot/core.py

@ -95,7 +95,8 @@ class Callbacks(object):
await self.bot.send_message(self.client, room.room_id, self.bot.greeting) await self.bot.send_message(self.client, room.room_id, self.bot.greeting)
return return
elif event.body.startswith('!!!'): elif event.body.startswith('!!!'):
return if len(self.bot.chat_history) < 3:
return
chat_history_event_id, chat_history_item = self.bot.chat_history.popitem() # current chat_history_event_id, chat_history_item = self.bot.chat_history.popitem() # current
await self.client.room_redact(room.room_id, chat_history_item.event_id, reason="user-request") await self.client.room_redact(room.room_id, chat_history_item.event_id, reason="user-request")
chat_history_event_id, chat_history_item = self.bot.chat_history.popitem() chat_history_event_id, chat_history_item = self.bot.chat_history.popitem()
@ -116,6 +117,21 @@ class Callbacks(object):
message = chat_history_item.message message = chat_history_item.message
translated_message = message translated_message = message
# don't return, we generate a new answer # don't return, we generate a new answer
elif event.body.startswith('!replace'):
if len(self.bot.chat_history) < 3:
return
chat_history_event_id, chat_history_item = self.bot.chat_history.popitem() # current
await self.client.room_redact(room.room_id, chat_history_item.event_id, reason="user-request")
chat_history_event_id, chat_history_item = self.bot.chat_history.popitem()
await self.client.room_redact(room.room_id, chat_history_item.event_id, reason="user-request")
new_answer = event.body.removeprefix('!replace').strip()
new_translated_answer = new_answer
if not (self.bot.translate is None):
new_translated_answer = translate.translate(new_answer, "en", self.bot.translate)
await self.bot.send_message(self.client, room.room_id, new_translated_answer, reply_to=chat_history_item.relates_to_event, original_message=new_answer)
else:
await self.bot.send_message(self.client, room.room_id, new_answer, reply_to=chat_history_item.relates_to_event)
return
# Other commands # Other commands
if re.search("^(?=.*\bsend\b)(?=.*\bpicture\b).*$", message): if re.search("^(?=.*\bsend\b)(?=.*\bpicture\b).*$", message):

Loading…
Cancel
Save