Files
Botator/code/cogs/chat.py

36 lines
1.5 KiB
Python
Raw Normal View History

2022-12-08 22:21:53 +01:00
import discord
import re
import asyncio
import openai
2022-12-10 23:50:17 +01:00
from config import debug, c, max_uses, cp, conn, connp
2022-12-10 00:28:20 +01:00
import random
2022-12-12 12:54:04 +01:00
import threading
import makeprompt as mp
2022-12-08 22:21:53 +01:00
class Chat (discord.Cog) :
def __init__(self, bot: discord.Bot):
super().__init__()
self.bot = bot
@discord.Cog.listener()
async def on_message(self, message: discord.Message):
await mp.process(self, message)
2022-12-12 12:58:45 +01:00
2022-12-08 22:21:53 +01:00
@discord.slash_command(name="say", description="Say a message")
async def say(self, ctx: discord.ApplicationContext, message: str):
await ctx.respond("Message sent !", ephemeral=True)
2022-12-10 09:36:06 +01:00
await ctx.send(message)
2022-12-16 12:51:46 +01:00
@discord.slash_command(name="redo", description="Redo a message")
async def redo(self, ctx: discord.ApplicationContext):
2022-12-16 15:43:32 +01:00
history = await ctx.channel.history(limit=2).flatten()
message_to_delete = history[0]
message_to_redo = history[1]
if message_to_delete.author.id == self.bot.user.id:
await message_to_delete.delete()
2022-12-16 12:51:46 +01:00
else:
await ctx.respond("The last message wasn't sent by the bot", ephemeral=True)
return
2022-12-16 15:43:32 +01:00
#get the message before the last message, because the new last message is the bot thinking message, so the message before the last message is the message to redo
2022-12-16 12:51:46 +01:00
await ctx.respond("The message to redo was sent by the bot", ephemeral=True)
return
2022-12-19 19:55:25 +01:00
await ctx.respond("Message redone !", ephemeral=True)
await mp.process(self, message_to_redo)