mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 01:06:19 +00:00
@@ -2,7 +2,7 @@ import discord
|
|||||||
import re
|
import re
|
||||||
import asyncio
|
import asyncio
|
||||||
import openai
|
import openai
|
||||||
from config import debug, c, max_uses, cp
|
from config import debug, c, max_uses, cp, conn, connp
|
||||||
import random
|
import random
|
||||||
class Chat (discord.Cog) :
|
class Chat (discord.Cog) :
|
||||||
def __init__(self, bot: discord.Bot):
|
def __init__(self, bot: discord.Bot):
|
||||||
@@ -39,15 +39,19 @@ class Chat (discord.Cog) :
|
|||||||
return
|
return
|
||||||
#check if the bot hasn't been used more than 5000 times in the last 24 hours (uses_count_today)
|
#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,))
|
c.execute("SELECT uses_count_today FROM data WHERE guild_id = ?", (message.guild.id,))
|
||||||
if c.fetchone()[0] >= 500:
|
uses = c.fetchone()[0]
|
||||||
|
cp.execute("SELECT premium FROM data WHERE user_id = ? AND guild_id = ?", (message.author.id, message.guild.id))
|
||||||
|
premium = cp.fetchone()
|
||||||
|
if c.fetchone()[0] >= 500 and premium != 1:
|
||||||
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.")
|
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.")
|
await message.channel.send("The bot has been used more than 500 times in the last 24 hours in this guild. Please try again in 24h.")
|
||||||
return
|
return
|
||||||
#add 1 to the uses_count_today
|
#add 1 to the uses_count_today
|
||||||
#show that the bot is typing
|
#show that the bot is typing
|
||||||
await message.channel.trigger_typing()
|
await message.channel.trigger_typing()
|
||||||
if message.guild.id != 1021872219888033903:
|
if message.guild.id != 1021872219888033903:
|
||||||
c.execute("UPDATE data SET uses_count_today = uses_count_today + 1 WHERE guild_id = ?", (message.guild.id,))
|
c.execute("UPDATE data SET uses_count_today = uses_count_today + 1 WHERE guild_id = ?", (message.guild.id,))
|
||||||
|
conn.commit()
|
||||||
#get the api key from the database
|
#get the api key from the database
|
||||||
c.execute("SELECT api_key FROM data WHERE guild_id = ?", (message.guild.id,))
|
c.execute("SELECT api_key FROM data WHERE guild_id = ?", (message.guild.id,))
|
||||||
api_key = c.fetchone()[0]
|
api_key = c.fetchone()[0]
|
||||||
|
|||||||
10
code/resetter.py
Normal file
10
code/resetter.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import sqlite3
|
||||||
|
conn = sqlite3.connect('../database/data.db')
|
||||||
|
c = conn.cursor()
|
||||||
|
import time
|
||||||
|
#the database is: 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)''')
|
||||||
|
#set the uses_count_today to 0 for all guilds every 24 hours
|
||||||
|
while True:
|
||||||
|
c.execute("UPDATE data SET uses_count_today = 0")
|
||||||
|
conn.commit()
|
||||||
|
time.sleep(86400)
|
||||||
17
docker/resetter/Dockerfile
Normal file
17
docker/resetter/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
# For more information, please refer to https://aka.ms/vscode-docker-python
|
||||||
|
FROM python:3.10.0
|
||||||
|
|
||||||
|
|
||||||
|
# Keeps Python from generating .pyc files in the container
|
||||||
|
|
||||||
|
# Turns off buffering for easier container logging
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
# Install pip requirements
|
||||||
|
RUN git clone https://github.com/Paillat-dev/Botator.git
|
||||||
|
WORKDIR /Botator/code/
|
||||||
|
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
|
||||||
|
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /Botator/code
|
||||||
|
USER appuser
|
||||||
|
CMD ["python", "resetter.py"]
|
||||||
Reference in New Issue
Block a user