This repository was archived by the owner on Dec 24, 2021. It is now read-only.
This repository was archived by the owner on Dec 24, 2021. It is now read-only.
Argument type: duration #182
Open
Description
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:
"3w 1d 11 [many spaces]h \t30m 20s 5ms"
Methods:
- duration.toWeeks() -> float
- duration.toDays() -> float
- duration.toMinutes() -> float
- duration.toSeconds() -> float
- duration.toMilliseconds() -> float
And perhaps a few aliases:
- duration.toW()
- duration.toD()
- duration.toM()
- duration.toMs()
etc
Activity
greavettey commentedon Aug 26, 2018
This would make my bot so much cleaner haha!
[-]Add new argument type: duration[/-][+]Argument type: duration[/+]jonahsnider commentedon Dec 11, 2018
Would Commando handle parsing a duration itself or use an external package like
moment.js
ordate-fns
to handle it?brandonbothell commentedon Dec 11, 2018
Gawdl3y commentedon Dec 11, 2018
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.
MADLAB96 commentedon Mar 28, 2019
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
npm install
andnpm install discord.js
. I ran into the same errors withnpm link
to my own bot locally.NVM I found #215 and figured it out.
MADLAB96 commentedon Mar 28, 2019
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.
Jazcash commentedon Apr 3, 2019
This is the regex I'm using to parse duration in one of my bots, not sure if it's any help to anybody:
^(?:(?<weeks>\d+)w)?(?:((?<days>\d+)d)?(?:(?<hours>\d+)h)?(?:(?<minutes>\d+)m)?)$
E.g. 2w3d4h15m where any part is optional
jonahsnider commentedon Sep 6, 2019
Moment supports plugins which you can use to define new formats and date-fns lets you define a pattern for parsing dates.
MagnusHJensen commentedon Dec 23, 2020
I'm guessing this was dropped, by people who tried to make it work?
If so, I would like to give it a shot, and see what I can come up with.
#256 (Was this ever implemented?)
sriRacha21 commentedon Jan 29, 2021
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!
Nik0lovD commentedon Sep 25, 2021
I have the same errorhttps://prnt.sc/1tkskl4