modified: bot.py
This commit is contained in:
71
bot.py
71
bot.py
@@ -34,11 +34,6 @@ OPENAI_BASE_URL = os.getenv("OPENAI_BASE_URL")
|
||||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
||||
OWNER_ID = int(os.getenv("OWNER_ID"))
|
||||
|
||||
GIVEAWAY_DB_HOST = os.getenv("GIVEAWAY_DB_HOST")
|
||||
GIVEAWAY_DB_PORT = os.getenv("GIVEAWAY_DB_PORT")
|
||||
GIVEAWAY_DB_USER = os.getenv("GIVEAWAY_DB_USER")
|
||||
GIVEAWAY_DB_PASSWORD = os.getenv("GIVEAWAY_DB_PASSWORD")
|
||||
GIVEAWAY_DB_DATABASE = os.getenv("GIVEAWAY_DB_DATABASE")
|
||||
GIVEAWAY_WEBSITE_URL = os.getenv("GIVEAWAY_WEBSITE_URL")
|
||||
|
||||
features = {
|
||||
@@ -46,36 +41,6 @@ features = {
|
||||
"vision": bool(int(os.getenv("VISION_ENABLED", 0)))
|
||||
}
|
||||
|
||||
def connect_to_giveaway_db():
|
||||
return mysql.connector.connect(
|
||||
host=GIVEAWAY_DB_HOST,
|
||||
port=GIVEAWAY_DB_PORT,
|
||||
user=GIVEAWAY_DB_USER,
|
||||
password=GIVEAWAY_DB_PASSWORD,
|
||||
database=GIVEAWAY_DB_DATABASE
|
||||
)
|
||||
|
||||
def create_giveaway_table():
|
||||
connection = connect_to_giveaway_db()
|
||||
cursor = connection.cursor()
|
||||
create_table_query = """
|
||||
CREATE TABLE IF NOT EXISTS giveaways (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
platform VARCHAR(255),
|
||||
name VARCHAR(255),
|
||||
uuid CHAR(36) NOT NULL UNIQUE,
|
||||
game_key VARCHAR(255),
|
||||
winner_dc_id BIGINT,
|
||||
aktiv BOOLEAN DEFAULT FALSE
|
||||
);
|
||||
"""
|
||||
cursor.execute(create_table_query)
|
||||
connection.commit()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
create_giveaway_table()
|
||||
|
||||
giveaways = {}
|
||||
|
||||
# Erstelle einen Ordner für die Logs, wenn er noch nicht existiert
|
||||
@@ -146,25 +111,8 @@ db_connection = mysql.connector.connect(
|
||||
# Cursor erstellen
|
||||
db_cursor = db_connection.cursor()
|
||||
|
||||
# SQL-Befehl für die Erstellung der Tabelle, falls sie noch nicht existiert
|
||||
create_table_query = """
|
||||
CREATE TABLE IF NOT EXISTS user_data (
|
||||
user_id BIGINT,
|
||||
guild_id BIGINT,
|
||||
permission INT,
|
||||
points INT,
|
||||
ban INT,
|
||||
askmultus INT,
|
||||
filter_value INT,
|
||||
rank INT,
|
||||
chat_history JSON,
|
||||
xp INT,
|
||||
level INT,
|
||||
PRIMARY KEY (user_id, guild_id)
|
||||
);
|
||||
"""
|
||||
db_cursor.execute(create_table_query)
|
||||
db_connection.commit()
|
||||
def close_database_connection(connection):
|
||||
connection.close()
|
||||
|
||||
def insert_user_data(user_id, guild_id, permission, points, ban, askmultus, filter_value, chat_history, xp=0, level=1):
|
||||
insert_query = """
|
||||
@@ -308,27 +256,26 @@ def load_user_data(user_id, guild_id):
|
||||
|
||||
return user_data
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------
|
||||
|
||||
def save_giveaway_to_db(platform, name, prize_uuid, game_key, winner_dc_id=None):
|
||||
connection = connect_to_giveaway_db()
|
||||
def save_giveaway_to_db(guild_id, platform, name, prize_uuid, game_key, winner_dc_id=None):
|
||||
connection = connect_to_database()
|
||||
cursor = connection.cursor()
|
||||
insert_query = """
|
||||
INSERT INTO giveaways (platform, name, uuid, game_key, winner_dc_id, aktiv)
|
||||
INSERT INTO giveaway_data (guild_id, platform, name, uuid, game_key, winner_dc_id, aktiv)
|
||||
VALUES (%s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
data = (platform, name, str(prize_uuid), game_key, winner_dc_id, False)
|
||||
data = (guild_id, platform, name, str(prize_uuid), game_key, winner_dc_id, False)
|
||||
cursor.execute(insert_query, data)
|
||||
connection.commit()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
def update_winner_in_db(prize_uuid, winner_dc_id):
|
||||
connection = connect_to_giveaway_db()
|
||||
connection = connect_to_database()
|
||||
cursor = connection.cursor()
|
||||
update_query = """
|
||||
UPDATE giveaways SET winner_dc_id = %s WHERE uuid = %s
|
||||
UPDATE giveaway_data SET winner_dc_id = %s WHERE uuid = %s
|
||||
"""
|
||||
data = (winner_dc_id, str(prize_uuid))
|
||||
cursor.execute(update_query, data)
|
||||
@@ -351,7 +298,7 @@ class Giveaway:
|
||||
self.game_key = f"PREDEFINED_GAME_KEY" # Platzhalter für den tatsächlichen Game-Key
|
||||
|
||||
# Speichern des Giveaways in der Datenbank
|
||||
save_giveaway_to_db(self.platform, self.title, self.prize_uuid, self.game_key)
|
||||
save_giveaway_to_db(ctx.guild.id, self.platform, self.title, self.prize_uuid, self.game_key)
|
||||
|
||||
def add_participant(self, user):
|
||||
if user not in self.participants:
|
||||
|
||||
Reference in New Issue
Block a user