Skip to content

refactor: remove dead code and duplication across plugins, handlers, config#20

Merged
rezhajulio merged 4 commits into
mainfrom
chore/ponytail-cleanup
Jul 5, 2026
Merged

refactor: remove dead code and duplication across plugins, handlers, config#20
rezhajulio merged 4 commits into
mainfrom
chore/ponytail-cleanup

Conversation

@rezhajulio

Copy link
Copy Markdown
Owner

Summary

  • Removes dead code: unused PluginProtocol/facade classes, ADMIN_COMMANDS, write-only bio-bait metrics, unreferenced is_monitored/is_plugin_enabled/get_warnings_past_time_threshold, per-group trust NotImplementedError branches that were never exercised.
  • Consolidates duplicated boilerplate into shared helpers: admin/DM-target guard for verify/unverify/check commands, handler registration in commands/spam plugins, contact/inline-keyboard spam skeleton, captcha probation+challenge start, admin ID cache sync, group-config field copying, trusted-user cache get-or-create.
  • No behavior or user-facing text changes.

Test plan

  • uv run ruff check . — clean
  • uv run mypy src/bot/ tests/ — no issues in 68 source files
  • uv run pytest --cov=bot --cov-report=term-missing — 99% coverage maintained, all tests passing

…config

Deletes unused plugin protocol/facade classes, dead metrics and DB helpers,
and consolidates duplicated admin-guard, registration, and spam-handling
boilerplate into shared helpers. No behavior change; coverage held at 99%.
return message.forward_origin is not None


def has_link(message: Message) -> bool:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we remove this?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zero callers anywhere in src or tests — grepped the whole repo to confirm. Actual link/URL spam detection lives lower in this same file (entity-by-entity check against the whitelist), so has_link was a coarser, unused duplicate nothing ever called.

_get_user_bio_cache(context).pop(user_id, None)


def _get_bio_bait_metrics(context: ContextTypes.DEFAULT_TYPE) -> dict[str, int]:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we no longer use any metrics for bio bait spam/scam?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed via repo-wide grep: these were write-only counters in bot_data, incremented but never read anywhere — no /stats command, no export, no log line, no test asserting on them. Not wired to any consumer, so no metrics were actually lost.

…fig state

Docs had drifted from code: stale file line counts, a bypass_for/enabled_plugins
API that no longer exists, missing bio_bait.py handler/plugin, and undocumented
duplicate-spam/bio-bait/PLUGINS_DEFAULT env vars and GroupConfig fields.
Diagram predated the bio_bait.py handler; wire it in parallel to
contact-card spam, covering admin/trusted bypass and monitor-only mode.
Old diagram treated topic_guard, contact/inline/probation spam, and
profile checks as one sequential function; they're actually independent
PTB handlers at groups -1..5, each able to stop propagation. Rebuilt the
diagram around that real group order and added every branch that was
missing: inline_keyboard_spam, duplicate_spam, bio_bait, /check, /trust,
/untrust, /trusted, their button callbacks, the admin-refresh job, and
the accurate DM multi-group unrestriction loop.

Also flags a real registration bug found while verifying this: duplicate_spam
and bio_bait_spam are both registered at group=4 with the identical filter
(GROUPS & not COMMAND). PTB checks handlers in registration order and stops
after the first match (block defaults to True), and duplicate_spam is listed
before bio_bait_spam in MANIFEST_ORDER, so bio_bait_spam's handler never
actually runs.
@rezhajulio rezhajulio merged commit 339c78d into main Jul 5, 2026
5 checks passed
@rezhajulio rezhajulio deleted the chore/ponytail-cleanup branch July 5, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant