hikariatama / Hikka

The most fresh and updateable developer-oriented Telegram userbot
https://hikka.pw
GNU Affero General Public License v3.0
318 stars 516 forks source link

Config Command Suggestion #36

Closed anon97945 closed 2 years ago

anon97945 commented 2 years ago

Additional context Maybe something like this (or a better one)



> 
> def to_bool(value):
>     if str(value).lower() in ("true"):
>         return True
>     if str(value).lower() in ("false"):
>         return False

> if not isinstance(to_bool(args[1]), bool):
>   return await utils.answer(message, self.strings("error", message))
hikariatama commented 2 years ago

Ig it would be better to add some kind of validator to loader.ConfigValue. E.g. validator=loader.Boolean

anon97945 commented 2 years ago

If this would do the same, sure. I think you got my point. 👍🏻 the problem is that you need to check whether the module use yes/no, true/flase, int or whatever. Thatswhy check if default: is an boolean and then apply that validator.

Or make modules able to help your loader by something like possible arguements

hikariatama commented 2 years ago

[ ] Add validators to loader.ConfigValue, inc. native ones aka loader.validators.Int, .Boolean etc and custom ones via lambda expressions

hikariatama commented 2 years ago

Added to local branch, will be added in 1.0.23 loader.validators.Boolean, loader.validators.Integer, loader.validators.Choice