- Python 96.7%
- Shell 3.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| tests | ||
| .gitignore | ||
| analyze.py | ||
| channels.example.txt | ||
| install.sh | ||
| install_support.py | ||
| LICENSE | ||
| logger.py | ||
| main.py | ||
| README.md | ||
| requirements.txt | ||
| service_runner.py | ||
| sorter.py | ||
TDSCLS
A Discord chat logger with terminal tools for grouping conversations and summarizing them locally with Ollama.
Discord → channel logs → select dialogue groups → local chat summaries
What it does
- Logs text from configured channels, with stable message indices and reply references.
- Keeps a current transcript and a history that preserves original messages, edits, and deletion events.
- Recovers missed messages after startup or reconnect using each channel's latest recorded message date. New channels import their latest 50 messages.
- Provides a curses sorter for assigning messages to numbered, colored groups.
- Summarizes channel logs or selected groups with
qwen3:1.7b, focusing on topics discussed, decisions made, and things done.
Attachments, embeds, stickers, GIF media, bot messages, and DMs are ignored.
HTTP(S) and www. URLs are removed; readable Markdown link labels are retained.
Forwarded text is kept with its parent message. Whitespace is collapsed to keep
transcript entries on one line.
Requirements
- Linux with systemd running and sudo access for installation.
- Python 3.10 or newer, including curses, venv, and pip support.
- A Discord bot with Message Content Intent enabled and View Channel / Read Message History permissions in the channels being logged.
- Ollama and
qwen3:1.7bfor the analyzer; logging and sorting work without them.
On Debian/Ubuntu, install python3-venv if virtual environment support is missing.
Install
From a checkout of this repository:
cp channels.example.txt channels.txt
Edit channels.txt to list the channels to monitor. Create token.txt with your
Discord bot token using a text editor, then run as your normal account:
./install.sh
The installer creates .venv/, installs Python dependencies, adds commands in
/usr/local/bin/, and enables tdscls-logger.service at boot. It asks for sudo
credentials when installing system files. The service is system-wide, runs as
its installing account, and restarts on failure after five seconds.
| Command | Purpose |
|---|---|
tdscls |
Open the dialogue sorter |
tdscls-logger |
Show the logger's systemd status |
tdscls-analyze |
Open the chat analyzer |
Arguments are forwarded, for example tdscls-logger --no-pager or
tdscls-analyze --context 8192. Commands work from any directory provided
/usr/local/bin is on PATH. Keep the checkout at its installed location: the
launchers and service reference it directly, and data stays inside it.
Preview installation without changing system files:
./install.sh --dry-run
An existing foreground logger is left running. The service waits until it exits before taking over. That handoff involves a reconnect; it is not a zero-gap transition. A file lock prevents updated logger processes from writing the same logs concurrently. Reinstalling does not restart an already-active service.
The installer does not install Ollama or download models. Once Ollama is set up:
ollama pull qwen3:1.7b
Configure and manage the logger
channels.txt matches channel names, case-insensitively. A leading # is optional
and // starts a comment:
#general
#project-chat
//#disabled-channel
The same name can match channels in multiple servers; their logs are isolated by server and channel IDs. Configuration and code changes take effect on restart:
sudo systemctl restart tdscls-logger
Other service commands:
tdscls-logger
sudo journalctl -u tdscls-logger -f
sudo systemctl stop tdscls-logger
sudo systemctl start tdscls-logger
Stopping the service intentionally leaves it stopped. Failure restarts use a five-second delay without a start-rate limit that would abandon retries.
Transcripts and recovery
Each recorded channel has files under data/<server ID>/<channel ID>/:
| File | Contents |
|---|---|
general.txt |
Current messages, with edits applied and deletions removed |
general.txt.history |
Originals followed by edit/deletion records |
[1] Alice: Shall we run a workshop?
[2] [Replied to 1] Bob: Saturday works.
[3] Cara: [Forwarded message]
[3] [Forwarded text]: The room is booked.
Indices are never reused or renumbered. Replies to deleted targets are labeled,
for example [Replied to 1, deleted]. History retains earlier text and records
changes such as [2] [Edited] Bob: Sunday works. and [1] [Deleted].
On startup and reconnect:
- A channel with no recorded messages imports its most recent 50 Discord messages, oldest first. Filtering can result in fewer than 50 saved entries.
- An existing channel recovers all newer messages, with no 50-message cap, using its latest recorded creation date encoded in the Discord message ID. Deleted database entries still count as checkpoints.
Boundary overlap and ID deduplication prevent skipping messages from the same millisecond. Live events for a channel wait behind recovery to preserve order. Up to two channels recover concurrently, with batched writes. History request failures retry with backoff up to 60 seconds; other synchronized channels keep logging. Permission errors and recovery progress appear in the service journal.
Recovery cannot retrieve messages deleted from Discord before they were fetched. It does not reconcile offline edits/deletions to messages already recorded. Recovered messages contain their current text, not unavailable earlier versions. Matching cached active threads are supported; archived threads are not discovered.
data/state.sqlite3 holds message IDs, indices, current state, and history events.
Back it up with the transcripts. Text exports are rebuilt from it on startup;
manual changes to exports will be overwritten. Each file replacement is atomic,
while the current and history files are not replaced as a single transaction.
Group dialogue
tdscls
Choose a channel, or pass a current log explicitly:
tdscls data/<server-ID>/<channel-ID>/general.txt
Each message is one truncated user: message row. Forwarded quotations stay in
that row. Saved text is complete, with original message order preserved.
| Control | Action |
|---|---|
1–9 or click a group tab |
Choose the active group |
| Click a message / Space | Toggle selection into that group |
Wheel / Up / Down / k / j |
Scroll or move focus |
| Page Up / Page Down / Home / End | Navigate longer conversations |
s |
Save the current channel's selected groups |
r |
Refresh messages, preserving surviving selections |
c / Tab |
Switch channels; selections remain in memory |
? |
Help |
q |
Quit; repeat to discard unsaved selections |
Assigning a message to another group moves it. Each save creates a new batch:
sorting/<timestamp>/group1.txt
sorting/<timestamp>/group2.txt
Only nonempty groups are saved, as full user: message lines without indices or
reply metadata. The sorter reads a snapshot so new messages cannot move a row
under a click; use r to include changes. Selections are not restored after
quitting unless saved. It does not change the logger or its transcripts.
Options: --data-dir PATH and --output-dir PATH.
Summarize chats
tdscls-analyze
The file tree offers Unsorted channel logs and Sorted timestamp/group folders. Click a file to preview it, then double click or press Enter to select. History, databases, and incomplete exports are excluded.
| Control | Action |
|---|---|
Up / Down / k / j |
Navigate files or scroll the summary |
| Left / Right in the tree | Collapse / expand folders |
| Click a folder | Expand / collapse |
| Tab or Left / Right outside the tree | Choose an action button |
| Click a button / Enter | Activate the chosen action |
+ / - on the budget screen |
Change context preset: 2K, 4K, 8K, 16K, 32K |
| Wheel / Page Up / Page Down / Home / End | Scroll; End follows streamed output |
| Escape | Back, or cancel an active request |
s / d after generation |
Save / Done |
r in the tree |
Refresh files and previews |
q |
Quit and cancel any active request |
The context screen defaults to 4,096 tokens, reserving 1,024 tokens for the
summary plus a safety margin. The input estimate includes instructions, chat,
and a template allowance. It is approximate, not an exact Qwen tokenizer count.
Estimated overflow is blocked, and a recent Ollama version is required for the
request's truncate: false protection. The model's reported context limit is
checked before generation. Automatic splitting is not implemented.
Each analysis uses one frozen file snapshot and a fresh request. Thinking is disabled. The prompt requests only topics discussed, decisions made, and things done, without advice or next steps, and distinguishes proposals from decisions and plans from completed work. Review summaries for factual accuracy.
Responses stream into a scrollable, word-wrapped viewer. Done returns without saving. Save writes only the summary to:
summaries/<timestamp>/<source-name>-<timestamp>.txt
Repeated Save clicks for the same result reuse its file. Failed/cancelled requests cannot be saved; output-limit responses are labeled possibly incomplete. Unsaved results are lost on Done or Quit.
The app reuses Ollama or starts a local ollama serve if needed. It does not
download missing models or start a remote server. The model loads after Analyze
is chosen and unloads after a completed request to reduce memory use. CPU
inference uses at most four threads. Any server started remains available after
exit. Larger contexts consume more memory and compete for machine resources.
tdscls-analyze --context 8192 --response-tokens 1024
Additional options: --model, --host (defaults to OLLAMA_HOST or localhost
port 11434), --timeout (600 seconds), --no-start-server, --data-dir,
--sorting-dir, and --output-dir. Minimum terminal size: 66 columns × 14 rows.
Development
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python -m unittest discover -s tests -v
Apps can also run directly with .venv/bin/python main.py, sorter.py, or
analyze.py. Default file paths are relative to the project, not the shell's
working directory. Tests use temporary data and simulated Discord/Ollama
responses; they do not connect to your bot or stop its service.
Local files
The repository excludes token.txt, the active channels.txt, .env files,
virtual environments, and generated data/, sorting/, and summaries/ folders.
Use channels.example.txt as the shared configuration template. Keep local tokens
and captured conversations out of commits, and back up runtime data separately.