-
Notifications
You must be signed in to change notification settings - Fork 242
Argument type: duration #182
Comments
This would make my bot so much cleaner haha! |
Would Commando handle parsing a duration itself or use an external package like |
It should parse the duration itself. Cutting down dependencies is usually
welcome.
Edit: I've written some tentative regex (I wrote it on mobile, on a bus). It would look somewhat like this:
```javascript
/(\d+)\s*([A-Za-z]+)/g
```
Of course, I don't know how allowing the duration to have whitespace in it would effect arguments after it. We may need to disallow whitespace unless in quotes or brackets or something. Maybe some better regex would solve this problem.
…On Mon, Dec 10, 2018, 11:42 PM Jonah Snider ***@***.*** wrote:
Would Commando handle parsing a duration itself or use an external package
like moment.js or date-fns to handle it?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#182 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AiKPagU7_swl7tQjMAPp56NdB8yU_Pxzks5u3ze_gaJpZM4V4Ls9>
.
|
I'm not opposed to using moment, since it covers a lot of possible input formats, and handles localisation. The only problem is it doesn't take the "6mo3d4h50m30s" format... which is something that, ideally, would also accept locale-specific suffixes. |
Hi, I am working on a solution to this but I am having difficulty testing it locally. I'm currently attempting to run the test bot included but receiving this error:
This is after a NVM I found #215 and figured it out. |
Okay I have this mostly done but I can't seem to get the methods working. Just adding them to my DurationArgumentType class doesn't do the trick. I also didn't find any examples of class methods with the rest of the types. |
This is the regex I'm using to parse duration in one of my bots, not sure if it's any help to anybody:
E.g. 2w3d4h15m where any part is optional |
Moment supports plugins which you can use to define new formats and date-fns lets you define a pattern for parsing dates. |
I'm guessing this was dropped, by people who tried to make it work? |
I've given this a shot using code from my own bot (#366). I think this would make a great addition to Commando and would love to see any of the suggested implementations merged! |
I have the same errorhttps://prnt.sc/1tkskl4 |
The most of Discord bots are expected to provide "mute" and "ban" commands. Their implementation involves juggling with parsing strings just to get so-much-desired duration.
Formats:
Methods:
And perhaps a few aliases:
etc
The text was updated successfully, but these errors were encountered: