integrate stk server starting

This commit is contained in:
searinminecraft 2024-01-20 16:17:53 +06:00
parent 1963ec5946
commit df37890dcf
4 changed files with 28 additions and 6 deletions

2
.gitignore vendored
View file

@ -4,3 +4,5 @@ venv
stkserver
logs
config.json
extensions
lina.log

12
bot.py
View file

@ -38,8 +38,9 @@ class Lina(commands.Bot):
"""
pool: asyncpg.Pool
stkserver: STKServer
def __init__(self, stkserver):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
@ -53,7 +54,6 @@ class Lina(commands.Bot):
command_prefix=constants.PREFIX)
self.accent_color = constants.ACCENT_COLOR
self.stkserver: STKServer = stkserver
self.stk_userid: int = None
self.stk_token: str = None
@ -201,7 +201,10 @@ class Lina(commands.Bot):
finally:
await self.session.close()
await super().close()
try:
await self.stkserver.stop()
finally:
await super().close()
async def start(self):
"""Bring lina to life"""
@ -221,3 +224,6 @@ class Lina(commands.Bot):
async def on_ready(self):
log.info(f"Bot {self.user} ({self.user.id}) is ready!")
self.stkPoll.start()
log.info("Starting verification server.")
await self.stkserver.launch()

View file

@ -77,5 +77,17 @@ class Core(commands.Cog):
await ctx.reply("Shutting down :wave:")
await self.bot.close()
@commands.command(hidden=True)
async def shutdownverificationserver(self, ctx: commands.Context):
self.bot.stkserver.restart = False
await ctx.reply("Shutting down verification server.")
await self.bot.stkserver.stop()
@commands.command(hidden=True)
async def restartverificationserver(self, ctx: commands.Context):
self.bot.stkserver.restart = True
await ctx.reply("Restarting verification server.")
await self.bot.stkserver.stop()
async def setup(bot: Lina):
await bot.add_cog(Core(bot))

View file

@ -106,11 +106,13 @@ async def runBot():
logger=log,
cwd=os.getcwd() + "/stkserver",
autostart=False,
extra_args="--disable-addon-karts --disable-addon-tracks",
data_path="/usr/share/supertuxkart",
extra_args=("--disable-addon-karts","--disable-addon-tracks"),
datapath="/usr/share/supertuxkart",
executable_path="/usr/bin/supertuxkart",
name="linaSTK Verification Server",
cfgpath=os.getcwd() + "/stkserver/config.xml"
cfgpath=os.getcwd() + "/stkserver/config.xml",
writeln=lambda _: None,
extra_env={"XDG_DATA_DIRS": ""}
)
await lina.start()