docker ready deployment
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import discord
|
||||
from discord import app_commands, ui
|
||||
import sqlite3
|
||||
from config import TOKEN, ROLE_NAME, DATABASE_FILE
|
||||
import psycopg2
|
||||
import os
|
||||
|
||||
class VerificationModal(ui.Modal, title='Server Verification'):
|
||||
token_input = ui.TextInput(
|
||||
@@ -15,31 +15,40 @@ class VerificationModal(ui.Modal, title='Server Verification'):
|
||||
async def on_submit(self, interaction: discord.Interaction):
|
||||
token = self.token_input.value
|
||||
|
||||
conn = sqlite3.connect(DATABASE_FILE)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT id, discord_user_id FROM participant WHERE discord_token = ?", (token,))
|
||||
result = cursor.fetchone()
|
||||
try:
|
||||
# Connect using your Postgres credentials
|
||||
conn = psycopg2.connect(database=os.environ.get("POSTGRES_DB"), username=os.environ.get("POSTGRES_USER"), password=os.environ.get("POSTGRES_PASSWORD"))
|
||||
with conn.cursor() as cursor:
|
||||
# Postgres uses %s as placeholders instead of ?
|
||||
cursor.execute("SELECT id, discord_user_id FROM participant WHERE discord_token = %s", (token,))
|
||||
result = cursor.fetchone()
|
||||
|
||||
if not result:
|
||||
await interaction.response.send_message("Invalid token. Check your email.", ephemeral=True)
|
||||
return
|
||||
if not result:
|
||||
await interaction.response.send_message("Invalid token. Check your email.", ephemeral=True)
|
||||
return
|
||||
|
||||
db_id, existing_user_id = result
|
||||
if existing_user_id:
|
||||
await interaction.response.send_message("This token is already linked to an account.", ephemeral=True)
|
||||
return
|
||||
db_id, existing_user_id = result
|
||||
if existing_user_id:
|
||||
await interaction.response.send_message("This token is already linked to an account.", ephemeral=True)
|
||||
return
|
||||
|
||||
# Update DB and Role
|
||||
cursor.execute("UPDATE participant SET discord_user_id = ? WHERE id = ?", (str(interaction.user.id), db_id))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
# Update DB
|
||||
cursor.execute("UPDATE participant SET discord_user_id = %s WHERE id = %s", (str(interaction.user.id), db_id))
|
||||
conn.commit()
|
||||
|
||||
conn.close()
|
||||
|
||||
role = discord.utils.get(interaction.guild.roles, name=ROLE_NAME)
|
||||
if role:
|
||||
await interaction.user.add_roles(role)
|
||||
await interaction.response.send_message("Verified! Welcome to the server.", ephemeral=True)
|
||||
else:
|
||||
await interaction.response.send_message("Verification successful, but role not found. Contact staff.", ephemeral=True)
|
||||
# Role Logic
|
||||
role = discord.utils.get(interaction.guild.roles, name=os.environ.get("ROLE_NAME"))
|
||||
if role:
|
||||
await interaction.user.add_roles(role)
|
||||
await interaction.response.send_message("Verified! Welcome to the server.", ephemeral=True)
|
||||
else:
|
||||
await interaction.response.send_message("Verification successful, but role not found. Contact staff.", ephemeral=True)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Database Error: {e}")
|
||||
await interaction.response.send_message("A database error occurred. Please try again later.", ephemeral=True)
|
||||
|
||||
class PersistentView(ui.View):
|
||||
def __init__(self):
|
||||
@@ -85,4 +94,4 @@ async def setup_welcome(interaction: discord.Interaction):
|
||||
await interaction.channel.send(embed=embed, view=PersistentView())
|
||||
await interaction.response.send_message("Setup complete!", ephemeral=True)
|
||||
|
||||
bot.run(TOKEN)
|
||||
bot.run(os.environ.get("TOKEN"))
|
||||
|
||||
Reference in New Issue
Block a user