Skip to content

Commit

Permalink
formatting; no longer using 'or' as a coalescing operator for boolean…
Browse files Browse the repository at this point in the history
…s as it causes bugs (duuuh)
  • Loading branch information
Ereiarrus committed Feb 5, 2024
1 parent 5a5bd99 commit 41d7b1c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
15 changes: 11 additions & 4 deletions src/complements_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,20 @@ class DoIfElse:
"""

def __init__(self,
if_check: Union[Callable[[commands.Context], Awaitable[bool]], Callable[[commands.Context], bool]],
if_check: Union[
Callable[[commands.Context], Awaitable[bool]],
Callable[[commands.Context], bool]
],
true_msg: Optional[str],
false_msg: Optional[str],
do_true: Optional[Union[
Callable[[commands.Context], Awaitable[None]], Callable[[commands.Context], None]]] = None,
do_false: Optional[Union[Callable[[commands.Context], Awaitable[None]], Callable[
[commands.Context], None]]] = None) -> None:
Callable[[commands.Context], Awaitable[None]],
Callable[[commands.Context], None]
]] = None,
do_false: Optional[Union[
Callable[[commands.Context], Awaitable[None]],
Callable[[commands.Context], None]
]] = None) -> None:
"""
:param if_check: what the condition for entering 'if' statement is
:param do_true: what to do when the if_check succeeds (done before sending message to chat);
Expand Down
32 changes: 18 additions & 14 deletions src/complements_bot/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ async def get_tts_mute_prefix(username: Optional[str] = None, userid: Optional[s

if not userid:
userid = await run_with_appropriate_awaiting(name_to_id, username)
prefix = (await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_MUTE_PREFIX).get)
or _DEFAULT_TTS_IGNORE_PREFIX)
return prefix
prefix: Optional[str] = await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_MUTE_PREFIX).get)
prefix = _DEFAULT_TTS_IGNORE_PREFIX if prefix is None else prefix
return str(prefix)


async def set_complement_chance(chance: float, username: Optional[str] = None, userid: Optional[str] = None,
Expand Down Expand Up @@ -378,9 +378,10 @@ async def get_complement_chance(username: Optional[str] = None, userid: Optional

if not userid:
userid = await run_with_appropriate_awaiting(name_to_id, username)
chance = (await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_COMPLEMENT_CHANCE).get)
or _DEFAULT_COMPLEMENT_CHANCE)
return chance
chance: Optional[float] = \
await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_COMPLEMENT_CHANCE).get)
chance = _DEFAULT_COMPLEMENT_CHANCE if chance is None else chance
return float(chance)


async def set_cmd_complement_enabled(is_enabled: bool, username: Optional[str] = None, userid: Optional[str] = None,
Expand Down Expand Up @@ -419,9 +420,10 @@ async def get_cmd_complement_enabled(username: Optional[str] = None, userid: Opt

if not userid:
userid = await run_with_appropriate_awaiting(name_to_id, username)
is_enabled = (await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_COMMAND_COMPLEMENT_ENABLED).get)
or _DEFAULT_COMMAND_COMPLEMENT_ENABLED)
return is_enabled
is_enabled: Optional[bool] = \
await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_COMMAND_COMPLEMENT_ENABLED).get)
is_enabled = _DEFAULT_COMMAND_COMPLEMENT_ENABLED if is_enabled is None else is_enabled
return bool(is_enabled)


async def set_random_complement_enabled(is_enabled: bool, username: Optional[str] = None, userid: Optional[str] = None,
Expand Down Expand Up @@ -460,9 +462,10 @@ async def get_random_complement_enabled(username: Optional[str] = None, userid:

if not userid:
userid = await run_with_appropriate_awaiting(name_to_id, username)
is_enabled = (await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_RANDOM_COMPLEMENT_ENABLED).get)
or _DEFAULT_RANDOM_COMPLEMENT_ENABLED)
return is_enabled
is_enabled: Optional[bool] = \
await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_RANDOM_COMPLEMENT_ENABLED).get)
is_enabled = _DEFAULT_RANDOM_COMPLEMENT_ENABLED if is_enabled is None else is_enabled
return bool(is_enabled)


async def add_complement(complement: str, username: Optional[str] = None, userid: Optional[str] = None,
Expand Down Expand Up @@ -683,8 +686,9 @@ async def are_default_complements_enabled(username: Optional[str] = None, userid

if not userid:
userid = await run_with_appropriate_awaiting(name_to_id, username)
is_enabled = (await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_DEFAULT_COMPLEMENTS_ENABLED).get)
or _DEFAULT_DEFAULT_COMPLEMENTS_ENABLED)
is_enabled: Optional[bool] = \
await _event_loop.run_in_executor(None, _USERS_DB_REF.child(userid).child(_DEFAULT_COMPLEMENTS_ENABLED).get)
is_enabled = _DEFAULT_DEFAULT_COMPLEMENTS_ENABLED if is_enabled is None else is_enabled
return bool(is_enabled)


Expand Down

0 comments on commit 41d7b1c

Please sign in to comment.