-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
boolean setting filter, split filters into own files
- Loading branch information
Showing
7 changed files
with
343 additions
and
268 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Setting filters module""" | ||
|
||
from .boolean_filter import BooleanFilter | ||
from .channel_filter import ChannelFilter | ||
from .role_filter import RoleFilter | ||
from .seconds_filter import SecondsFilter | ||
from .setting_filter import SettingFilter | ||
|
||
__all__ = ( | ||
"BooleanFilter", | ||
"ChannelFilter", | ||
"RoleFilter", | ||
"SecondsFilter", | ||
"SettingFilter", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Boolean setting filter""" | ||
|
||
# 3rd party | ||
from discord.ext.commands import Context | ||
|
||
# local | ||
from .setting_filter import SettingFilter | ||
|
||
|
||
class BooleanFilter(SettingFilter): | ||
|
||
"""Filter used for converting strings to boolean values""" | ||
|
||
def __init__(self, setting: str): | ||
super().__init__(setting) | ||
|
||
def in_(self, ctx: Context, value: str | None) -> bool | None: | ||
""" | ||
Filter setting input. | ||
Args: | ||
ctx: The current context | ||
value: The incoming value | ||
Returns: | ||
The raw setting value (a boolean) | ||
""" | ||
|
||
if not value: | ||
return | ||
|
||
return bool(value) | ||
|
||
def out( | ||
self, | ||
ctx: Context, | ||
value: bool | None, | ||
) -> bool | None: | ||
""" | ||
Filter setting output. | ||
Args: | ||
ctx: The current context | ||
value: The raw setting value (a boolean) | ||
Returns: | ||
The raw setting value | ||
""" | ||
|
||
return value |
Oops, something went wrong.