added logging
This commit is contained in:
parent
9d30aea5a8
commit
aa6a4728ba
2 changed files with 14 additions and 6 deletions
|
@ -2,3 +2,4 @@ discord-py-interactions==4.3.1
|
||||||
steamid==1.0.2
|
steamid==1.0.2
|
||||||
python-dotenv==0.21.0
|
python-dotenv==0.21.0
|
||||||
mysql-connector-python==8.0.30
|
mysql-connector-python==8.0.30
|
||||||
|
loguru==0.6.0
|
||||||
|
|
15
src/main.py
15
src/main.py
|
@ -6,10 +6,10 @@ import database
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from steamid import SteamID
|
from steamid import SteamID
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
class GracefulDeath:
|
class GracefulDeath:
|
||||||
"""Catch signals to allow graceful shutdown."""
|
"""Catch signals to allow graceful shutdown."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.receivedSignal=self.receivedSignalTermSignal=False
|
self.receivedSignal=self.receivedSignalTermSignal=False
|
||||||
catchSignals = [
|
catchSignals = [
|
||||||
|
@ -19,7 +19,7 @@ class GracefulDeath:
|
||||||
10,
|
10,
|
||||||
12,
|
12,
|
||||||
15,
|
15,
|
||||||
]
|
]
|
||||||
for signum in catchSignals:
|
for signum in catchSignals:
|
||||||
signal.signal(signum, self.handler)
|
signal.signal(signum, self.handler)
|
||||||
|
|
||||||
|
@ -44,8 +44,9 @@ def main(args):
|
||||||
try:
|
try:
|
||||||
if args[0] == "init_database":
|
if args[0] == "init_database":
|
||||||
database.init_test_database(mysql)
|
database.init_test_database(mysql)
|
||||||
|
logger.info(f"First init of database... Please disable this afterwards with the flag init_dabase")
|
||||||
except:
|
except:
|
||||||
print("Skipping database init...")
|
logger.info(f"Skipping database init...")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@bot.command(
|
@bot.command(
|
||||||
|
@ -68,31 +69,37 @@ def main(args):
|
||||||
|
|
||||||
if channel != "433738529898627073":
|
if channel != "433738529898627073":
|
||||||
await ctx.send(f"This command only works in the Channel <#433738529898627073>!", ephemeral=True)
|
await ctx.send(f"This command only works in the Channel <#433738529898627073>!", ephemeral=True)
|
||||||
|
logger.debug(f"Command was used in the wrong channel. ({channel})")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
steam_id = SteamID(steamid)
|
steam_id = SteamID(steamid)
|
||||||
except:
|
except:
|
||||||
await ctx.send(f"You failed to give a valid SteamID as it seems, please head to <https://steamid.xyz/> and check.", ephemeral=True)
|
await ctx.send(f"You failed to give a valid SteamID as it seems, please head to <https://steamid.xyz/> and check.", ephemeral=True)
|
||||||
|
logger.debug(f"User ({user.id}) has give a invalid SteamID. Could not convert!")
|
||||||
return
|
return
|
||||||
|
|
||||||
if steam_id.isValid() == False:
|
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)
|
await ctx.send(f"You failed to give a valid SteamID as it seems, please head to <https://steamid.xyz/> and check.", ephemeral=True)
|
||||||
|
logger.debug(f"User ({user.id}) has given a invalid SteamID!")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
database.create_reserved_slot(mysql, user, steam_id.steam2(1))
|
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)}`!")
|
await ctx.send(f"You just claimed a reserved slot for: `{steam_id.steam2(1)}`!")
|
||||||
|
logger.debug(f"{steam_id.steam2(1)} has just claimed a reserved slot.")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if str(err) != "Duplicate entrys":
|
if str(err) != "Duplicate entrys":
|
||||||
await ctx.send(f"Something failed with the database, please try again later.", ephemeral=True)
|
await ctx.send(f"Something failed with the database, please try again later.", ephemeral=True)
|
||||||
|
logger.warning(f"Error while trying to access database.", err)
|
||||||
return
|
return
|
||||||
await ctx.send(f"You have already claimed a reserved slot!", ephemeral=True)
|
await ctx.send(f"You have already claimed a reserved slot!", ephemeral=True)
|
||||||
|
logger.debug(f"{steam_id.steam2(1)} or {user.id} is already in the database.")
|
||||||
|
|
||||||
bot.start()
|
bot.start()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print("Graceful shutdown...")
|
logger.info("Trying graceful shutdown...")
|
||||||
if sighandler.receivedSignal:
|
if sighandler.receivedSignal:
|
||||||
bot.remove("reserve_slot", remove_commands=True)
|
bot.remove("reserve_slot", remove_commands=True)
|
||||||
exit()
|
exit()
|
||||||
|
|
Loading…
Reference in a new issue