From 016041dc88ef890576633614bf08b75374d4a672 Mon Sep 17 00:00:00 2001 From: NotSoToothless <67082114+FURRO404@users.noreply.github.com> Date: Sun, 31 May 2026 01:43:19 -0700 Subject: [PATCH] move venv to shared (#1291) --- ecosystem.config.js | 7 +++---- requirements.txt | 6 ------ start_bot.py | 51 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 14 deletions(-) delete mode 100644 requirements.txt diff --git a/ecosystem.config.js b/ecosystem.config.js index 8485fa1..91b0d26 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -6,10 +6,9 @@ const DEPLOY_PATH = __dirname; -// Reuse SREBOT's venv by default — both bots share BOTS/SHARED and most -// runtime deps (discord.py, dotenv, …). Split into TSSBOT/.venv once the -// dep sets diverge meaningfully. -const PY_INTERPRETER = `${DEPLOY_PATH}/../SREBOT/.venv/bin/python`; +// Both bots share one venv at BOTS/SHARED/.venv, built from +// SHARED/requirements.txt (both bots also share BOTS/SHARED for code). +const PY_INTERPRETER = `${DEPLOY_PATH}/../SHARED/.venv/bin/python`; module.exports = { apps: [ diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 38a7099..0000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -# TSSBOT runtime deps — populate as the bot is built out. -# Many shared utilities under BOTS/SHARED/ require the same deps SREBOT uses; -# see ../SREBOT/requirements.txt for reference. -aiosqlite -discord.py -python-dotenv diff --git a/start_bot.py b/start_bot.py index 518ab1b..f500a52 100644 --- a/start_bot.py +++ b/start_bot.py @@ -19,7 +19,7 @@ from dotenv import load_dotenv load_dotenv(dotenv_path=_HERE / ".env") # Imported after load_dotenv so env vars are available. -from BOT.storage import init_tss_dbs # noqa: E402 +from BOT.storage import init_tss_dbs, STORAGE_DIR # noqa: E402 from BOT.autologging import set_bot as set_autolog_bot # noqa: E402 from BOT.commands import setup_commands # noqa: E402 from tss_ws import listen, _handle_game # noqa: E402 @@ -71,13 +71,56 @@ async def _ws_task_loop() -> None: await asyncio.sleep(10) +def _write_guild_report() -> None: + """Write TSSBOT's own guild list to the shared storage volume. + + Uses a TSS-specific filename so it does not clobber SREBOT's + SREBOT_GUILDS.txt, which lives on the same STORAGE_VOL_PATH volume. + """ + out_path = STORAGE_DIR / "TSSBOT_GUILDS.txt" + with out_path.open("w", encoding="utf-8") as f: + f.write(f"We have logged in as {bot.user} in the following Guilds:\n\n") + for guild in bot.guilds: + created = guild.created_at.strftime("%Y-%m-%d") + f.write( + f" - {guild.name} (id: {guild.id}) | Members: {guild.member_count} | Created: {created}\n" + ) + log.info(f"Guild report written to {out_path.resolve()}") + + +async def _refresh_presence() -> None: + """Update the bot's Discord presence to show the current guild count.""" + guild_total = len(bot.guilds) + await bot.change_presence( + activity=discord.Activity( + type=discord.ActivityType.playing, + name=f"Playing TSS in {guild_total} servers!", + ) + ) + + +@bot.event +async def on_guild_join(guild): + log.info(f"joined guild: {guild.name} (id: {guild.id})") + log.info(f"updated total guilds: {len(bot.guilds)}") + _write_guild_report() + await _refresh_presence() + + +@bot.event +async def on_guild_remove(guild): + log.info(f"removed from guild: {guild.name} (id: {guild.id})") + log.info(f"updated total guilds: {len(bot.guilds)}") + _write_guild_report() + await _refresh_presence() + + @bot.event async def on_ready(): log.info(f"logged in as {bot.user} (id={bot.user.id if bot.user else '?'})") log.info(f"connected to {len(bot.guilds)} guild(s)") - await bot.change_presence( - activity=discord.CustomActivity(name="Soon...") - ) + _write_guild_report() + await _refresh_presence() asyncio.create_task(_ws_task_loop())