randydev commited on
Commit
45a13e0
·
verified ·
1 Parent(s): ca52a5e

Create prefixprem.py

Browse files
Files changed (1) hide show
  1. Akeno/utils/prefixprem.py +68 -0
Akeno/utils/prefixprem.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from pyrogram import Client, Message
3
+ from Akeno.utils.base_sqlite import *
4
+
5
+ def command(commands: Union[str, List[str]], case_sensitive: bool = False):
6
+ command_re = re.compile(
7
+ r"([\"'])(.*?)(?<!\\)\1|(\S+)",
8
+ flags=re.UNICODE,
9
+ )
10
+
11
+ async def func(flt, client: Client, message: Message):
12
+ username = client.me.username or ""
13
+ user_id = message.from_user.id
14
+ text = message.text or message.caption
15
+ message.command = None
16
+
17
+ if not text:
18
+ return False
19
+
20
+ stored_prefix = get_prefix(user_id)
21
+ if message.entities and stored_prefix:
22
+ for entity in message.entities:
23
+ if entity.type == "custom_emoji" and entity.custom_emoji_id == stored_prefix:
24
+ without_prefix = text[entity.length:]
25
+ for cmd in flt.commands:
26
+ if re.match(
27
+ f"^(?:{cmd}(?:@?{username})?)(?:\s|$)",
28
+ without_prefix,
29
+ flags=0 if flt.case_sensitive else re.IGNORECASE,
30
+ ):
31
+ without_command = re.sub(
32
+ f"{cmd}(?:@?{username})?\s?",
33
+ "",
34
+ without_prefix,
35
+ count=1,
36
+ flags=0 if flt.case_sensitive else re.IGNORECASE,
37
+ )
38
+ message.command = [cmd] + [
39
+ re.sub(r"\\([\"'])", r"\1", m.group(2) or m.group(3) or "")
40
+ for m in command_re.finditer(without_command)
41
+ ]
42
+ return True
43
+
44
+ if stored_prefix and text.startswith(stored_prefix):
45
+ without_prefix = text[len(stored_prefix):]
46
+
47
+ for cmd in flt.commands:
48
+ if re.match(
49
+ f"^(?:{cmd}(?:@?{username})?)(?:\s|$)",
50
+ without_prefix,
51
+ flags=0 if flt.case_sensitive else re.IGNORECASE,
52
+ ):
53
+ without_command = re.sub(
54
+ f"{cmd}(?:@?{username})?\s?",
55
+ "",
56
+ without_prefix,
57
+ count=1,
58
+ flags=0 if flt.case_sensitive else re.IGNORECASE,
59
+ )
60
+ message.command = [cmd] + [
61
+ re.sub(r"\\([\"'])", r"\1", m.group(2) or m.group(3) or "")
62
+ for m in command_re.finditer(without_command)
63
+ ]
64
+ return True
65
+ return False
66
+ commands = commands if isinstance(commands, list) else [commands]
67
+ commands = {c if case_sensitive else c.lower() for c in commands}
68
+ return create(func, "CommandFilter", commands=commands, case_sensitive=case_sensitive)