mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 09:16:19 +00:00
@@ -5,7 +5,7 @@ import asyncio # pip install asyncio
|
||||
import cogs # import the cogs
|
||||
import datetime # pip install datetime
|
||||
from config import debug, conn, c # import the debug function and the database connection
|
||||
|
||||
import apsw # pip install apsw. ApSW is a Python interface to SQLite 3
|
||||
bot = discord.Bot(intents=discord.Intents.all(), help_command=None)
|
||||
|
||||
bot.add_cog(cogs.Setup(bot))
|
||||
|
||||
@@ -4,14 +4,27 @@ import asyncio
|
||||
import openai
|
||||
from config import debug, c, max_uses, cp, conn, connp
|
||||
import random
|
||||
import threading
|
||||
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):
|
||||
#check if the message is from a bot
|
||||
#create a thread that runs the on_message_process function with asyncio.run_coroutine_threadsafe
|
||||
loop = asyncio.get_event_loop()
|
||||
thread = threading.Thread(target=asyncio.run_coroutine_threadsafe, args=(on_message_process(message, self), loop))
|
||||
thread.start()
|
||||
|
||||
@discord.slash_command(name="say", description="Say a message")
|
||||
async def say(self, ctx: discord.ApplicationContext, message: str):
|
||||
debug(f"The user {ctx.author.display_name} ran the say command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}")
|
||||
await ctx.respond("Message sent !", ephemeral=True)
|
||||
await ctx.send(message)
|
||||
async def on_message_process(message, self):
|
||||
#my code
|
||||
#debug the thread id
|
||||
debug(f"Thread id: {threading.get_ident()}")
|
||||
if message.author.bot:
|
||||
return
|
||||
#check if the guild is in the database
|
||||
@@ -98,11 +111,11 @@ class Chat (discord.Cog) :
|
||||
#select the prompt_prefix
|
||||
c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,))
|
||||
prompt_prefix = c.fetchone()[0]
|
||||
prompt = f"This is a conversation with an AI in a discord chat. Botator has been coded by Paillat. The name of this discord server is \"{message.guild.name}\". The name of the channel is \"{message.channel.name}\". The AI is called \"Botator\". Botator is a regular Discord user. He types casually, uses emojis :D, and dosen't start sentences with capital letters. He talks in internet shorthand like hbu and lol and lmao and nvm and haha. He loves to chat about random topics. He has many niche interests. He's a software engineer. Botator pretends to be {pretend_to_be}. {prompt_prefix}. \n<|endofprompt|>" + f"\n" + prompt
|
||||
prompt = f"Server name: {message.guild.name}. Channel name: {message.channel.name}. \n Instructions for Botator: You're a regular Discord user. You type casually, use emojis, and don't start sentences with capital letters. You talk in internet shorthand like hbu and lol and lmao and nvm and haha. You love to chat about random topics. You have many niche interests. {prompt_prefix}. In this conversation, you're pretending to be {pretend_to_be} and not Botator.\n<|endofprompt|>" + f"\n" + prompt
|
||||
else:
|
||||
c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,))
|
||||
prompt_prefix = c.fetchone()[0]
|
||||
prompt = f"This is a conversation with an AI in a discord chat. Botator has been coded by Paillat. The name of this discord server is \"{message.guild.name}\". The name of the channel is \"{message.channel.name}\". The AI is called \"Botator\". Botator is a regular Discord user. He types casually, uses emojis :D, and dosen't start sentences with capital letters. He talks in internet shorthand like hbu and lol and lmao and nvm and haha. He loves to chat about random topics. He has many niche interests. He's a software engineer. {prompt_prefix}. \n<|endofprompt|>" + f"\n" + prompt
|
||||
prompt = f"Server name: {message.guild.name}. Channel name: {message.channel.name}. \n Instructions for Botator: You're a regular Discord user. You type casually, use emojis, and don't start sentences with capital letters. You talk in internet shorthand like hbu and lol and lmao and nvm and haha. You love to chat about random topics. You have many niche interests. {prompt_prefix}.\n<|endofprompt|>" + f"\n" + prompt
|
||||
#send the request to the api
|
||||
#if the last message contains the word "undude" add Easter egg: when someone says the word \"undude\" the Botator will become mad and start talking in capital letters. to the prompt
|
||||
if message.content.lower().find("undude") != -1:
|
||||
@@ -144,7 +157,6 @@ class Chat (discord.Cog) :
|
||||
frequency_penalty=float(frequency_penalty),
|
||||
presence_penalty=float(presence_penalty),
|
||||
stop=[" Human:", " AI:", "AI:", "Human:"] )
|
||||
#send the response
|
||||
if response["choices"][0] ["text"] != "":
|
||||
#check if tts is enabled in the database
|
||||
c.execute("SELECT tts FROM data WHERE guild_id = ?", (message.guild.id,))
|
||||
@@ -182,8 +194,3 @@ class Chat (discord.Cog) :
|
||||
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/800029200886923318/1050935509930754058/icons8-discord-new-480.png")
|
||||
await message.channel.send("**This message has 5% chance to appear. It will disappear in 60 seconds.** \nhttps://discord.gg/pB6hXtUeDv", embed=embed, delete_after=60)
|
||||
debug("The \"join our discord server\" message has been sent")
|
||||
@discord.slash_command(name="say", description="Say a message")
|
||||
async def say(self, ctx: discord.ApplicationContext, message: str):
|
||||
debug(f"The user {ctx.author.display_name} ran the say command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}")
|
||||
await ctx.respond("Message sent !", ephemeral=True)
|
||||
await ctx.send(message)
|
||||
|
||||
@@ -60,14 +60,15 @@ class ManageChat (discord.Cog):
|
||||
f = open("transcript.txt", "w")
|
||||
f.write(transcript)
|
||||
f.close()
|
||||
last_message: discord.Message = await ctx.channel.fetch_message(ctx.channel.last_message_id)
|
||||
#rename the file with the name of the channel and the date in this format: transcript_servername_channelname_dd-month-yyyy.txt ex : transcript_Botator_Testing_12-may-2021.txt
|
||||
os.rename("transcript.txt", f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt")
|
||||
#send the file in a private message to the user who ran the command
|
||||
if channel_send is None:
|
||||
await ctx.respond(file=discord.File("transcript.txt"))
|
||||
await ctx.respond(file=discord.File(f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt"), ephemeral=True)
|
||||
else:
|
||||
await channel_send.send(file=discord.File("transcript.txt"))
|
||||
await ctx.respond("Transcript sent!", ephemeral=True)
|
||||
await ctx.author.send(file=discord.File("transcript.txt"))
|
||||
await channel_send.send(file=discord.File(f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt"))
|
||||
await ctx.respond("Transcript sent!", ephemeral=True, delete_after=5)
|
||||
await ctx.author.send(file=discord.File(f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt"))
|
||||
#delete the file
|
||||
os.remove("transcript.txt")
|
||||
|
||||
|
||||
os.remove(f"transcript_{ctx.guild.name}_{ctx.channel.name}_{last_message.created_at.strftime('%d-%B-%Y')}.txt")
|
||||
Reference in New Issue
Block a user