remove graceful stop, update to discord-py-interaction 5.0.0
We had to remove the graceful stop because it somehow blocked the bot from starting.
This commit is contained in:
parent
3b23bd1a0b
commit
5ec82be548
2 changed files with 49 additions and 87 deletions
|
@ -3,3 +3,4 @@ MYSQL_USER=root
|
||||||
MYSQL_PASSWORD=password
|
MYSQL_PASSWORD=password
|
||||||
MYSQL_DATABASE=database
|
MYSQL_DATABASE=database
|
||||||
DISCORD_TOKEN=token
|
DISCORD_TOKEN=token
|
||||||
|
DISCORD_GUILD=433600034983116810
|
||||||
|
|
77
src/main.py
77
src/main.py
|
@ -8,66 +8,36 @@ from dotenv import load_dotenv
|
||||||
from steamid import SteamID
|
from steamid import SteamID
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
class GracefulDeath:
|
load_dotenv()
|
||||||
"""Catch signals to allow graceful shutdown."""
|
token = os.getenv('DISCORD_TOKEN')
|
||||||
def __init__(self):
|
host = os.getenv('MYSQL_HOST')
|
||||||
self.receivedSignal=self.receivedSignalTermSignal=False
|
user = os.getenv('MYSQL_USER')
|
||||||
catchSignals = [
|
password = os.getenv('MYSQL_PASSWORD')
|
||||||
1,
|
db = os.getenv('MYSQL_DATABASE')
|
||||||
2,
|
guild_id = os.getenv('DISCORD_GUILD')
|
||||||
3,
|
|
||||||
10,
|
|
||||||
12,
|
|
||||||
15,
|
|
||||||
]
|
|
||||||
for signum in catchSignals:
|
|
||||||
signal.signal(signum, self.handler)
|
|
||||||
|
|
||||||
def handler(self, signum):
|
bot = Client()
|
||||||
self.lastSignal=signum
|
|
||||||
self.receivedSignal=True
|
|
||||||
if signum in [2, 3, 15]:
|
|
||||||
self.receivedSignalTermSignal=True
|
|
||||||
|
|
||||||
def main(args):
|
con = Database(host, user, password, db)
|
||||||
sighandler = GracefulDeath()
|
|
||||||
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 = Client(intents=Intents.DEFAULT)
|
try:
|
||||||
|
|
||||||
con = Database(host, user, password, db)
|
|
||||||
|
|
||||||
try:
|
|
||||||
if args[0] == "init_database":
|
if args[0] == "init_database":
|
||||||
con.init_test_database()
|
con.init_test_database()
|
||||||
logger.info(f"First init of database... Please disable this afterwards with the flag init_dabase")
|
logger.info(f"First init of database... Please disable this afterwards with the flag init_dabase")
|
||||||
except:
|
except:
|
||||||
logger.info(f"Skipping database init...")
|
logger.info(f"Skipping database init...")
|
||||||
pass
|
|
||||||
|
|
||||||
@slash_command(
|
@listen()
|
||||||
name="reserve_slot",
|
async def on_ready():
|
||||||
description="Claim your reserved slot on the DM Server",
|
logger.info(f"We logged in as {bot.app.name}.")
|
||||||
scopes=[433600034983116810],
|
|
||||||
)
|
|
||||||
|
|
||||||
@slash_option(
|
@slash_command(name="reserve_slot", description="Claim your reserved slot on the DM Server", scopes=[guild_id])
|
||||||
name="steamid",
|
@slash_option(name="steamid", description="Please provide your SteamID, from https://steamid.xyz/", required=True, opt_type=OptionType.STRING)
|
||||||
description="Please provide your SteamID, from https://steamid.xyz/",
|
async def reserve_slot(ctx: SlashContext, steamid: str):
|
||||||
required=True,
|
|
||||||
opt_type=OptionType.STRING,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def reserve_slot(ctx: SlashContext, steamid: str):
|
|
||||||
channel = ctx.channel.id
|
channel = ctx.channel.id
|
||||||
user = ctx.user
|
user = ctx.user
|
||||||
|
|
||||||
if channel != "433738529898627073" and channel != "441985560144379912":
|
if channel != 433738529898627073 and channel != 441985560144379912:
|
||||||
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})")
|
logger.debug(f"Command was used in the wrong channel. ({channel})")
|
||||||
return
|
return
|
||||||
|
@ -96,13 +66,4 @@ def main(args):
|
||||||
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 {user.username} ({user.id}) is already in the database.")
|
logger.debug(f"{steam_id.steam2(1)} or User {user.username} ({user.id}) is already in the database.")
|
||||||
|
|
||||||
bot.start(token)
|
bot.start(token)
|
||||||
|
|
||||||
while True:
|
|
||||||
logger.info("Trying graceful shutdown...")
|
|
||||||
if sighandler.receivedSignal:
|
|
||||||
bot.remove("reserve_slot", remove_commands=True)
|
|
||||||
exit()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main(sys.argv[1:])
|
|
||||||
|
|
Loading…
Reference in a new issue