Spaces:
Running
Running
taslim19
commited on
Commit
·
5b1240d
1
Parent(s):
e1ab2db
feat: Add plain text support for afk/brb commands without prefixes
Browse files- DragMusic/plugins/tools/afk.py +76 -78
DragMusic/plugins/tools/afk.py
CHANGED
@@ -9,7 +9,7 @@ from DragMusic.Mongo.afkdb import add_afk, is_afk, remove_afk
|
|
9 |
|
10 |
|
11 |
|
12 |
-
@app.on_message(filters.command(["afk", "brb"], prefixes=["/", "!"]))
|
13 |
async def active_afk(_, message: Message):
|
14 |
if message.sender_chat:
|
15 |
return
|
@@ -61,103 +61,101 @@ async def active_afk(_, message: Message):
|
|
61 |
disable_web_page_preview=True,
|
62 |
)
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
"data": None,
|
69 |
-
"reason": None,
|
70 |
-
}
|
71 |
-
elif len(message.command) > 1 and not message.reply_to_message:
|
72 |
-
_reason = (message.text.split(None, 1)[1].strip())[:100]
|
73 |
-
details = {
|
74 |
-
"type": "text_reason",
|
75 |
-
"time": time.time(),
|
76 |
-
"data": None,
|
77 |
-
"reason": _reason,
|
78 |
-
}
|
79 |
-
elif len(message.command) == 1 and message.reply_to_message.animation:
|
80 |
-
_data = message.reply_to_message.animation.file_id
|
81 |
-
details = {
|
82 |
-
"type": "animation",
|
83 |
-
"time": time.time(),
|
84 |
-
"data": _data,
|
85 |
-
"reason": None,
|
86 |
-
}
|
87 |
-
elif len(message.command) > 1 and message.reply_to_message.animation:
|
88 |
-
_data = message.reply_to_message.animation.file_id
|
89 |
-
_reason = (message.text.split(None, 1)[1].strip())[:100]
|
90 |
-
details = {
|
91 |
-
"type": "animation",
|
92 |
-
"time": time.time(),
|
93 |
-
"data": _data,
|
94 |
-
"reason": _reason,
|
95 |
-
}
|
96 |
-
elif len(message.command) == 1 and message.reply_to_message.photo:
|
97 |
-
await app.download_media(
|
98 |
-
message.reply_to_message, file_name=f"/tmp/downloads/{user_id}.jpg"
|
99 |
-
)
|
100 |
-
details = {
|
101 |
-
"type": "photo",
|
102 |
-
"time": time.time(),
|
103 |
-
"data": None,
|
104 |
-
"reason": None,
|
105 |
-
}
|
106 |
-
elif len(message.command) > 1 and message.reply_to_message.photo:
|
107 |
-
await app.download_media(
|
108 |
-
message.reply_to_message, file_name=f"/tmp/downloads/{user_id}.jpg"
|
109 |
-
)
|
110 |
-
_reason = message.text.split(None, 1)[1].strip()
|
111 |
-
details = {
|
112 |
-
"type": "photo",
|
113 |
-
"time": time.time(),
|
114 |
-
"data": None,
|
115 |
-
"reason": _reason,
|
116 |
-
}
|
117 |
-
elif len(message.command) == 1 and message.reply_to_message.sticker:
|
118 |
-
if message.reply_to_message.sticker.is_animated:
|
119 |
details = {
|
120 |
"type": "text",
|
121 |
"time": time.time(),
|
122 |
"data": None,
|
123 |
"reason": None,
|
124 |
}
|
125 |
-
|
126 |
-
|
127 |
-
message.reply_to_message, file_name=f"/tmp/downloads/{user_id}.jpg"
|
128 |
-
)
|
129 |
details = {
|
130 |
-
"type": "
|
131 |
"time": time.time(),
|
132 |
"data": None,
|
133 |
-
"reason":
|
134 |
}
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
138 |
details = {
|
139 |
-
"type": "
|
140 |
"time": time.time(),
|
141 |
"data": None,
|
142 |
-
"reason":
|
143 |
}
|
144 |
else:
|
145 |
-
|
146 |
-
message.reply_to_message, file_name=f"/tmp/downloads/{user_id}.jpg"
|
147 |
-
)
|
148 |
details = {
|
149 |
-
"type": "
|
150 |
"time": time.time(),
|
151 |
"data": None,
|
152 |
"reason": _reason,
|
153 |
}
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
"reason":
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
await add_afk(user_id, details)
|
163 |
await message.reply_text(f"{message.from_user.first_name} ɪs ɴᴏᴡ ᴀғᴋ!")
|
|
|
9 |
|
10 |
|
11 |
|
12 |
+
@app.on_message(filters.command(["afk", "brb"], prefixes=["/", "!"]) | filters.regex(r"^(afk|brb)(?:\s+(.+))?$"))
|
13 |
async def active_afk(_, message: Message):
|
14 |
if message.sender_chat:
|
15 |
return
|
|
|
61 |
disable_web_page_preview=True,
|
62 |
)
|
63 |
|
64 |
+
# Handle both command format and plain text format
|
65 |
+
if message.command:
|
66 |
+
# Command format: /afk or /afk reason
|
67 |
+
if len(message.command) == 1 and not message.reply_to_message:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
details = {
|
69 |
"type": "text",
|
70 |
"time": time.time(),
|
71 |
"data": None,
|
72 |
"reason": None,
|
73 |
}
|
74 |
+
elif len(message.command) > 1 and not message.reply_to_message:
|
75 |
+
_reason = (message.text.split(None, 1)[1].strip())[:100]
|
|
|
|
|
76 |
details = {
|
77 |
+
"type": "text_reason",
|
78 |
"time": time.time(),
|
79 |
"data": None,
|
80 |
+
"reason": _reason,
|
81 |
}
|
82 |
+
else:
|
83 |
+
# Plain text format: afk or afk reason
|
84 |
+
text_parts = message.text.strip().split(None, 1)
|
85 |
+
if len(text_parts) == 1:
|
86 |
details = {
|
87 |
+
"type": "text",
|
88 |
"time": time.time(),
|
89 |
"data": None,
|
90 |
+
"reason": None,
|
91 |
}
|
92 |
else:
|
93 |
+
_reason = text_parts[1].strip()[:100]
|
|
|
|
|
94 |
details = {
|
95 |
+
"type": "text_reason",
|
96 |
"time": time.time(),
|
97 |
"data": None,
|
98 |
"reason": _reason,
|
99 |
}
|
100 |
+
|
101 |
+
# Handle reply to media (works for both command and plain text)
|
102 |
+
if message.reply_to_message:
|
103 |
+
if message.reply_to_message.animation:
|
104 |
+
_data = message.reply_to_message.animation.file_id
|
105 |
+
if details.get("reason"):
|
106 |
+
details.update({
|
107 |
+
"type": "animation",
|
108 |
+
"data": _data,
|
109 |
+
})
|
110 |
+
else:
|
111 |
+
details.update({
|
112 |
+
"type": "animation",
|
113 |
+
"data": _data,
|
114 |
+
"reason": None,
|
115 |
+
})
|
116 |
+
elif message.reply_to_message.photo:
|
117 |
+
await app.download_media(
|
118 |
+
message.reply_to_message, file_name=f"/tmp/downloads/{user_id}.jpg"
|
119 |
+
)
|
120 |
+
if details.get("reason"):
|
121 |
+
details.update({
|
122 |
+
"type": "photo",
|
123 |
+
"data": None,
|
124 |
+
})
|
125 |
+
else:
|
126 |
+
details.update({
|
127 |
+
"type": "photo",
|
128 |
+
"data": None,
|
129 |
+
"reason": None,
|
130 |
+
})
|
131 |
+
elif message.reply_to_message.sticker:
|
132 |
+
if message.reply_to_message.sticker.is_animated:
|
133 |
+
if details.get("reason"):
|
134 |
+
details.update({
|
135 |
+
"type": "text_reason",
|
136 |
+
"data": None,
|
137 |
+
})
|
138 |
+
else:
|
139 |
+
details.update({
|
140 |
+
"type": "text",
|
141 |
+
"data": None,
|
142 |
+
"reason": None,
|
143 |
+
})
|
144 |
+
else:
|
145 |
+
await app.download_media(
|
146 |
+
message.reply_to_message, file_name=f"/tmp/downloads/{user_id}.jpg"
|
147 |
+
)
|
148 |
+
if details.get("reason"):
|
149 |
+
details.update({
|
150 |
+
"type": "photo",
|
151 |
+
"data": None,
|
152 |
+
})
|
153 |
+
else:
|
154 |
+
details.update({
|
155 |
+
"type": "photo",
|
156 |
+
"data": None,
|
157 |
+
"reason": None,
|
158 |
+
})
|
159 |
|
160 |
await add_afk(user_id, details)
|
161 |
await message.reply_text(f"{message.from_user.first_name} ɪs ɴᴏᴡ ᴀғᴋ!")
|