zekroTJA / shinpuru

シンプル - Discord Bot with role selection, moderation, karma ranking, a starboard, code execution, raid alerting, backups, a web interface, twitch notifications and more!
https://shnp.de
MIT License
190 stars 37 forks source link

Improve Duration decoding #372

Closed zekroTJA closed 2 years ago

zekroTJA commented 2 years ago

Type

UI/UX Enhancement

Description

Currently, commands which take time spans as parameter should also be able to handle time formats like days d or weeks w and should generally be less strictive as the default Go implementation.

Attachments

Idea

This could be easily achieved using the following regex.

(?Uis)(?:(?<w>\d+)w)?(?:(?<d>\d+)d)?(?:(?<h>\d+)h)?(?:(?<m>\d+)m)?(?:(?<s>\d+)s)?
lus commented 2 years ago

You could also use https://github.com/karrick/tparse like I did in one of my projects: https://github.com/lus/jacques/blob/main/internal/discord/reminder.go#L107

This package implements more advanced duration notations (you could actually provide 1d-1h and would end up with a duration of 23 hours).

zekroTJA commented 2 years ago

Yeah, thank you for the recommendation, but I already implemented something to handle it. ^^