Skip to content

feat: 多帳號切換 + whoami,並修正版本/跨年日期比對 - #21

Merged
PttCodingMan merged 5 commits into
mainfrom
fix/version-compare-and-cross-year-date
Jul 20, 2026
Merged

feat: 多帳號切換 + whoami,並修正版本/跨年日期比對#21
PttCodingMan merged 5 commits into
mainfrom
fix/version-compare-and-cross-year-date

Conversation

@PttCodingMan

Copy link
Copy Markdown
Member

摘要

本分支累積了三塊獨立改動:

1. 修正版本比較與跨年日期比對 (f2c4458)

  • 修正 semver 比較邏輯
  • 修正跨年份的日期比對

2. 多帳號切換 (83d60e9)

  • 用單一環境變數 PTT_ACCOUNTS(名稱=帳號:密碼,名稱2=帳號2:密碼2)設定多組帳號,執行期切換,密碼不進對話
  • switch_account(name):切換到指定帳號並登入,會記住當前帳號
  • list_accounts():列出已設定帳號與目前使用中的帳號
  • 抽出共用登入核心 _perform_login()
  • 仍支援舊的 PTT_ID / PTT_PW,成為 default 帳號

3. whoami 工具 (122bcf4)

  • 回傳目前帳號標籤(來自 PTT_ACCOUNTS)、實際 PTT ID、登入狀態(直接向 PyPtt 查)
  • 登出後不回報殘留的 ptt_id

測試

  • test_parse_accounts.pytest_switch_account.pytest_whoami.py 全數通過(9 passed)
  • mypy 無問題;flake8 依 CI 設定通過

🤖 Generated with Claude Code

PttCodingMan and others added 5 commits June 29, 2026 21:39
- auto_version: compare versions via int tuples instead of stripping
  dots, which mis-ordered multi-digit segments (e.g. 0.2.15 vs 0.3.0).
- get_post_index_range: compare PTT list_date (yearless M/DD) by
  (month, day) only, so a target date carrying a non-current year no
  longer fails to match. Cross-year ranges remain unsupported (noted).
- Add assert-based self-checks for both.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CI runs flake8/mypy over the whole repo. The module-level sys.modules
stubbing before importing api_post triggered E402. Move it into a
helper function (function-level import is exempt) and use setattr for
the stub attribute to keep mypy's warn_unused_ignores happy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Configure multiple PTT accounts with a single PTT_ACCOUNTS env var
("name=id:pw,name2=id:pw2") and switch between them at runtime without
putting passwords in the conversation.

- switch_account(name): switch to a named account and log in; remembers it
- list_accounts(): list configured account names and the current one
- extract shared login core into _perform_login()
- legacy PTT_ID/PTT_PW still supported, becomes the "default" account

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Returns the current account label (from PTT_ACCOUNTS), the real PTT ID,
and login state queried directly from PyPtt. Does not report a stale
ptt_id after logout, since PyPtt leaves it set.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Keep one logged-in PyPtt.Service per account in a pool; switching just
repoints the active bot instead of logging out then re-logging in. A
failed switch no longer destroys the working session or repoints state
at the failed account, and Services that leave the pool are close()d
instead of leaked (they own a daemon thread + connection).

- _login_new_service builds+logs in a fresh Service, close()ing it on
  failure; _activate probes liveness (get_time) and re-logs a dead
  pooled session before repointing.
- switch_account/login go through _activate; logout closes just the
  active Service and drops it from the pool.
- list_accounts reports current=None when not actually logged in.
- mcp_server closes the whole pool at exit.

Addresses the switch-atomicity, Service-leak, and list_accounts
false-current findings from the branch review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@PttCodingMan
PttCodingMan merged commit 5b7d1a9 into main Jul 20, 2026
1 check passed
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