Added experimental bot wrapper functionality for completely automated updates and restarts
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
# modules/common/boot_notice.py
|
|
import os
|
|
import time
|
|
import discord
|
|
|
|
async def post_boot_notice(bot: discord.Client):
|
|
# Needs modlog_channel_id in config/env
|
|
cfg = bot.config['DEFAULT']
|
|
ch_raw = cfg.get('modlog_channel_id') or os.getenv('SHAI_MODLOG_CHANNEL_ID')
|
|
if not ch_raw:
|
|
return
|
|
try:
|
|
ch_id = int(ch_raw)
|
|
except Exception:
|
|
return
|
|
ch = None
|
|
for g in bot.guilds:
|
|
ch = g.get_channel(ch_id)
|
|
if ch:
|
|
break
|
|
if not ch:
|
|
return
|
|
|
|
status = os.getenv("SHAI_BOOT_STATUS", "").strip()
|
|
oldver = os.getenv("SHAI_BOOT_OLDVER", "").strip()
|
|
newver = os.getenv("SHAI_BOOT_NEWVER", "").strip()
|
|
commit = os.getenv("SHAI_BUILD_COMMIT", "").strip()
|
|
subject = os.getenv("SHAI_BUILD_SUBJECT", "").strip()
|
|
|
|
if not status:
|
|
return
|
|
|
|
parts = [f"**Boot**: {status}"]
|
|
if oldver or newver:
|
|
parts.append(f"**Version**: {oldver or '?'} → {newver or '?'}")
|
|
if commit:
|
|
parts.append(f"**Commit**: `{commit}`")
|
|
if subject and len(subject) > 5:
|
|
parts.append(f"**Note**: {subject}")
|
|
|
|
msg = " | ".join(parts) + f" — <t:{int(time.time())}:R>"
|
|
try:
|
|
await ch.send(msg, allowed_mentions=discord.AllowedMentions.none())
|
|
except Exception:
|
|
pass
|