feat(commands/utils/tokenize): add remove_prefix parameter
This commit is contained in:
parent
3930175c79
commit
0e69a039a1
@ -55,14 +55,17 @@ def match(command: str) -> list[Command] | None:
|
|||||||
|
|
||||||
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def tokenize(string: str) -> list[str]:
|
def tokenize(string: str, remove_prefix: bool = True) -> list[str]:
|
||||||
tokens = []
|
tokens = []
|
||||||
token = ""
|
token = ""
|
||||||
in_quotes = False
|
in_quotes = False
|
||||||
quote_char = None
|
quote_char = None
|
||||||
escape = False
|
escape = False
|
||||||
|
|
||||||
for char in string[len(constants.PREFIX) :]:
|
if remove_prefix:
|
||||||
|
string = string[len(constants.PREFIX) :]
|
||||||
|
|
||||||
|
for char in string:
|
||||||
if escape:
|
if escape:
|
||||||
token += char
|
token += char
|
||||||
escape = False
|
escape = False
|
||||||
|
4
fun.py
4
fun.py
@ -1,7 +1,9 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
|
import commands
|
||||||
|
|
||||||
|
|
||||||
async def on_message(message):
|
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:
|
if random.random() < 0.01:
|
||||||
await message.add_reaction(random.choice(["💤", "😪", "😴", "🛌"]))
|
await message.add_reaction(random.choice(["💤", "😪", "😴", "🛌"]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user