fix(platform.tg_adapter): import Forbidden instead of deprecated Unauthorized (#6765)#6769
fix(platform.tg_adapter): import Forbidden instead of deprecated Unauthorized (#6765)#6769Soulter merged 1 commit intoAstrBotDevs:masterfrom
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Now that
Forbiddenis used instead of the deprecatedUnauthorized, consider updating the log message to reflect the broader meaning ofForbidden(e.g., chat/bot restrictions) rather than only saying the token is invalid or unauthorized. - Depending on how
Forbiddenis raised by python-telegram-bot, you may want to distinguish between invalid token (InvalidToken) and other forbidden scenarios in separate except blocks so you can react or message users differently.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Now that `Forbidden` is used instead of the deprecated `Unauthorized`, consider updating the log message to reflect the broader meaning of `Forbidden` (e.g., chat/bot restrictions) rather than only saying the token is invalid or unauthorized.
- Depending on how `Forbidden` is raised by python-telegram-bot, you may want to distinguish between invalid token (`InvalidToken`) and other forbidden scenarios in separate except blocks so you can react or message users differently.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Pull request overview
Fixes the Telegram platform adapter failing to load with newer python-telegram-bot versions by replacing the deprecated/removed Unauthorized import/exception with Forbidden, aligning the adapter with the dependency version constraints.
Changes:
- Replace
telegram.error.Unauthorizedwithtelegram.error.Forbiddenin imports. - Update polling startup exception handling to catch
Forbiddeninstead ofUnauthorized.
There was a problem hiding this comment.
Code Review
This pull request correctly replaces the deprecated Unauthorized exception with Forbidden from the python-telegram-bot library. The changes in astrbot/core/platform/sources/telegram/tg_adapter.py are accurate and address the issue of using a deprecated API. The modifications are correct and align with the library's new API. I have reviewed the changes and found no issues.
Fix #6765 .
Modifications / 改动点
Edited file:
astrbot/core/platform/sources/telegram/tg_adapter.pyFunctions:
Nothing but use Forbidden instead of python-telegram-bot's deprecated Unauthorized to let telegram bot adapter work again.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Log:
Note:
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Bug Fixes: