-
-
Notifications
You must be signed in to change notification settings - Fork 12
Add premium button #83
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 Guide by SourceryThis pull request introduces a new File-Level Changes
Tips
|
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 @f4b1ii - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 3 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
""" | ||
super().__init__(custom_id=custom_id, disabled=disabled) | ||
self.style: ButtonStyle = try_enum(ButtonStyle, style) | ||
if not emoji and not label: | ||
raise InvalidArgument('A button must have at least one of label or emoji set') | ||
if self.style.Premium and not sku_id: |
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.
issue (bug_risk): Check for 'Premium' should use 'ButtonStyle.Premium'
The check for 'self.style.Premium' should be 'self.style == ButtonStyle.Premium' to ensure it is comparing against the correct enum value.
raise InvalidArgument('A button must have at least one of label or emoji set') | ||
if self.style.Premium and not sku_id: | ||
raise InvalidArgument("An sku_id must be specified for premium buttons") | ||
elif sku_id and not self.style.Premium: |
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.
issue: Check for 'Premium' should use 'ButtonStyle.Premium'
The check for 'not self.style.Premium' should be 'self.style != ButtonStyle.Premium' to ensure it is comparing against the correct enum value.
discord/components.py
Outdated
@@ -399,6 +422,9 @@ def to_dict(self) -> ButtonPayload: | |||
base['url'] = self.url | |||
if self.emoji: | |||
base['emoji'] = self.emoji.to_dict() | |||
if self.sku_id: | |||
base['sku_id'] = str(self.sku_id) | |||
del base['label'] |
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.
suggestion: Consider handling other attributes
Consider also deleting 'custom_id', 'url', and 'emoji' from 'base' if 'sku_id' is present to ensure consistency with the premium button constraints.
del base['label'] | |
del base['label'] | |
if 'custom_id' in base: | |
del base['custom_id'] | |
if 'url' in base: | |
del base['url'] | |
if 'emoji' in base: | |
del base['emoji'] |
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.
Looks good :) Thank you
This commit adds discord.ButtonStyle.Premium and the corresponing changes for the discord.Button class.
I couldn't really test this any further as to the point where I could send a call to Discord's API with all the necessary parameters, but since I don't have access to an app with SUKs, I don't know if this actually works.
Summary by Sourcery
This pull request adds support for a new premium button style in Discord buttons, including the necessary changes to the Button class to handle SKU identifiers and enforce validation rules.