-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
beginning refactor to separate twitch action with internal action
- Loading branch information
Ereiarrus
committed
Feb 4, 2024
1 parent
e47c6e8
commit 6a7c20f
Showing
2 changed files
with
65 additions
and
62 deletions.
There are no files selected for viewing
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
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,44 @@ | ||
""" | ||
Holds all logic for how ComplementsBot should complement Twitch chatters | ||
""" | ||
import asyncio | ||
from typing import Awaitable, Callable, Optional, Tuple, Union | ||
|
||
|
||
def custom_log(msg: str) -> None: | ||
""" | ||
Any messages which we want to log should be passed through this method | ||
""" | ||
|
||
print(msg) | ||
|
||
|
||
def is_bot(username: str) -> bool: | ||
""" | ||
checks if a username matches that of a known or assumed bot; currently the following count as bots: | ||
- any username ending in 'bot' | ||
- streamlabs | ||
""" | ||
|
||
return (len(username) >= 3 and username[-3:].lower() == 'bot' or | ||
username in ("streamlabs", "streamelements")) | ||
|
||
|
||
def isolate_args(full_cmd_msg: str) -> str: | ||
""" | ||
:param full_cmd_msg: the command message which includes the command name itself | ||
:return: removes the '!command' part of the msg along with exactly one single space after it | ||
""" | ||
|
||
full_cmd_msg = full_cmd_msg.strip() | ||
# ^ Twitch should already do this before getting | ||
# the message, but just done in case they don't | ||
|
||
first_space_at: int = full_cmd_msg.find(" ") | ||
space_found: bool = first_space_at >= 0 | ||
|
||
if not space_found: | ||
return "" | ||
|
||
# won't give 'index out of range' as message can't end on a space due to the strip() | ||
return full_cmd_msg[first_space_at + 1:] |