Metadata-Version: 2.4
Name: tg-cleaner
Version: 0.1.0
Summary: Clean up your Telegram from the terminal: leave dead chats, quiet unread channels, sort into folders.
Keywords: telegram,cleanup,folders,cli
Author: hillelGonen
License-Expression: MIT
License-File: LICENSE
Classifier: Environment :: Console
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Communications :: Chat
Requires-Dist: pydantic>=2.14.1
Requires-Dist: pydantic-settings>=2.16.1
Requires-Dist: python-bidi>=0.6.12
Requires-Dist: python-dotenv>=1.2.4
Requires-Dist: questionary>=2.1.1
Requires-Dist: rich>=15.0.0
Requires-Dist: telethon>=1.45.0
Requires-Dist: typer>=0.27.3
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/hillelGonen/telegram-cleaner
Project-URL: Issues, https://github.com/hillelGonen/telegram-cleaner/issues
Description-Content-Type: text/markdown

# telegram-cleaner

[![CI](https://github.com/hillelGonen/telegram-cleaner/actions/workflows/ci.yml/badge.svg)](https://github.com/hillelGonen/telegram-cleaner/actions/workflows/ci.yml)

A small menu that helps you clean up and organize Telegram: delete old chats, leave dead groups,
quiet noisy channels, and sort channels into folders.

## Install
```
pipx install tg-cleaner      # or: uv tool install tg-cleaner
tgo
```
Python 3.12+. Plain `pip install tg-cleaner` works too; pipx/uv keep the tool in its own
environment. Latest code straight from GitHub:
`pipx install git+https://github.com/hillelGonen/telegram-cleaner`

On first run `tgo` asks for your Telegram API id and hash (get them at https://my.telegram.org →
"API development tools") and saves them to `~/.tgo/.env`. Your login and data live in `~/.tgo/`,
readable only by you. `~/.tgo/data/tgo.session` gives full access to your account; never share it.

Update: `pipx upgrade tg-cleaner` · Remove: `pipx uninstall tg-cleaner` (then delete `~/.tgo`).
With uv: `uv tool upgrade tg-cleaner` / `uv tool uninstall tg-cleaner`.

## Use
```
tgo
```
First time it asks you to log in (phone, code from Telegram, 2FA password if set).
It reads your chats (again whenever the last read is over an hour old), then shows:

| Menu | What it does |
|---|---|
| 📊 Overview | Counts: channels, groups, private chats, bots; dead (1y+), noisy (1000+ unread), in no folder; folders |
| 🧹 Clean up old chats | Pick types (or All types) + age (1 month … 2 years) → delete/leave, archive or mute |
| 📭 Channels & groups I don't read | 50 / 100 / 300 / 1000+ unread (they still post, you don't read) → leave, mute, archive or mark read |
| 📁 Sort into folders | Pick a folder (or make one), type words like `news חדשות أخبار` → matching channels are added |
| ↩️ Undo | Undo the last folder change or last archive/mute; list chats you left with rejoin links |
| 🔄 Rescan now | Read your chats again |

Every action shows the list first. You can take all, untick some, or cancel, and then confirm
with y/N. Nothing happens before that.

Other command: `tgo logout`.

## Safety
- Never touched: chats/groups you own, pinned chats, Saved Messages, Telegram's service chat.
- **Leaving / deleting can't be undone.** Public chats can be rejoined from the links in Undo;
  private channels/groups need a new invite link. Deleting a private chat removes its history
  for you only.
- Folder changes save a full backup first (`data/backups/`), so Undo restores them exactly.
  Only the folder's chat list changes; its flags, pins, icon and color stay.
- Every action is logged in `data/actions.jsonl`.
- Ctrl+C anytime. Chats already done are saved, so running again continues where you stopped.

## Hebrew / Arabic
Titles are flipped for terminals that print right-to-left text backwards (macOS Terminal, most).
If yours already shows RTL correctly (text looks reversed), set `TGO_BIDI=false` in `.env`.

## Code layout
```
src/tgo/
  cli.py           entry: `tgo` opens the menu, `tgo logout`
  menu.py          TgoApp: the menu screens
  prompter.py      Prompter protocol + QuestionaryPrompter (arrow-key menus)
  views.py         Rich tables/messages
  settings.py      Settings (.env)
  models.py        Chat, Folder, FolderFlags, FolderLimits (Pydantic)
  telegram.py      TelegramGateway (all network) + TelethonMapper
  repository.py    Repository (SQLite)
  scanner.py       Scanner (Telegram -> Repository)
  selection.py     ChatFilter + ChatSelector (protected chats)
  cleanup.py       CleanupExecutor + ActionLog (batches, undo)
  applier.py       FolderEditor (add to folder), Restorer (undo)
  backup.py        FolderBackup + BackupStore
  folder_index.py  which folders show each chat
  report.py        counts for the overview
  text.py          bidi + markup escaping
```

## Development
Release: bump `version` in pyproject.toml, commit, then `git tag vX.Y.Z && git push --tags`;
the Publish workflow tests, builds and uploads to PyPI.

```
git clone https://github.com/hillelGonen/telegram-cleaner && cd telegram-cleaner
uv sync
uv run tgo           # run from the checkout (uses ./data if it exists, else ~/.tgo/data)
uv run pytest        # tests (no Telegram account needed; Telegram is faked)
uv run ruff check .  # lint
```
CI runs both on every push.

## License
MIT, see [LICENSE](LICENSE).
