@@ -770,34 +770,34 @@ async def func(flt, client: pyrogram.Client, message: Message):
770770 nonlocal username
771771
772772 if username is None :
773- username = (await client .get_me ()).username
773+ username = (await client .get_me ()).username or ""
774774
775775 text = message .text or message .caption
776776 message .command = None
777777
778778 if not text :
779779 return False
780780
781- pattern = rf"^(?:{{cmd}}|{{cmd}}@{ username } )(?:\s|$)" if username else r"^{cmd}(?:\s|$)"
782-
783781 for prefix in flt .prefixes :
784782 if not text .startswith (prefix ):
785783 continue
786784
787785 without_prefix = text [len (prefix ):]
788786
789787 for cmd in flt .commands :
790- if not re .match (pattern . format ( cmd = re . escape ( cmd )) , without_prefix ,
788+ if not re .match (rf"^(?: { cmd } (?:@? { username } )?)(?:\s|$)" , without_prefix ,
791789 flags = re .IGNORECASE if not flt .case_sensitive else 0 ):
792790 continue
793791
792+ without_command = re .sub (rf"{ cmd } (?:@?{ username } )?\s" , "" , without_prefix , count = 1 )
793+
794794 # match.groups are 1-indexed, group(1) is the quote, group(2) is the text
795795 # between the quotes, group(3) is unquoted, whitespace-split text
796796
797797 # Remove the escape character from the arguments
798798 message .command = [cmd ] + [
799799 re .sub (r"\\([\"'])" , r"\1" , m .group (2 ) or m .group (3 ) or "" )
800- for m in command_re .finditer (without_prefix [ len ( cmd ):] )
800+ for m in command_re .finditer (without_command )
801801 ]
802802
803803 return True
0 commit comments