2022-09-20 01:44:23 +02:00
|
|
|
import os
|
|
|
|
import interactions
|
2022-09-20 13:49:23 +02:00
|
|
|
import database
|
2022-09-20 01:44:23 +02:00
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from steamid import SteamID
|
|
|
|
|
2022-09-20 13:49:23 +02:00
|
|
|
def main():
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
if steam_id.isValid() == True:
|
|
|
|
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"You have already claimed a reserved slot!")
|
|
|
|
else:
|
|
|
|
await ctx.send(f"Something failed with the database, please try again later.")
|
|
|
|
else:
|
|
|
|
await ctx.send(f"You failed to give a valid SteamID as it seems, please head to <https://steamid.xyz/ and check.")
|
|
|
|
|
|
|
|
bot.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|