-
-
Notifications
You must be signed in to change notification settings - Fork 40
fix(starboard): make starboard work in threads #937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideIntroduce a unified get_channel_safe helper in converters to abstract channel retrieval (including threads) with error handling, and refactor poll and starboard cogs to use it instead of inlined logic. Sequence diagram for unified channel retrieval with get_channel_safesequenceDiagram
participant Bot as Tux (bot)
participant get_channel_safe
participant DiscordAPI
participant Logger
Bot->>get_channel_safe: get_channel_safe(bot, channel_id)
get_channel_safe->>Bot: bot.get_channel(channel_id)
alt Channel found in cache
get_channel_safe-->>Bot: Return channel
else Channel not found
get_channel_safe->>DiscordAPI: fetch_channel(channel_id)
alt Channel fetched successfully
get_channel_safe-->>Bot: Return channel
else Channel not found or error
get_channel_safe->>Logger: Log error
get_channel_safe-->>Bot: Return None
end
end
Sequence diagram for starboard reaction handling with thread supportsequenceDiagram
participant StarboardCog
participant get_channel_safe
participant Logger
participant Channel as TextChannel/Thread
StarboardCog->>get_channel_safe: get_channel_safe(bot, payload.channel_id)
alt Channel found
get_channel_safe-->>StarboardCog: Channel (TextChannel or Thread)
StarboardCog->>Channel: fetch_message(payload.message_id)
else Channel not found
get_channel_safe-->>StarboardCog: None
StarboardCog->>Logger: Log error
end
Class diagram for get_channel_safe and channel retrievalclassDiagram
class Tux
class discord.TextChannel
class discord.Thread
class get_channel_safe {
+async get_channel_safe(bot: Tux, channel_id: int) discord.TextChannel | discord.Thread | None
}
Tux <|-- get_channel_safe
get_channel_safe --> discord.TextChannel
get_channel_safe --> discord.Thread
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @electron271 - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `tux/cogs/utility/poll.py:76` </location>
<code_context>
- channel = self.bot.get_channel(payload.channel_id)
- if not isinstance(channel, discord.TextChannel):
+ channel = await get_channel_safe(self.bot, payload.channel_id)
+ if channel is None:
+ logger.error(f"Channel with ID {payload.channel_id} not found.")
</code_context>
<issue_to_address>
Error logging is duplicated with get_channel_safe.
Consider removing the extra logger.error here to prevent duplicate log entries, as get_channel_safe already handles error logging.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if channel is None:
logger.error(f"Channel with ID {payload.channel_id} not found.")
return
=======
if channel is None:
return
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `tux/cogs/services/starboard.py:300` </location>
<code_context>
- channel = self.bot.get_channel(payload.channel_id)
- if not isinstance(channel, discord.TextChannel):
+ channel = await get_channel_safe(self.bot, payload.channel_id)
+ if channel is None:
+ logger.error(f"Channel with ID {payload.channel_id} not found.")
</code_context>
<issue_to_address>
Error logging may be redundant with get_channel_safe.
get_channel_safe already logs missing channels, so this additional log may be unnecessary. Please check if both are needed.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
channel = await get_channel_safe(self.bot, payload.channel_id)
if channel is None:
logger.error(f"Channel with ID {payload.channel_id} not found.")
return
=======
channel = await get_channel_safe(self.bot, payload.channel_id)
if channel is None:
return
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a helper to safely fetch text channels or threads and updates the poll and starboard cogs to use it, enabling starboard to work in threads.
- Added
get_channel_safeto abstract channel retrieval with error handling - Updated
poll.pyto useget_channel_safeinstead of inline fetching - Updated
starboard.pysimilarly to handle threads and reuse the new helper
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tux/utils/converters.py | Added get_channel_safe function and imported necessary tools |
| tux/cogs/utility/poll.py | Replaced manual channel lookup with get_channel_safe |
| tux/cogs/services/starboard.py | Swapped inline channel fetching for get_channel_safe |
Comments suppressed due to low confidence (3)
tux/utils/converters.py:82
- The new
get_channel_safefunction does not have accompanying tests. Consider adding unit tests for successful fetch, NotFound, and exception paths to ensure coverage.
async def get_channel_safe(bot: Tux, channel_id: int) -> discord.TextChannel | discord.Thread | None:
tux/cogs/utility/poll.py:78
- The
loggeris used here but not imported in this file, which will cause a NameError. Addfrom loguru import loggerat the top of the file.
logger.error(f"Channel with ID {payload.channel_id} not found.")
tux/cogs/services/starboard.py:302
- The
loggeris used here but not imported in this file, leading to a NameError. Please addfrom loguru import loggeralongside the other imports.
logger.error(f"Channel with ID {payload.channel_id} not found.")
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #937 +/- ##
========================================
+ Coverage 9.07% 9.31% +0.24%
========================================
Files 121 121
Lines 10272 10280 +8
Branches 1257 1258 +1
========================================
+ Hits 932 958 +26
+ Misses 9239 9220 -19
- Partials 101 102 +1
*This pull request uses carry forward flags. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Deploying tux with
|
| Latest commit: |
0073dfb
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f8e3fcc1.tux-afh.pages.dev |
| Branch Preview URL: | https://fix-starboard.tux-afh.pages.dev |
672760b to
0073dfb
Compare
feat(converters): add get_channel_safe function
Description
make starboard work in threads and add a get_channel_safe function to make some of this more abstracted
Guidelines
My code follows the style guidelines of this project (formatted with Ruff)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation if needed
My changes generate no new warnings
I have tested this change
Any dependent changes have been merged and published in downstream modules
I have added all appropriate labels to this PR
I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
tested in a channel and in thread, temporarily disabled self star protection so it would work
setup:
%starboard setup #starboard ⭐ 1Screenshots (if applicable)
Please add screenshots to help explain your changes.
Additional Information
Please add any other information that is important to this PR.
Summary by Sourcery
Add a safe channel retrieval helper and refactor channel-fetch logic to support thread messages for starboard and polling features, including error logging.
Bug Fixes:
Enhancements: