No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-22 13:50:39 +01:00
workspace aggressive image-intent routing to local Qwen-Image gen; never SVG/codegen fallback 2026-11-21 19:36:32 +01:00
.gitignore Strata Discord gateway bot: react 👀/🤔, in-channel memory, systemd unit docs 2026-11-21 17:43:29 +01:00
bot.mjs cap thinking at 300 tokens per chat answer (wall-time for Discord) 2026-11-22 13:50:39 +01:00
package-lock.json Strata Discord gateway bot: react 👀/🤔, in-channel memory, systemd unit docs 2026-11-21 17:43:29 +01:00
package.json Strata Discord gateway bot: react 👀/🤔, in-channel memory, systemd unit docs 2026-11-21 17:43:29 +01:00
README.md read-only stats (strata/gpu/box) + web search via SearXNG 2026-11-21 18:11:43 +01:00

strata-discord-bot

Gateway bot (websocket out to Discord) answering from local Strata. No public URL, no port forwarding.

Using it on Discord

  • Mention the bot in any channel: @StrataBot what does serve/server.py do?
  • Text before/after the mention is the prompt; the mention itself is stripped.
  • Bare mention (@StrataBot alone) prints this in-server help.
  • Status emoji appear on your post: 👀 seen, 🤔 generating (removed when the answer posts).
  • Follow-ups keep context — the last 8 turns in that channel are replayed to the model.
  • Replies are chat markdown: bold, italics, code, blocks, > quotes, ### headings, @mentions. Long answers arrive as several messages (2000-char Discord limit).
  • It does not answer slash commands, DMs, or un-mentioned messages.

Setup

  1. discord.com/developers/applications → your Application → Bot tab: copy token, enable the Message Content toggle (without it messageCreate never fires).
  2. OAuth2 → URL Generator: scope bot, permissions Send Messages + Read Message History, open the generated URL, invite to your server.
  3. npm i discord.js (already done here).
  4. echo 'DISCORD_TOKEN=***' > .env — mode 600, gitignored. Never in code, never in chat; rotate if pasted.
  5. STRATA_URL / STRATA_MODEL in the same file:
STRATA_URL=http://127.0.0.1:8090
STRATA_MODEL=qwen3.8-flash-next-coder-iq1_m

Get the real values from curl -s localhost:8090/v1/models | jq -r '.data[].id' — the model id, not a friendly name.

Backend

Plain OpenAI-compatible call to Strata (/v1/chat/completions) — no agent process, nothing else to run. Per message the bot sends: system prompt (Discord rules + workspace state), last 8 turns of that channel, then the mention text. Images attached to the message go in as vision parts (the model is multimodal, ≤2 images, ≤8 MB each).

Replies

  • Real code blocks become attachments (code1.python…), one message, never chunked.
  • Blocks tagged text/md/markdown/plain stay inline — the model is told to keep prose outside fences.
  • Control blocks (memory/user/soul/agents) are consumed by the bot and never shown; the reply ends with 📝 updated MEMORY.md.
  • 👀 / 🤔 reactions mark seen/generating. If they never appear, the bot role lacks Add Reactions — grant it in Server Settings → Roles.
  • Replies never ping anyone (allowedMentions.parse = []), so the bot cannot tag itself or start a mention storm.
  • Another bot that mentions us gets answered too, up to 3 hops per channel; a human message resets the count. @name markup is read as "@Name" / "@Name (bot)" so the model knows who is talking.
  • Attached images are read as vision input; GIFs/stickers/videos are ignored.
  • @StrataBot note <text> appends a timestamped bullet to workspace/MEMORY.md without a model call.
  • Replies never ping anyone (allowedMentions.parse = []), so the bot cannot tag itself or start a mention storm.
  • Another bot that mentions us gets answered too, up to 3 hops per channel; a human message resets the count. @name markup is read as "@Name" / "@Name (bot)" so the model knows who is talking.
  • Attached images are read as vision input; GIFs/stickers/videos are ignored.
  • @StrataBot note <text> appends a timestamped bullet to workspace/MEMORY.md without a model call.

Workspace (bot state)

workspace/ holds the bot's own markdown, re-read on every message and pasted into its system prompt (last 2000 chars each):

file meaning how it changes
SOUL.md who the bot is model rewrites it via a ```soul block
AGENTS.md how it behaves model rewrites it via a ```agents block
MEMORY.md facts learned on the server model appends ```memory bullets; @Bot note <text> appends too
USER.md who the humans are model appends ```user bullets

Runtime edits dirty the repo (git status) — commit when you agree with them; the bot cannot touch any other path.

  • @StrataBot search <query> searches the web via SearXNG (SEARXNG_URL in .env, default https://searxng.cyfrowynomada.com) and answers with cited sources. Requires formats: [html, json] in the instance's settings.yml — without it the API 403s and the bot says so.

Security & robustness

  • Token only via .env (mode 600, gitignored); bot exits loudly if missing. Never in code or chat — rotate if exposed.
  • Replies carry allowedMentions.parse: [] — the bot can never ping anyone, so no mention storms.
  • One guard around the whole message handler plus client/shard/unhandled-rejection logging: a bad message logs an error, it never kills the process.
  • Model calls and image fetches are timeout-bounded (180 s / 30 s); note input capped at 280 chars; image attachments capped at 2 × 8 MB.
  • Channel content is treated as data, not instructions (stated in the system prompt); workspace/*.md are the only files it can touch, all paths derive from its own directory.

Service

~/.config/systemd/user/strata-bot.service — Restart=on-failure, RestartSec=3.

systemctl --user restart strata-bot.service   # after editing .env or bot.mjs
systemctl --user status   strata-bot.service
journalctl --user -u strata-bot.service -f    # live log

Unit needs an absolute node path (/home/llama/.local/share/mise/installs/node/latest/bin/node) — systemd's PATH does not contain the mise shim.