v2: watch-party Activity

The Activity is now the full bug.tv site plus a small Discord overlay. Whoever
starts the instance hosts and controls everything; everyone else mirrors the
host's page and playback. The server is a relay keyed by activity instance and
checks membership through Discord's activity-instances API, so it works in DM
and group calls. The bot gateway, slash commands and control message are gone.
This commit is contained in:
4DBug committed 2026-10-27 10:00:34 -05:00
1 parent 4d900c5b56
commit 7de90b5b7c
39 files changed
+1620 -4372

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# Build the Discord Activity: the bug.tv site + the watch-party overlay (docs/protocol.md "Build").
#
# scripts/build-activity.sh <bug-tv web dir> <out dir> [apiBase=/tv]
#
# - copies the site (bug-tv `web/` or its nix packages.web output) to <out dir>
# - index.html + 404.html: sets the bug-tv-api / -tmdb / -img / -force-proxy metas (inserted when
# missing), drops the Google Fonts links (Activity CSP), appends overlay.css + discord.js
# - bundles activity/js/discord.js with @discord/embedded-app-sdk → <out dir>/discord.js
#
# esbuild: $ESBUILD (e.g. nixpkgs' esbuild) or `npx esbuild`. No network access needed;
# @discord/embedded-app-sdk must be in node_modules.
set -euo pipefail
if [ $# -lt 2 ]; then
echo "usage: $0 <bug-tv web dir> <out dir> [apiBase=/tv]" >&2
exit 2
fi
web=$1
out=$2
api=${3:-/tv}
here=$(cd "$(dirname "$0")/.." && pwd)
esbuild=${ESBUILD:-npx esbuild}
[ -f "$web/index.html" ] || { echo "build-activity: $web/index.html not found" >&2; exit 1; }
rm -rf "$out"
mkdir -p "$out"
cp -R "$web"/. "$out"/
chmod -R u+w "$out"
rm -rf "$out/test" # bug-tv's web tests, if building from the source dir
# The site's own img/ would sit under Discord's /img → image.tmdb.org mapping: move it to
# site-img/ and rewrite the references in the pages and stylesheets (before the metas below).
if [ -d "$out/img" ]; then
mv "$out/img" "$out/site-img"
find "$out" -path "$out/vendor" -prune -o -type f \( -name '*.html' -o -name '*.css' \) -print |
while IFS= read -r f; do
sed -i -E "s#([\"'(=])(\\.\\./|\\./|/)?img/#\\1\\2site-img/#g" "$f"
done
fi
set_meta() { # file name content
local f=$1 name=$2 content=$3
if grep -q "<meta name=\"$name\"" "$f"; then
sed -i -E "s|<meta name=\"$name\"[^>]*>|<meta name=\"$name\" content=\"$content\">|" "$f"
else
sed -i -E "0,/<\/head>/s|</head>| <meta name=\"$name\" content=\"$content\">\n</head>|" "$f"
fi
}
for page in index.html 404.html; do
f=$out/$page
[ -f "$f" ] || continue
set_meta "$f" bug-tv-api "$api"
set_meta "$f" bug-tv-tmdb /tmdb/3
set_meta "$f" bug-tv-img /img/t/p/
set_meta "$f" bug-tv-force-proxy 1
# Google Fonts (stylesheet + preconnects) are blocked by the Activity CSP
sed -i -E '/<link[^>]*fonts\.(googleapis|gstatic)\.com[^>]*>/d; /<link rel="preconnect"[^>]*(image|api)\.(tmdb|themoviedb)\.org[^>]*>/d' "$f"
grep -q 'href="/overlay.css"' "$f" || sed -i -E '0,/<\/head>/s|</head>| <link rel="stylesheet" href="/overlay.css">\n</head>|' "$f"
grep -q 'src="/discord.js"' "$f" || sed -i -E '0,/<\/body>/s|</body>| <script type="module" src="/discord.js"></script>\n</body>|' "$f"
done
cp "$here/activity/overlay.css" "$out/overlay.css"
# shellcheck disable=SC2086
(cd "$here" && $esbuild activity/js/discord.js --bundle --format=esm --target=es2020 --minify --legal-comments=none \
--log-level=warning --outfile="$out/discord.js")
echo "build-activity: $out (api $api)"
-35
View File
@@ -1,35 +0,0 @@
#!/usr/bin/env node
// Register slash commands without starting the bot.
// node scripts/register-commands.js → guild-scoped for cfg.guildIds, else global
// node scripts/register-commands.js --global → global
// node scripts/register-commands.js --clear → remove them (same scope rules)
const { REST, Routes } = require('discord.js');
const { loadConfig } = require('../src/config');
const { commandDefs } = require('../src/bot/commands');
async function main() {
const cfg = loadConfig();
const args = process.argv.slice(2);
const body = args.includes('--clear') ? [] : commandDefs;
const rest = new REST({ version: '10' }).setToken(cfg.token);
const guilds = args.includes('--global') ? [] : cfg.guildIds || [];
if (guilds.length) {
for (const g of guilds) {
const res = await rest.put(Routes.applicationGuildCommands(cfg.applicationId, g), { body });
console.log(`guild ${g}: ${res.length} commands`);
}
} else {
// keep Discord's Activity entry-point command (type 4): a bulk overwrite without it fails
const existing = await rest.get(Routes.applicationCommands(cfg.applicationId));
const res = await rest.put(Routes.applicationCommands(cfg.applicationId), {
body: [...body, ...existing.filter((c) => c.type === 4)],
});
console.log(`global: ${res.length} commands (may take up to an hour to appear)`);
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});
-28
View File
@@ -1,28 +0,0 @@
#!/usr/bin/env bash
# Copies bug-tv's player engine + hls.js into activity/vendor/bugtv/, mirroring bug-tv's web/ layout:
# activity/vendor/bugtv/js/ui/player.js (unchanged copy)
# activity/vendor/bugtv/js/config.js (shim: resolveUrl from activity/js/urls.js)
# activity/vendor/bugtv/vendor/hls.min.js (unchanged copy; main.js preloads it as window.Hls)
# Run before `npm run build:activity` (esbuild bundles player.js + the shim into dist/main.js).
#
# usage: scripts/vendor-bugtv.sh <bug-tv web dir> [activity dir]
set -euo pipefail
web="${1:?usage: vendor-bugtv.sh <bug-tv web dir> [activity dir]}"
here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
activity="${2:-$here/activity}"
out="$activity/vendor/bugtv"
for f in js/ui/player.js vendor/hls.min.js; do
[ -f "$web/$f" ] || { echo "vendor-bugtv: missing $web/$f" >&2; exit 1; }
done
rm -rf "$out"
mkdir -p "$out/js/ui" "$out/vendor"
install -m 0644 "$web/js/ui/player.js" "$out/js/ui/player.js"
install -m 0644 "$web/vendor/hls.min.js" "$out/vendor/hls.min.js"
cat > "$out/js/config.js" <<'EOF'
// generated by scripts/vendor-bugtv.sh — player.js imports only resolveUrl from here
export { resolveUrl } from '../../../js/urls.js';
EOF
echo "vendor-bugtv: $web → $out"