add deletion and prepopulated reacts
This commit is contained in:
12
bot.py
12
bot.py
@@ -45,6 +45,8 @@ async def discord_send(channel, text, name, avatar=DEFAULT_AVATAR):
|
|||||||
else:
|
else:
|
||||||
message = await channel.send(content=chunk)
|
message = await channel.send(content=chunk)
|
||||||
messages.append(message.id)
|
messages.append(message.id)
|
||||||
|
await message.add_reaction("🔁")
|
||||||
|
await message.add_reaction("❌")
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
async def webhook(channel):
|
async def webhook(channel):
|
||||||
@@ -88,6 +90,10 @@ async def on_message(message):
|
|||||||
try:
|
try:
|
||||||
async with channel.typing():
|
async with channel.typing():
|
||||||
response = await conversation.generate(user_message, media)
|
response = await conversation.generate(user_message, media)
|
||||||
|
for old_message_id in conversation.last_messages:
|
||||||
|
old_message = await channel.fetch_message(old_message_id)
|
||||||
|
await old_message.clear_reaction("🔁")
|
||||||
|
await old_message.clear_reaction("❌")
|
||||||
conversation.last_messages = await discord_send(
|
conversation.last_messages = await discord_send(
|
||||||
channel, response, conversation.bot_name,
|
channel, response, conversation.bot_name,
|
||||||
)
|
)
|
||||||
@@ -98,7 +104,7 @@ async def on_message(message):
|
|||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_reaction_add(reaction, user):
|
async def on_reaction_add(reaction, user):
|
||||||
if reaction.emoji != "🔁":
|
if reaction.emoji not in ("🔁", "❌") or user == bot.user:
|
||||||
return
|
return
|
||||||
message = reaction.message
|
message = reaction.message
|
||||||
channel = message.channel
|
channel = message.channel
|
||||||
@@ -120,6 +126,10 @@ async def on_reaction_add(reaction, user):
|
|||||||
await reaction.clear()
|
await reaction.clear()
|
||||||
for message in messages:
|
for message in messages:
|
||||||
await message.delete()
|
await message.delete()
|
||||||
|
|
||||||
|
if reaction.emoji == "❌":
|
||||||
|
conversation.pop()
|
||||||
|
elif reaction.emoji == "🔁":
|
||||||
response = await conversation.regenerate()
|
response = await conversation.regenerate()
|
||||||
conversation.last_messages = await discord_send(
|
conversation.last_messages = await discord_send(
|
||||||
channel, response, conversation.bot_name,
|
channel, response, conversation.bot_name,
|
||||||
|
@@ -68,6 +68,11 @@ class Conversation:
|
|||||||
{"role": "assistant", "content": assistant},
|
{"role": "assistant", "content": assistant},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def pop(self):
|
||||||
|
if len(self.history) >= 3:
|
||||||
|
self.history = self.history[:-2]
|
||||||
|
self.save()
|
||||||
|
|
||||||
async def generate(self, text, media=tuple()):
|
async def generate(self, text, media=tuple()):
|
||||||
# prepare text part
|
# prepare text part
|
||||||
if text:
|
if text:
|
||||||
|
Reference in New Issue
Block a user