Add a timedelta converter #2736

Merged
DiscordLiz merged 3 commits from timedelta-converter into V3/develop 2019-05-28 18:43:55 +02:00
DiscordLiz commented 2019-05-28 04:45:55 +02:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

This reuses a lot of logic from @mikeshardmind 's scheduler cog with permission

It adds a timedelta converter
It keeps it generalized as requested
It keeps the function available for non converter use as requested

### Type - [ ] Bugfix - [ ] Enhancement - [X] New feature ### Description of the changes This reuses a lot of logic from @mikeshardmind 's scheduler cog with permission It adds a timedelta converter It keeps it generalized as requested It keeps the function available for non converter use as requested
mikeshardmind (Migrated from github.com) requested changes 2019-05-28 08:42:19 +02:00
mikeshardmind (Migrated from github.com) left a comment

There are a couple of things which need fixing, beyond that I think the arguments other than the user input here are better suited as keyword only in all instances for the timedelta conversion stuff.

There are a couple of things which need fixing, beyond that I think the arguments other than the user input here are better suited as keyword only in all instances for the timedelta conversion stuff.
@ -1,5 +1,6 @@
import re
mikeshardmind (Migrated from github.com) commented 2019-05-28 08:31:32 +02:00
    allowed_units : Optional[List[str]]
```suggestion allowed_units : Optional[List[str]] ```
mikeshardmind (Migrated from github.com) commented 2019-05-28 08:41:18 +02:00

you've put these in the wrong order for the signature of the class

you've put these in the wrong order for the signature of the class
DevilXD (Migrated from github.com) requested changes 2019-05-28 17:02:12 +02:00
DevilXD (Migrated from github.com) commented 2019-05-28 17:00:39 +02:00

Hmm, what about adding something along the lines of a default_unit, that would be used when the argument parsed would be an integer only?

This would be really helpful for other cogs where passing just a number would default to the unit specified, while passing numbers with units would be converted as it currently is now.

The argument could easily be checked with argument.isdigit() to determine if it should be parsed with default_unit or not.

Finally, setting default_unit to None (probably by default) would disable this additional functionality altogether.

Hmm, what about adding something along the lines of a `default_unit`, that would be used when the argument parsed would be an integer only? This would be really helpful for other cogs where passing just a number would default to the unit specified, while passing numbers with units would be converted as it currently is now. The argument could easily be checked with `argument.isdigit()` to determine if it should be parsed with `default_unit` or not. Finally, setting `default_unit` to `None` (probably by default) would disable this additional functionality altogether.
DiscordLiz (Migrated from github.com) reviewed 2019-05-28 18:33:54 +02:00
DiscordLiz (Migrated from github.com) commented 2019-05-28 18:33:54 +02:00

Is there any benefit to this beyond not using a union converter? I don't think guessing or assuming units in a converter designed to accept multiple is a good idea.

Is there any benefit to this beyond not using a union converter? I don't think guessing or assuming units in a converter designed to accept multiple is a good idea.
mikeshardmind (Migrated from github.com) reviewed 2019-05-28 18:40:37 +02:00
mikeshardmind (Migrated from github.com) commented 2019-05-28 18:40:37 +02:00

I somewhat agree, except in the case of being guaranteed a specific type rather either using an int converter or needing to write a custom converter on top of this for that case.

I'm not completely made up on this either way, and think that while it's worth discussion, it's not worth delaying the addition since it can be added non-breakingly later, and in the mean time there are other options for this specific case.

I somewhat agree, except in the case of being guaranteed a specific type rather either using an int converter or needing to write a custom converter on top of this for that case. I'm not completely made up on this either way, and think that while it's worth discussion, it's not worth delaying the addition since it can be added non-breakingly later, and in the mean time there are other options for this specific case.
mikeshardmind (Migrated from github.com) approved these changes 2019-05-28 18:43:40 +02:00
mikeshardmind (Migrated from github.com) left a comment

This is ready to go, there may be more to add to this later, but it's in a good place to get people using it for now.

This is ready to go, there may be more to add to this later, but it's in a good place to get people using it for now.
Sign in to join this conversation.
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!2736
No description provided.