Add support for reactions with emojis.
This commit is contained in:
parent
3bdf9d03c6
commit
73d9b9184d
@ -292,6 +292,15 @@ class AIResponder(AIResponderBase):
|
||||
response["picture"] = await self.translate(response["picture"])
|
||||
return True
|
||||
|
||||
async def memoize(self, user: str, message: str, answer: str) -> None:
|
||||
self.memory = await self.memory_rewrite(self.memory, user, message, answer)
|
||||
self.update_memory(self.memory)
|
||||
|
||||
async def memoize_reaction(self, message_user: str, reaction_user: str, operation: str, reaction: str, message: str) -> None:
|
||||
quoted_message = message.replace('\n', '\n> ')
|
||||
await self.memoize(reaction_user, f'{message_user}:\n> {quoted_message}',
|
||||
f'User {reaction_user} has {operation} this raction: {reaction}')
|
||||
|
||||
async def send(self, message: AIMessage) -> AIResponse:
|
||||
# Get the history limit from the configuration
|
||||
limit = self.config["history-limit"]
|
||||
@ -343,8 +352,7 @@ class AIResponder(AIResponderBase):
|
||||
|
||||
# Update memory
|
||||
if answer_message.answer is not None:
|
||||
self.memory = await self.memory_rewrite(self.memory, message.user, message.message, answer_message.answer)
|
||||
self.update_memory(self.memory)
|
||||
await self.memoize(message.user, message.message, answer_message.answer)
|
||||
|
||||
# Return the updated answer message
|
||||
return answer_message
|
||||
|
||||
@ -108,6 +108,22 @@ class FjerkroaBot(commands.Bot):
|
||||
return
|
||||
await self.handle_message_through_responder(message)
|
||||
|
||||
async def on_reaction_add(self, reaction, user):
|
||||
if user.bot:
|
||||
return
|
||||
airesponder = self.get_ai_responder(self.get_channel_name(reaction.message.channel))
|
||||
message = str(reaction.message.content) if reaction.message.content else ''
|
||||
if len(message) > 1:
|
||||
await airesponder.memoize_reaction(reaction.message.user.name, user.name, 'adding', str(reaction.emoji), message)
|
||||
|
||||
async def on_reaction_remove(self, reaction, user):
|
||||
if user.bot:
|
||||
return
|
||||
airesponder = self.get_ai_responder(self.get_channel_name(reaction.message.channel))
|
||||
message = str(reaction.message.content) if reaction.message.content else ''
|
||||
if len(message) > 1:
|
||||
await airesponder.memoize_reaction(reaction.message.user.name, user.name, 'removing', str(reaction.emoji), message)
|
||||
|
||||
def on_config_file_modified(self, event):
|
||||
if event.src_path == self.config_file:
|
||||
new_config = self.load_config(self.config_file)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user