Merge pull request #17 from Paillat-dev/main

u
This commit is contained in:
Paillat
2022-12-10 23:22:31 +01:00
committed by GitHub
5 changed files with 55 additions and 21 deletions

View File

@@ -3,7 +3,7 @@ Botator is a discord bot that binds openai's gpt3 AI with discord. You will be a
![discord com_channels_1021872219888033903_1046119234033434734](https://user-images.githubusercontent.com/75439456/204105583-2abb2d77-9404-4558-bd3e-c1a70b939758.png)
# Adding the bot to your discord server
In order to add the bot to your discord server, you will need an OpenAI API key. You can create an account and take one [here](https://beta.openai.com/account/api-keys)
In order to add the bot to your discord server, you will need an OpenAI API key. You can create an account and take one [here](https://beta.openai.com/account/api-keys). **Please note that you'll have 18$ free credits (it's really enough if you don't use the bot contineousely) when creating your account. They will be slowly used, and will expire 3 months after you created your accound, and when they gave all been used, you'll need to buy new tokens. You can check your tokens usage [here](https://beta.openai.com/account/usage).**
You can add the bot to your server by clicking [here](https://discord.com/api/oauth2/authorize?client_id=1046051875755134996&permissions=2214808576&scope=applications.commands%20bot). **PLEASE NOTE THAT WE ARE NOT RESPONSIBLE FOR ANY MISUSE YOU'LL DO WITH THE BOT..**
@@ -42,6 +42,31 @@ You can always disable the bot by doing **/disable** and delete your api key fro
*/help* - Show this command list
# Support me
You can support me by getting Botator premium, or donating [here](https://www.buymeacoffee.com/paillat). More informations about botator premium here below:
### Why?
At the beginning, Botator was just a project between friends, but now many people are using it, so we need something to pay for our servers. Premium is also a way to support us and our work.
### Is this mandatory?
Not at all! You can still continue using botator for free, but in order to limit our servers overload, we limit your requests at 500 per server per day.
### What are my advantages with premium?
With premium, we will increase the maximal number of requests to 5000 for the server of your choice. You will also have access to exclusive Discord channels and get help if you want to self-host Botator. Discord server self promote and "support us" messages will not be shown on this server
### Am I going to have unlimited tokens with premium?
No! With premium, Botator will still use tokens from YOUR OpenAI account, but you will be able to use it 5000 times per day instead of 500.
### How much doe it cost?
Premium subscription costs 1$ per month.
### How can I get premium?
First join our discord server [here](https://discord.gg/pB6hXtUeDv).
Then subscribe to botator premium by clicking here:
<a href="https://www.buymeacoffee.com/paillat"><img src="https://img.buymeacoffee.com/button-api/?text=Get botator premium&emoji=&slug=paillat&button_colour=5F7FFF&font_colour=ffffff&font_family=Inter&outline_colour=000000&coffee_colour=FFDD00" /></a>
Then, link your discord account to BuyMeACoffe by following [these instructions](https://help.buymeacoffee.com/en/articles/4601477-how-do-i-access-my-discord-role).
After that you will normally be able to access some new channels in our discord server. In the Verify Premium channel, run the /premium_activate command and give your server's ID. You can learn about how to get your server's ID by clicking [here](https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-). If you have any question, you can ask here: [help-getting-premium](https://discord.com/channels/1050769643180146749/1050828186159685743).
# ToDo
- [ ] add image recognition
- [ ] When chatgpt API is released, add that api instead of davinci-003

View File

@@ -39,8 +39,8 @@ class Chat (discord.Cog) :
return
#check if the bot hasn't been used more than 5000 times in the last 24 hours (uses_count_today)
c.execute("SELECT uses_count_today FROM data WHERE guild_id = ?", (message.guild.id,))
if c.fetchone()[0] >= max_uses:
debug("The bot has been used more than 4000 times in the last 24 hours in this guild")
if c.fetchone()[0] >= 500:
debug(f"The bot has been used more than {max_uses} times in the last 24 hours in this guild. Please try again in 24h.")
await message.channel.send("The bot has been used more than 5000 times in the last 24 hours in this guild. Please try again in 24h.")
return
#add 1 to the uses_count_today
@@ -125,7 +125,7 @@ class Chat (discord.Cog) :
prompt += "Botator:"
prompt = prompt + f"\n"
debug("Sending request to the api")
debug(prompt)
#debug(prompt)
openai.api_key = api_key
response = openai.Completion.create(
engine="text-davinci-003",
@@ -162,13 +162,18 @@ class Chat (discord.Cog) :
if not premium:
#get a random number between 1 and 5 , 1 and 4
# 5 included
random_number = random.randint(1, 10)
if random_number == 1:
debug("User is not premium, sending a random message")
random_number = random.randint(1, 20)
if random_number == 30:
embed = discord.Embed(title="Support us by donating here!", url="https://www.buymeacoffee.com/paillat", description="Botator is a free discord bot, but it costs money to run our servers. If you want to support us, you can donate here: https://www.buymeacoffee.com/paillat. For only **2$** a month, you can remove this message and have a daliy maximal usage of **4000** uses instead of **400**. You will acces also to restricted help channels on our discord server,", color=0x00ff00)
await message.channel.send("**This message has 10% chance to appear. It will disappear in 60 seconds.**", embed=embed, delete_after=60)
elif random_number == 2:
debug("The \"support us\" message has been sent")
elif random_number == 11:
#add the picture https://cdn.discordapp.com/attachments/800029200886923318/1050935509930754058/icons8-discord-new-480.png
embed = discord.Embed(title="Join our discord server!", url="https://discord.gg/pB6hXtUeDv", description="You need help with Botator? You can join our discord server and ask for help in the help channel. You can also suggest new features and report bugs. You can also join our discord server to talk with other Botator users and the Botator team, by on the following link: https://discord.gg/pB6hXtUeDv", color=0x00ff00)
await message.channel.send("**This message has 10% chance to appear. It will disappear in 60 seconds.**", embed=embed, delete_after=60)
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}")

View File

@@ -127,8 +127,8 @@ class Settings (discord.Cog) :
#when someone mentions the bot, check if the guild is in the database and if the bot is enabled. If it is, send a message answering the mention
@discord.slash_command(name="pretend", description="Make the bot pretend to be someone else")
@discord.option(name="pretend to be...", description="The person/thing you want the bot to pretend to be", required=True)
async def pretend(self, ctx: discord.ApplicationContext, pretend_to_be: str):
@discord.option(name="pretend to be...", description="The person/thing you want the bot to pretend to be. Leave blank to disable pretend mode", required=False)
async def pretend(self, ctx: discord.ApplicationContext, pretend_to_be: str = None):
debug(f"The user {ctx.author} ran the pretend command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}")
#check if the guild is in the database
c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,))
@@ -140,23 +140,23 @@ class Settings (discord.Cog) :
if c.fetchone()[3] == 0:
await ctx.respond("The bot is disabled", ephemeral=True)
return
#enable pretend if it is not enabled, and disable it if it is
c.execute("SELECT pretend_enabled FROM data WHERE guild_id = ?", (ctx.guild.id,))
if c.fetchone()[0] == 1:
if pretend_to_be is None:
pretend_to_be = ""
c.execute("UPDATE data SET pretend_enabled = 0 WHERE guild_id = ?", (ctx.guild.id,))
conn.commit()
await ctx.respond("Pretend mode disabled", ephemeral=True)
botuser = await self.bot.fetch_user(self.bot.user.id)
await ctx.guild.me.edit(nick=None)
return
else:
c.execute("UPDATE data SET pretend_enabled = 1 WHERE guild_id = ?", (ctx.guild.id,))
conn.commit()
await ctx.respond("Pretend mode enabled", ephemeral=True)
#change the bots name on the server wit ctx.guild.me.edit(nick=pretend_to_be)
await ctx.guild.me.edit(nick=pretend_to_be)
#save the pretend_to_be value
ctx.guild.me.edit(nick=pretend_to_be)
c.execute("UPDATE data SET pretend_to_be = ? WHERE guild_id = ?", (pretend_to_be, ctx.guild.id))
conn.commit()
await ctx.guild.me.edit(nick=pretend_to_be)
return
@discord.slash_command(name="enable_tts", description="Enable TTS when chatting")
async def enable_tts(self, ctx: discord.ApplicationContext):

View File

@@ -1,6 +1,6 @@
import logging
import sqlite3
max_uses: int = 500
max_uses: int = 400
logging.basicConfig(level=logging.INFO)
def debug(message):
@@ -9,6 +9,9 @@ def debug(message):
#create a database called "database.db" if the database does not exist, else connect to it
conn = sqlite3.connect('../database/data.db')
c = conn.cursor()
connp = sqlite3.connect('../database/premium.db')
cp = connp.cursor()
# Create table called "data" if it does not exist with the following columns: guild_id, channel_id, api_key, is_active, max_tokens, temperature, frequency_penalty, presence_penalty, uses_count_today, prompt_size
c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_prefix text, tts boolean, pretend_to_be text, pretend_enabled boolean)''')
cp.execute('''CREATE TABLE IF NOT EXISTS data (user_id text, guild_id text, premium boolean)''')

View File

@@ -4,9 +4,10 @@ import sqlite3 # pip install sqlite3
import logging # pip install logging
import os # pip install os
intents = discord.Intents.all()
conn = sqlite3.connect('premium.db')
conn = sqlite3.connect('../database/premium.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS data (user_id text, guild_id text, premium boolean)''')
conn.commit()
bot = discord.Bot()
logging.basicConfig(level=logging.INFO)
@bot.command()