[Trivia] Add support for payout to multiple trivia winners #4649

Merged
leblancg merged 5 commits from V3/develop into V3/develop 2021-01-17 23:32:04 +01:00
leblancg commented 2020-12-02 09:33:15 +01:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

This PR is for issue #3931. These changes allow for more than one winner of the trivia game. Each winner will receive an even split of the payout. This also adds a new message to congratulate the winner(s).

### Type - [ ] Bugfix - [x] Enhancement - [ ] New feature ### Description of the changes This PR is for issue #3931. These changes allow for more than one winner of the trivia game. Each winner will receive an even split of the payout. This also adds a new message to congratulate the winner(s).
leblancg commented 2020-12-02 09:41:05 +01:00 (Migrated from github.com)

I've tested it out on my own, but is any additional QA recommended? Not really sure how to unit test this using pytest.

I've tested it out on my own, but is any additional QA recommended? Not really sure how to unit test this using pytest.
Jackenmen commented 2020-12-02 09:52:35 +01:00 (Migrated from github.com)

There's no need for making unit tests here, PRs are reviewed by one of our Core Dev/QA members.

There's no need for making unit tests here, PRs are reviewed by one of our Core Dev/QA members.
Jackenmen (Migrated from github.com) requested changes 2020-12-18 03:06:23 +01:00
Jackenmen (Migrated from github.com) left a comment

This is a really clean solution, the code also seems more readable than what's been there before 😄

The new functionality appears to work fine however, I got a few review comments before I can approve this.

This is a really clean solution, the code also seems more readable than what's been there before 😄 The new functionality appears to work fine however, I got a few review comments before I can approve this.
@ -281,42 +281,57 @@ class TriviaSession:
channel = self.ctx.channel
LOG.debug("Force stopping trivia session; #%s in %s", channel, channel.guild.id)
Jackenmen (Migrated from github.com) commented 2020-12-18 02:22:21 +01:00

According to our style guide, the fact that empty sequences evaluate to false should be used instead of len() (you can see PEP 8 for more information)

        if not winners or num_humans < 3:
According to our style guide, the fact that empty sequences evaluate to false should be used instead of `len()` (you can see PEP 8 for more information) ```suggestion if not winners or num_humans < 3: ```
Jackenmen (Migrated from github.com) commented 2020-12-18 02:34:23 +01:00

There's a few things with how this message is defined that need to be changed:

  1. _() is a call to Translator object defined at the top of the file and is needed in order for the string to be translated when there's a translated version available.
  2. Instead of .join(), we have a humanize_list() utility function that formats a list according to formatting rules of the locale in use.
  3. To support plural rules properly with translations, the string for a single user should be a separate from the string for multiple users as it allows translators to make more appropriate translations. While that is not perfect (Red currently doesn't support tools that would be more appropriate for this), it's still better for translating than using a single string with a {plural} format field.
        if len(winners) > 1:
            msg = _(
                "Congratulations {users}! You have each received {num} {currency} for winning!"
            ).format(
                users=humanize_list([bold(winner.display_name) for winner in winners]),
                num=payout,
                currency=await bank.get_currency_name(self.ctx.guild),
            )
        else:
            msg =  _(
                "Congratulations {user}! You have received {num} {currency} for winning!"
            ).format(
                user=bold(winners[0].display_name),
                num=payout,
                currency=await bank.get_currency_name(self.ctx.guild),
            )
        await self.ctx.send(msg)
There's a few things with how this message is defined that need to be changed: 1. `_()` is a call to Translator object defined at the top of the file and is needed in order for the string to be translated when there's a translated version available. 2. Instead of `.join()`, we have a `humanize_list()` utility function that formats a list according to formatting rules of the locale in use. 3. To support plural rules properly with translations, the string for a single user should be a separate from the string for multiple users as it allows translators to make more appropriate translations. While that is not perfect (Red currently doesn't support tools that would be more appropriate for this), it's still better for translating than using a single string with a `{plural}` format field. ```suggestion if len(winners) > 1: msg = _( "Congratulations {users}! You have each received {num} {currency} for winning!" ).format( users=humanize_list([bold(winner.display_name) for winner in winners]), num=payout, currency=await bank.get_currency_name(self.ctx.guild), ) else: msg = _( "Congratulations {user}! You have received {num} {currency} for winning!" ).format( user=bold(winners[0].display_name), num=payout, currency=await bank.get_currency_name(self.ctx.guild), ) await self.ctx.send(msg) ```
Jackenmen (Migrated from github.com) commented 2020-12-18 02:40:04 +01:00

Since this is not a public API, it would be clearer if this got renamed to pay_winners() and the usage of it got updated appropriately.

    async def pay_winners(self, multiplier: float):
Since this is not a public API, it would be clearer if this got renamed to `pay_winners()` and the usage of it got updated appropriately. ```suggestion async def pay_winners(self, multiplier: float): ```
Jackenmen (Migrated from github.com) approved these changes 2021-01-17 23:21:04 +01:00
Jackenmen (Migrated from github.com) left a comment

I went ahead and made the appropriate changes on my own and this is now ready to be merged.
Thanks for your contribution!

I went ahead and made the appropriate changes on my own and this is now ready to be merged. Thanks for your contribution!
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!4649
No description provided.