feat(commands/utils/tokenize): add remove_prefix parameter

This commit is contained in:
Ryan 2025-01-23 14:50:39 -05:00
parent 3930175c79
commit 0e69a039a1
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 8 additions and 3 deletions

View File

@ -55,14 +55,17 @@ def match(command: str) -> list[Command] | None:
@lru_cache
def tokenize(string: str) -> list[str]:
def tokenize(string: str, remove_prefix: bool = True) -> list[str]:
tokens = []
token = ""
in_quotes = False
quote_char = None
escape = False
for char in string[len(constants.PREFIX) :]:
if remove_prefix:
string = string[len(constants.PREFIX) :]
for char in string:
if escape:
token += char
escape = False

4
fun.py
View File

@ -1,7 +1,9 @@
import random
import commands
async def on_message(message):
if "gn" in message.content:
if "gn" in commands.tokenize(message.content, remove_prefix=False):
if random.random() < 0.01:
await message.add_reaction(random.choice(["💤", "😪", "😴", "🛌"]))