Skip to content

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

Merged
merged 3 commits into from
Jun 29, 2024
Merged

Add premium button #83

merged 3 commits into from
Jun 29, 2024

Conversation

f4b1ii
Copy link

@f4b1ii f4b1ii commented Jun 29, 2024

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.

  • New Features:
    • Introduced a new ButtonStyle.Premium for Discord buttons, allowing the creation of premium buttons with SKU identifiers.
  • Enhancements:
    • Updated the Button class to support the new premium button style, including validation rules for SKU identifiers and other button attributes.
Copy link

sourcery-ai bot commented Jun 29, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new ButtonStyle.Premium to the discord.Button class, along with the necessary changes to support this new button style. The changes include adding a new sku_id attribute to the Button class, updating the constructor and validation logic, and modifying the to_dict method to handle the new attribute.

File-Level Changes

Files Changes
discord/components.py
discord/enums.py
Introduced ButtonStyle.Premium and added support for it in the Button class, including a new sku_id attribute and corresponding validation and serialization logic.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.
Copy link

@sourcery-ai sourcery-ai bot left a 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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:
Copy link

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:
Copy link

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.

@@ -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']
Copy link

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.

Suggested change
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']
Copy link
Owner

@mccoderpy mccoderpy left a 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

@mccoderpy mccoderpy merged commit 181e3cd into mccoderpy:developer Jun 29, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants