0.4.0.0.a5

- Minor styling fix for the docsite footer
- Cleaned up data, variables, etc. relating to the docsite
This commit is contained in:
Franz Rolfsvaag 2025-08-13 13:06:28 +02:00
parent 985888fb5a
commit d768712b75
2 changed files with 46 additions and 7 deletions

2
bot.py
View File

@ -9,7 +9,7 @@ from modules.common.boot_notice import post_boot_notice
# Version consists of:
# Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesnt trigger auto update)
VERSION = "0.4.0.0.a4"
VERSION = "0.4.0.0.a5"
# ---------- Env loading ----------

View File

@ -634,6 +634,9 @@ _HTML = """<!doctype html>
.flag-emoji { height:1em; width:auto; vertical-align:-0.18em; border-radius:2px; display:inline-block; }
footer { margin-top:16px; color:var(--muted); font-size:12px; text-align:center; }
footer .line { margin:4px 0; }
footer a { color: var(--fg); text-decoration: none; border-bottom: 1px dotted #334155; }
footer a:hover { text-decoration: underline; }
/* Copy modal */
#copyModal { position: fixed; inset: 0; display:none; align-items:center; justify-content:center; z-index: 10; }
@ -720,11 +723,13 @@ _HTML = """<!doctype html>
</div>
</div>
<footer id="footer">
<footer id="footer">
<div class="line" id="copyright"></div>
<div class="line" id="statusline">Uptime: · Version: v</div>
<div class="line" id="coffee"><a href="https://throne.com/ookamikuntv/item/39590391-c582-4c5d-8795-fe6f1925eaae">Buy me a :coffee:</a></div>
</footer>
<div class="line" id="coffee" style="display:__SUPPORT_VIS__">
<a id="supportLink" href="__SUPPORT_URL__" target="_blank" rel="noopener noreferrer">__SUPPORT_LABEL__</a>
</div>
</footer>
<!-- Copy/share modal -->
<div id="copyModal" aria-hidden="true">
@ -866,7 +871,7 @@ function openCopyModal(text) {
}
function moduleSansPrefix(r) {
const m = r.module || '';
return m.replace(/^modules?\\./, '');
return m.replace(/^modules?\./, '').replace(/^discord\.ext\./, '');
}
async function shareFor(r) {
@ -1152,6 +1157,28 @@ class _DocsHandler(BaseHTTPRequestHandler):
schema = build_command_schema(self.bot)
inline = json.dumps(_to_primitive(schema), ensure_ascii=False, separators=(",", ":"))
html = html.replace("</head>", f"<script>window.__DATA__={inline};</script></head>")
# Inject support link + visibility
support_url = getattr(_DocsHandler, "support_url", "") or ""
support_label = getattr(_DocsHandler, "support_label", "Buy me a ☕")
vis = "block" if support_url else "none"
html = (html
.replace("__SUPPORT_URL__", support_url)
.replace("__SUPPORT_LABEL__", support_label)
.replace("__SUPPORT_VIS__", vis)
)
# Fallback to values stored on the cog (well wire them below in _start_server)
support_url = support_url or getattr(_DocsHandler, "support_url", "")
support_label = support_label or getattr(_DocsHandler, "support_label", "Buy me a ☕")
vis = "block" if support_url else "none"
html = (html
.replace("__SUPPORT_URL__", support_url)
.replace("__SUPPORT_LABEL__", support_label)
.replace("__SUPPORT_VIS__", vis)
)
except Exception:
traceback.print_exc()
self.wfile.write(html.encode("utf-8"))
@ -1188,6 +1215,8 @@ class _DocsHandler(BaseHTTPRequestHandler):
def _start_server(bot: commands.Bot, host: str, port: int, title: str):
_DocsHandler.bot = bot
_DocsHandler.title = title
_DocsHandler.support_url = getattr(bot, "docs_support_url", None)
_DocsHandler.support_label = getattr(bot, "docs_support_label", None)
_DocsHandler.force_ready = os.getenv("SHAI_OFFLINE", "").lower() in {"1", "true", "yes"}
httpd = ThreadingHTTPServer((host, port), _DocsHandler)
@ -1207,9 +1236,19 @@ class DocsSite(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
r = cfg(bot)
self.host = r.get("docs_host", "0.0.0.0") # SHAI_DOCS_HOST
self.port = r.int("docs_port", 8910) # SHAI_DOCS_PORT
self.title = r.get("docs_title", "ShaiWatcher Commands") # SHAI_DOCS_TITLE
# Support link config
self.support_url = r.get("docs_support_url", "https://throne.com/ookamikuntv/item/39590391-c582-4c5d-8795-fe6f1925eaae")
self.support_label = r.get("docs_support_label", "Buy me a ☕")
# Expose to handler via bot (read in _start_server)
self.bot.docs_support_url = self.support_url
self.bot.docs_support_label = self.support_label
_start_server(self.bot, self.host, self.port, self.title)
def force_ready(self, value: bool = True):