65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
import os
|
|
import sys
|
|
import interactions
|
|
import database
|
|
|
|
from dotenv import load_dotenv
|
|
from steamid import SteamID
|
|
|
|
def main(args):
|
|
load_dotenv()
|
|
token = os.getenv('DISCORD_TOKEN')
|
|
host = os.getenv('MYSQL_HOST')
|
|
user = os.getenv('MYSQL_USER')
|
|
password = os.getenv('MYSQL_PASSWORD')
|
|
db = os.getenv('MYSQL_DATABASE')
|
|
|
|
bot = interactions.Client(token=token)
|
|
|
|
mysql = database.create_connection(host, user, password, db)
|
|
if args[0] == "init_database":
|
|
database.init_test_database(mysql)
|
|
|
|
@bot.command(
|
|
name="reserve_slot",
|
|
description="Claim your reserved slot on the DM Server",
|
|
scope=433600034983116810,
|
|
options=[
|
|
interactions.Option(
|
|
name="steamid",
|
|
description="Please provide your SteamID, from https://steamid.xyz/",
|
|
type=interactions.OptionType.STRING,
|
|
required=True,
|
|
),
|
|
],
|
|
)
|
|
|
|
async def reserve_slot(ctx: interactions.CommandContext, steamid: str):
|
|
steam_id = SteamID(steamid)
|
|
user = ctx.user
|
|
channel = ctx.channel.id
|
|
|
|
if channel != "433738529898627073":
|
|
await ctx.send(f"This command only works in the Channel <#433738529898627073>!", ephemeral=True)
|
|
return
|
|
|
|
if steam_id.isValid() == False:
|
|
await ctx.send(f"You failed to give a valid SteamID as it seems, please head to <https://steamid.xyz/ and check.", ephemeral=True)
|
|
return
|
|
|
|
try:
|
|
database.create_reserved_slot(mysql, user, steam_id.steam2(1))
|
|
await ctx.send(f"You just claimed a reserved slot for: `{steam_id.steam2(1)}`!")
|
|
except Exception as err:
|
|
if str(err) != "Duplicate entrys":
|
|
await ctx.send(f"Something failed with the database, please try again later.", ephemeral=True)
|
|
return
|
|
await ctx.send(f"You have already claimed a reserved slot!", ephemeral=True)
|
|
|
|
bot.start()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv[1:])
|