async def func(flt, _, message: Message): text: str = message.text or message.caption message.command = None if not text: return False regex = "^({prefix})+\\b({regex})\\b(\\b@{bot_name}\\b)?(.*)".format( prefix="|".join(re.escape(x) for x in Command), regex="|".join(flt.commands).lower(), bot_name=BOT_USERNAME, ) matches = re.search(re.compile(regex), text.lower()) if matches: message.command = [matches.group(2)] try: for arg in shlex.split(matches.group(4).strip()): if arg == BOT_USERNAME: continue message.command.append(arg) except ValueError: return True return True return False
async def func(flt, _, message: Message): text = message.text or message.caption message.command = None if not text: return False pattern = r"^{}(?:\s|$)" if flt.case_sensitive else r"(?i)^{}(?:\s|$)" for prefix in flt.prefixes: if not text.startswith(prefix): continue without_prefix = text[len(prefix):] for cmd in flt.commands: if not re.match(pattern.format(re.escape(cmd)), without_prefix): continue # match.groups are 1-indexed, group(1) is the quote, group(2) is the text # between the quotes, group(3) is unquoted, whitespace-split text # Remove the escape character from the arguments message.command = [cmd] + [ re.sub(r"\\([\"'])", r"\1", m.group(2) or m.group(3) or "") for m in command_re.finditer(without_prefix[len(cmd):]) ] return True return False
async def func(flt, client, message: Message): if message.scheduled: # allow to trigger commands! return False # don't get triggered when the message is scheduled, only when it's sent! This allows scheduling actions text = message.text or message.caption message.command = None if not text: return False pattern = r"^{cmd}(?:@{uname}|)(?:\s|$)" if flt.case_sensitive else r"(?i)^{cmd}(?:@{uname}+|)(?:\s|$)" for prefix in flt.prefixes: if not text.startswith(prefix): continue without_prefix = text[len(prefix):] my_username = client.me.username if hasattr(client, "me") else (await client.get_me()).username for cmd in flt.commands: if not re.match(pattern.format(cmd=re.escape(cmd), uname=my_username), without_prefix): continue without_cmd = re.sub("^@[^ ]+", "", without_prefix[len(cmd):])[1:] # remove 1st whitespace # match.groups are 1-indexed, group(1) is the quote, group(2) is the text # between the quotes, group(3) is unquoted, whitespace-split text # Remove the escape character from the arguments match_list = [ re.sub(r"\\([\"'])", r"\1", m.group(2) or m.group(3) or "") for m in command_re.finditer(without_cmd) ] raw_buf = ConsumableBuffer(without_cmd) message.command = CommandMatch(cmd) while len(match_list) > 0: token = match_list.pop(0) if token in flt.flags: raw_buf.consume(token) message.command.flags.append(token) continue found = False for opt in flt.options: if token in flt.options[opt]: found = True val = match_list.pop(0) # pop the value raw_buf.consume([token, val]) message.command.options[opt] = val break if found: continue message.command.arg.append(token) message.command.text = str(raw_buf).strip() return True return False
async def func(flt, _, m: Message): if not m.from_user: return False if m.from_user.is_bot: return False if any([m.forward_from_chat, m.forward_from]): return False if dev_cmd and (m.from_user.id not in DEV_LEVEL): # Only devs allowed to use this...! return False if sudo_cmd and (m.from_user.id not in SUDO_LEVEL): # Only sudos and above allowed to use it return False text: str = m.text or m.caption m.command = None if not text: return False regex = "^({prefix})+\\b({regex})\\b(\\b@{bot_name}\\b)?(.*)".format( prefix="|".join(escape(x) for x in flt.prefixes), regex="|".join(flt.commands), bot_name=BOT_USERNAME, ) matches = search(compile_re(regex), text) if matches: m.command = [matches.group(2)] matches = (matches.group(4)).replace( "'", "\\'", ) # fix for shlex qoutation error, majorly in filters db = Disabling(m.chat.id) disable_list = db.get_disabled() status = db.get_action() try: user_status = (await m.chat.get_member(m.from_user.id)).status except ValueError: # i.e. PM user_status = "creator" if str(matches.group(2)) in disable_list and user_status not in { "creator", "administrator", }: try: if status == "del": await m.delete() except RPCError: pass return False for arg in split(matches.strip()): m.command.append(arg) return True return False
async def func(flt, _, message: Message): text = message.text or message.caption message.command = None if not text: return False pattern = r"^{}(?:\s|$)" if flt.case_sensitive else r"(?i)^{}(?:\s|$)" for prefix in flt.prefixes: if not text.startswith(prefix): continue without_prefix = text[len(prefix):] for cmd in flt.commands: if not re.match(pattern.format(re.escape(cmd)), without_prefix): continue # match.groups are 1-indexed, group(1) is the quote, group(2) is the text # between the quotes, group(3) is unquoted, whitespace-split text # Remove the escape character from the arguments match_list = [ re.sub(r"\\([\"'])", r"\1", m.group(2) or m.group(3) or "") for m in command_re.finditer(without_prefix[len(cmd):]) ] message.command = { "raw" : [cmd] + list(match_list), # make a copy "flags" : [] } i = 0 while i < len(match_list): if match_list[i] in flt.flags: message.command["flags"].append(match_list.pop(i)) continue op = False for k in flt.options: if match_list[i] in flt.options[k]: op = True match_list.pop(i) message.command[k] = match_list.pop(i) break if not op: i +=1 if len(match_list) > 0: message.command["cmd"] = match_list # everything not consumed message.command["arg"] = " ".join(match_list) # provide a joined argument already return True return False
async def func(flt, client: pyrogram.Client, message: Message): # Username shared among all commands; used for mention commands, e.g.: /start@username global username if username is None: username = (await client.get_me()).username or "" text = message.text or message.caption message.command = None if not text: return False for prefix in flt.prefixes: if not text.startswith(prefix): continue without_prefix = text[len(prefix):] for cmd in flt.commands: if not re.match( rf"^(?:{cmd}(?:@?{username})?)(?:\s|$)", without_prefix, flags=re.IGNORECASE if not flt.case_sensitive else 0): continue without_command = re.sub( rf"{cmd}(?:@?{username})?\s?", "", without_prefix, count=1, flags=re.IGNORECASE if not flt.case_sensitive else 0) # match.groups are 1-indexed, group(1) is the quote, group(2) is the text # between the quotes, group(3) is unquoted, whitespace-split text # Remove the escape character from the arguments message.command = [cmd] + [ re.sub(r"\\([\"'])", r"\1", m.group(2) or m.group(3) or "") for m in command_re.finditer(without_command) ] return True return False
async def func(flt, _: Client, message: Message): text: str = message.text or message.caption message.command = None if not text: return False regex = "^({prefix})+\\b({regex})\\b(\\b@{bot_name}\\b)?(.*)".format( prefix='|'.join(re.escape(x) for x in flt.prefixes), regex='|'.join(flt.commands), bot_name=BotUsername, ) matches = re.search(re.compile(regex), text) if matches: message.command = [matches.group(2)] for arg in shlex.split(matches.group(4).strip()): message.command.append(arg) return True else: return False
async def func(flt, _, m: Message): text: str = m.text or m.caption m.command = None if not text: return False regex = "^({prefix})+\\b({regex})\\b(\\b@{bot_name}\\b)?(.*)".format( prefix="|".join(escape(x) for x in flt.prefixes), regex="|".join(flt.commands), bot_name=BOT_USERNAME, ) matches = search(compile_re(regex), text) if matches: m.command = [matches.group(2)] for arg in split(matches.group(4).strip()): m.command.append(arg) return True else: return False
async def func(flt, client: pyrogram.Client, message: Message): nonlocal username if username is None: username = (await client.get_me()).username text = message.text or message.caption message.command = None if not text: return False pattern = rf"^(?:{{cmd}}|{{cmd}}@{username})(?:\s|$)" if username else r"^{cmd}(?:\s|$)" for prefix in flt.prefixes: if not text.startswith(prefix): continue without_prefix = text[len(prefix):] for cmd in flt.commands: if not re.match( pattern.format(cmd=re.escape(cmd)), without_prefix, flags=re.IGNORECASE if not flt.case_sensitive else 0): continue # match.groups are 1-indexed, group(1) is the quote, group(2) is the text # between the quotes, group(3) is unquoted, whitespace-split text # Remove the escape character from the arguments message.command = [cmd] + [ re.sub(r"\\([\"'])", r"\1", m.group(2) or m.group(3) or "") for m in command_re.finditer(without_prefix[len(cmd):]) ] return True return False