awaitctx.respond("You do not have the permission to do that!",ephemeral=True)
#create a command called "setkey"
@bot.command()
asyncdefsetkey(ctx,key):
# Check if the bot has the "Manage Channels" permission
ifctx.author.guild_permissions.manage_channels:
# Check if the channel is already set
c.execute("SELECT channel_id FROM data WHERE guild_id = ?",(ctx.guild.id,))
ifc.fetchone()isnotNone:
# Insert the api key into the database
c.execute("UPDATE data SET api_key = ? WHERE guild_id = ?",(key,ctx.guild.id))
conn.commit()
awaitctx.respond("Key set!",ephemeral=True)
else:
awaitctx.respond("Channel not set!",ephemeral=True)
else:
awaitctx.respond("You do not have the permission to do that!",ephemeral=True)
#create a command called "enable"
@bot.command()
asyncdefenable(ctx):
# Check if the bot has the "Manage Channels" permission
ifctx.author.guild_permissions.manage_channels:
# Check if the channel is already set
c.execute("SELECT channel_id FROM data WHERE guild_id = ?",(ctx.guild.id,))
ifc.fetchone()isnotNone:
# Check if the api key is already set
c.execute("SELECT api_key FROM data WHERE guild_id = ?",(ctx.guild.id,))
ifc.fetchone()isnotNone:
# Set is_active to True
c.execute("UPDATE data SET is_active = ? WHERE guild_id = ?",(True,ctx.guild.id))
conn.commit()
awaitctx.respond("Enabled!",ephemeral=True)
else:
awaitctx.respond("Key not set!",ephemeral=True)
else:
awaitctx.respond("Channel not set!",ephemeral=True)
else:
awaitctx.respond("You do not have the permission to do that!",ephemeral=True)
#create a command called "disable"
@bot.command()
asyncdefdisable(ctx):
# Check if the bot has the "Manage Channels" permission
ifctx.author.guild_permissions.manage_channels:
# Check if the channel is already set
c.execute("SELECT channel_id FROM data WHERE guild_id = ?",(ctx.guild.id,))
ifc.fetchone()isnotNone:
# Check if the api key is already set
c.execute("SELECT api_key FROM data WHERE guild_id = ?",(ctx.guild.id,))
ifc.fetchone()isnotNone:
# Set is_active to false
c.execute("UPDATE data SET is_active = ? WHERE guild_id = ?",(False,ctx.guild.id))
conn.commit()
awaitctx.respond("Disabled!",ephemeral=True)
else:
awaitctx.respond("Key not set!",ephemeral=True)
else:
awaitctx.respond("Channel not set!",ephemeral=True)
else:
awaitctx.respond("You do not have the permission to do that!",ephemeral=True)
#create a command called "delete" to delete the channel and api key from the database
@bot.command()
asyncdefdelete(ctx):
# Check if the bot has the "Manage Channels" permission
ifctx.author.guild_permissions.manage_channels:
# Check if the channel is already set
c.execute("SELECT channel_id FROM data WHERE guild_id = ?",(ctx.guild.id,))
ifc.fetchone()isnotNone:
# Delete the channel and api key from the database
c.execute("DELETE FROM data WHERE guild_id = ?",(ctx.guild.id,))
conn.commit()
awaitctx.respond("Deleted!",ephemeral=True)
else:
awaitctx.respond("Channel not set!",ephemeral=True)
else:
awaitctx.respond("You do not have the permission to do that!",ephemeral=True)
#create a command called "info" to get the channel and api key from the database
@bot.command()
asyncdefinfo(ctx):
# Check if the bot has the "administrator" permission
ifctx.author.guild_permissions.administrator:
# Check if the channel is already set
c.execute("SELECT channel_id FROM data WHERE guild_id = ?",(ctx.guild.id,))
ifc.fetchone()isnotNone:
# Get the channel and api key from the database
c.execute("SELECT channel_id, api_key FROM data WHERE guild_id = ?",(ctx.guild.id,))
channel_id,api_key=c.fetchone()
awaitctx.respond(f"Channel: {channel_id}, api key: {api_key}",ephemeral=True)
else:
awaitctx.respond("Channel not set!",ephemeral=True)
else:
awaitctx.respond("You do not have the permission to do that!",ephemeral=True)
# when a message is sent in a channel, check if the channel is in the database for the guild, and if it is, and if it is not, check if the channel is active, and if it is, check if the user is a bot, and if it is not, send the message to openai with the 5 last messages from the channel as the prompt
@bot.event
asyncdefon_message(message):
debug(message)
# Check if the channel is in the database for the guild and if the message has been sent in that channel
c.execute("SELECT channel_id FROM data WHERE guild_id = ?",(message.guild.id,))
# Create the prompt with the 5 last messages and the message sent by the user goint at the line after each message, adding HUMAN: before the messages taht were not sent by the bot and AI: before the messages that were sent by the bot
prompt=""
forminmessages:
#add at the beginning of the prompt and not at the end to have the messages in the right order