Spaces:
Sleeping
Sleeping
Captain Ezio
commited on
Commit
·
07091ae
1
Parent(s):
d7f1a07
fixes
Browse files- Powers/plugins/bans.py +7 -0
- Powers/plugins/flood.py +21 -1
- Powers/plugins/muting.py +7 -0
- Powers/plugins/utils.py +2 -2
- Powers/plugins/watchers.py +98 -94
- Powers/utils/custom_filters.py +1 -1
Powers/plugins/bans.py
CHANGED
@@ -973,6 +973,13 @@ async def unbanbutton(c: Gojo, q: CallbackQuery):
|
|
973 |
user_id = int(splitter[1])
|
974 |
user = await q.message.chat.get_member(q.from_user.id)
|
975 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
976 |
if not user.privileges.can_restrict_members and q.from_user.id != OWNER_ID:
|
977 |
await q.answer(
|
978 |
"You don't have enough permission to do this!\nStay in your limits!",
|
|
|
973 |
user_id = int(splitter[1])
|
974 |
user = await q.message.chat.get_member(q.from_user.id)
|
975 |
|
976 |
+
if not user:
|
977 |
+
await q.answer(
|
978 |
+
"You don't have enough permission to do this!\nStay in your limits!",
|
979 |
+
show_alert=True,
|
980 |
+
)
|
981 |
+
return
|
982 |
+
|
983 |
if not user.privileges.can_restrict_members and q.from_user.id != OWNER_ID:
|
984 |
await q.answer(
|
985 |
"You don't have enough permission to do this!\nStay in your limits!",
|
Powers/plugins/flood.py
CHANGED
@@ -330,30 +330,46 @@ dic = {}
|
|
330 |
@Gojo.on_message(filters.all & ~filters.bot | ~filters.private, 10)
|
331 |
async def flood_watcher(c: Gojo, m: Message):
|
332 |
c_id = m.chat.id
|
|
|
333 |
if not m.chat:
|
334 |
return
|
|
|
335 |
Flood = Floods()
|
|
|
336 |
try:
|
337 |
u_id = m.from_user.id
|
338 |
except AttributeError:
|
339 |
return # Get this error when the message received is not by an user and return
|
|
|
340 |
is_flood = Flood.is_chat(c_id)
|
|
|
341 |
if not is_flood:
|
342 |
return # return of chat is not in anti flood protection
|
|
|
343 |
app_users = Approve(m.chat.id).list_approved()
|
|
|
344 |
if u_id in {i[0] for i in app_users}:
|
345 |
return #return if the user is approved
|
|
|
346 |
if not is_flood or u_id in SUPPORT_STAFF:
|
347 |
return #return if the user is in support_staff
|
348 |
-
|
|
|
|
|
|
|
|
|
|
|
349 |
if user_status in [CMS.OWNER, CMS.ADMINISTRATOR]:
|
350 |
return #return if the user is owner or admin
|
|
|
351 |
action = is_flood[2]
|
352 |
limit = int(is_flood[0])
|
353 |
within = int(is_flood[1])
|
|
|
354 |
if not len(dic):
|
355 |
z = {c_id : {u_id : [[],[]]}}
|
356 |
dic.update(z)
|
|
|
357 |
try:
|
358 |
dic[c_id] # access and check weather the c_id present or not
|
359 |
except KeyError:
|
@@ -365,14 +381,18 @@ async def flood_watcher(c: Gojo, m: Message):
|
|
365 |
except KeyError:
|
366 |
z = {u_id : [[],[]]}
|
367 |
dic[c_id].update(z) # make the dic something like {c_id : {u_id : [[for time],[for msg]]}}
|
|
|
368 |
sec = round(time.time())
|
|
|
369 |
try:
|
370 |
dic[c_id][u_id][0].append(sec)
|
371 |
dic[c_id][u_id][1].append("x")
|
372 |
except KeyError:
|
373 |
dic[c_id].update({u_id : [[sec], ["x"]]})
|
|
|
374 |
x = int(dic[c_id][u_id][0][0])
|
375 |
y = int(dic[c_id][u_id][0][-1])
|
|
|
376 |
if len(dic[c_id][u_id][1]) == limit:
|
377 |
if y-x <= within:
|
378 |
if action == "ban":
|
|
|
330 |
@Gojo.on_message(filters.all & ~filters.bot | ~filters.private, 10)
|
331 |
async def flood_watcher(c: Gojo, m: Message):
|
332 |
c_id = m.chat.id
|
333 |
+
|
334 |
if not m.chat:
|
335 |
return
|
336 |
+
|
337 |
Flood = Floods()
|
338 |
+
|
339 |
try:
|
340 |
u_id = m.from_user.id
|
341 |
except AttributeError:
|
342 |
return # Get this error when the message received is not by an user and return
|
343 |
+
|
344 |
is_flood = Flood.is_chat(c_id)
|
345 |
+
|
346 |
if not is_flood:
|
347 |
return # return of chat is not in anti flood protection
|
348 |
+
|
349 |
app_users = Approve(m.chat.id).list_approved()
|
350 |
+
|
351 |
if u_id in {i[0] for i in app_users}:
|
352 |
return #return if the user is approved
|
353 |
+
|
354 |
if not is_flood or u_id in SUPPORT_STAFF:
|
355 |
return #return if the user is in support_staff
|
356 |
+
|
357 |
+
try:
|
358 |
+
user_status = (await m.chat.get_member(m.from_user.id)).status
|
359 |
+
except Exception:
|
360 |
+
return
|
361 |
+
|
362 |
if user_status in [CMS.OWNER, CMS.ADMINISTRATOR]:
|
363 |
return #return if the user is owner or admin
|
364 |
+
|
365 |
action = is_flood[2]
|
366 |
limit = int(is_flood[0])
|
367 |
within = int(is_flood[1])
|
368 |
+
|
369 |
if not len(dic):
|
370 |
z = {c_id : {u_id : [[],[]]}}
|
371 |
dic.update(z)
|
372 |
+
|
373 |
try:
|
374 |
dic[c_id] # access and check weather the c_id present or not
|
375 |
except KeyError:
|
|
|
381 |
except KeyError:
|
382 |
z = {u_id : [[],[]]}
|
383 |
dic[c_id].update(z) # make the dic something like {c_id : {u_id : [[for time],[for msg]]}}
|
384 |
+
|
385 |
sec = round(time.time())
|
386 |
+
|
387 |
try:
|
388 |
dic[c_id][u_id][0].append(sec)
|
389 |
dic[c_id][u_id][1].append("x")
|
390 |
except KeyError:
|
391 |
dic[c_id].update({u_id : [[sec], ["x"]]})
|
392 |
+
|
393 |
x = int(dic[c_id][u_id][0][0])
|
394 |
y = int(dic[c_id][u_id][0][-1])
|
395 |
+
|
396 |
if len(dic[c_id][u_id][1]) == limit:
|
397 |
if y-x <= within:
|
398 |
if action == "ban":
|
Powers/plugins/muting.py
CHANGED
@@ -632,6 +632,13 @@ async def unmutebutton(c: Gojo, q: CallbackQuery):
|
|
632 |
user_id = int(splitter[1])
|
633 |
user = await q.message.chat.get_member(q.from_user.id)
|
634 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
635 |
if not user.privileges.can_restrict_members and user.id != OWNER_ID:
|
636 |
await q.answer(
|
637 |
"You don't have enough permission to do this!\nStay in your limits!",
|
|
|
632 |
user_id = int(splitter[1])
|
633 |
user = await q.message.chat.get_member(q.from_user.id)
|
634 |
|
635 |
+
if not user:
|
636 |
+
await q.answer(
|
637 |
+
"You don't have enough permission to do this!\nStay in your limits!",
|
638 |
+
show_alert=True,
|
639 |
+
)
|
640 |
+
return
|
641 |
+
|
642 |
if not user.privileges.can_restrict_members and user.id != OWNER_ID:
|
643 |
await q.answer(
|
644 |
"You don't have enough permission to do this!\nStay in your limits!",
|
Powers/plugins/utils.py
CHANGED
@@ -287,11 +287,11 @@ async def github(_, m: Message):
|
|
287 |
|
288 |
|
289 |
pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
|
290 |
-
BASE = "https://
|
291 |
|
292 |
|
293 |
def paste(content: str):
|
294 |
-
resp = resp_post(f"{BASE}api/
|
295 |
if resp.status_code != 200:
|
296 |
return
|
297 |
resp = resp.json()
|
|
|
287 |
|
288 |
|
289 |
pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
|
290 |
+
BASE = "https://batbin.me/"
|
291 |
|
292 |
|
293 |
def paste(content: str):
|
294 |
+
resp = resp_post(f"{BASE}api/v2/paste", data=content)
|
295 |
if resp.status_code != 200:
|
296 |
return
|
297 |
resp = resp.json()
|
Powers/plugins/watchers.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from re import escape as re_escape
|
2 |
from time import time
|
3 |
from traceback import format_exc
|
@@ -53,117 +54,120 @@ async def bl_watcher(_, m: Message):
|
|
53 |
return
|
54 |
|
55 |
bl_db = Blacklist(m.chat.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
await m.chat.kick_member(
|
69 |
m.from_user.id,
|
|
|
70 |
)
|
71 |
-
)
|
72 |
-
await m.reply_text(
|
73 |
-
text="Banned {user} for sending a blacklisted word!".format(
|
74 |
-
user=m.from_user.username or f"<b>{m.from_user.first_name}</b>",
|
75 |
-
),
|
76 |
-
)
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
await m.reply_text(
|
85 |
-
text="Muted {user} for sending a blacklisted word!".format(
|
86 |
-
user=m.from_user.username or f"<b>{m.from_user.first_name}</b>",
|
87 |
-
),
|
88 |
-
)
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
)
|
102 |
-
|
103 |
-
elif warn_settings["warn_mode"] == "ban":
|
104 |
-
await m.chat.ban_member(m.from_user.id)
|
105 |
-
action = "banned"
|
106 |
-
elif warn_settings["warn_mode"] == "mute":
|
107 |
-
await m.chat.restrict_member(m.from_user.id, ChatPermissions())
|
108 |
-
action = "muted"
|
109 |
await m.reply_text(
|
110 |
(
|
111 |
-
f"
|
112 |
-
f"
|
|
|
113 |
),
|
114 |
)
|
115 |
-
|
116 |
-
await m.reply_text(
|
117 |
-
(
|
118 |
-
f"{(await mention_html(m.from_user.first_name, m.from_user.id))} warned {num}/{warn_settings['warn_limit']}\n"
|
119 |
-
# f"Last warn was for:\n<i>{warn_reason}</i>"
|
120 |
-
f"Last warn was for:\n<i>{warn_reason.format(trigger)}</i>"
|
121 |
-
),
|
122 |
-
)
|
123 |
-
return
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
|
140 |
-
|
141 |
-
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
167 |
|
168 |
|
169 |
|
|
|
1 |
+
from datetime import datetime, timedelta
|
2 |
from re import escape as re_escape
|
3 |
from time import time
|
4 |
from traceback import format_exc
|
|
|
54 |
return
|
55 |
|
56 |
bl_db = Blacklist(m.chat.id)
|
57 |
+
try:
|
58 |
+
async def perform_action_blacklist(m: Message, action: str, trigger: str):
|
59 |
+
if action == "kick":
|
60 |
+
tim = datetime.now() + timedelta(minutes=45)
|
61 |
+
await m.chat.ban_member(m.from_user.id, tim)
|
62 |
+
await m.reply_text(
|
63 |
+
text="Kicked {user} for sending a blacklisted word!".format(
|
64 |
+
user=m.from_user.username or f"<b>{m.from_user.first_name}</b>",
|
65 |
+
),
|
66 |
+
)
|
67 |
|
68 |
+
elif action == "ban":
|
69 |
+
(
|
70 |
+
await m.chat.ban_member(
|
71 |
+
m.from_user.id,
|
72 |
+
)
|
73 |
+
)
|
74 |
+
await m.reply_text(
|
75 |
+
text="Banned {user} for sending a blacklisted word!".format(
|
76 |
+
user=m.from_user.username or f"<b>{m.from_user.first_name}</b>",
|
77 |
+
),
|
78 |
+
)
|
79 |
|
80 |
+
elif action == "mute":
|
81 |
+
await m.chat.restrict_member(
|
|
|
82 |
m.from_user.id,
|
83 |
+
ChatPermissions(),
|
84 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
await m.reply_text(
|
87 |
+
text="Muted {user} for sending a blacklisted word!".format(
|
88 |
+
user=m.from_user.username or f"<b>{m.from_user.first_name}</b>",
|
89 |
+
),
|
90 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
+
elif action == "warn":
|
93 |
+
warns_settings_db = WarnSettings(m.chat.id)
|
94 |
+
warns_db = Warns(m.chat.id)
|
95 |
+
warn_settings = warns_settings_db.get_warnings_settings()
|
96 |
+
warn_reason = bl_db.get_reason()
|
97 |
+
_, num = warns_db.warn_user(m.from_user.id, warn_reason)
|
98 |
+
if num >= warn_settings["warn_limit"]:
|
99 |
+
if warn_settings["warn_mode"] == "kick":
|
100 |
+
await m.chat.ban_member(
|
101 |
+
m.from_user.id,
|
102 |
+
until_date=int(time() + 45),
|
103 |
+
)
|
104 |
+
action = "kicked"
|
105 |
+
elif warn_settings["warn_mode"] == "ban":
|
106 |
+
await m.chat.ban_member(m.from_user.id)
|
107 |
+
action = "banned"
|
108 |
+
elif warn_settings["warn_mode"] == "mute":
|
109 |
+
await m.chat.restrict_member(m.from_user.id, ChatPermissions())
|
110 |
+
action = "muted"
|
111 |
+
await m.reply_text(
|
112 |
+
(
|
113 |
+
f"Warnings {num}/{warn_settings['warn_limit']}\n"
|
114 |
+
f"{(await mention_html(m.from_user.first_name, m.from_user.id))} has been <b>{action}!</b>"
|
115 |
+
),
|
116 |
)
|
117 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
await m.reply_text(
|
119 |
(
|
120 |
+
f"{(await mention_html(m.from_user.first_name, m.from_user.id))} warned {num}/{warn_settings['warn_limit']}\n"
|
121 |
+
# f"Last warn was for:\n<i>{warn_reason}</i>"
|
122 |
+
f"Last warn was for:\n<i>{warn_reason.format(trigger)}</i>"
|
123 |
),
|
124 |
)
|
125 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
+
if m.from_user.id in SUPPORT_STAFF:
|
128 |
+
# Don't work on Support Staff!
|
129 |
+
return
|
130 |
|
131 |
+
# If no blacklists, then return
|
132 |
+
chat_blacklists = bl_db.get_blacklists()
|
133 |
+
if not chat_blacklists:
|
134 |
+
return
|
135 |
|
136 |
+
# Get admins from admin_cache, reduces api calls
|
137 |
+
try:
|
138 |
+
admin_ids = {i[0] for i in ADMIN_CACHE[m.chat.id]}
|
139 |
+
except KeyError:
|
140 |
+
admin_ids = await admin_cache_reload(m, "blacklist_watcher")
|
141 |
|
142 |
+
if m.from_user.id in admin_ids:
|
143 |
+
return
|
144 |
|
145 |
+
# Get approved user from cache/database
|
146 |
+
app_users = Approve(m.chat.id).list_approved()
|
147 |
+
if m.from_user.id in {i[0] for i in app_users}:
|
148 |
+
return
|
149 |
|
150 |
+
# Get action for blacklist
|
151 |
+
action = bl_db.get_action()
|
152 |
+
for trigger in chat_blacklists:
|
153 |
+
pattern = r"( |^|[^\w])" + re_escape(trigger) + r"( |$|[^\w])"
|
154 |
+
match = await regex_searcher(pattern, m.text.lower())
|
155 |
+
if not match:
|
156 |
+
continue
|
157 |
+
if match:
|
158 |
+
try:
|
159 |
+
await perform_action_blacklist(m, action, trigger)
|
160 |
+
LOGGER.info(
|
161 |
+
f"{m.from_user.id} {action}ed for using blacklisted word {trigger} in {m.chat.id}",
|
162 |
+
)
|
163 |
+
await m.delete()
|
164 |
+
except RPCError as ef:
|
165 |
+
LOGGER.error(ef)
|
166 |
+
LOGGER.error(format_exc())
|
167 |
+
break
|
168 |
+
return
|
169 |
+
except Exception:
|
170 |
+
return
|
171 |
|
172 |
|
173 |
|
Powers/utils/custom_filters.py
CHANGED
@@ -219,7 +219,7 @@ async def restrict_check_func(_, __, m: Message or CallbackQuery):
|
|
219 |
|
220 |
user = await m.chat.get_member(m.from_user.id)
|
221 |
|
222 |
-
if user.status in [CMS.ADMINISTRATOR, CMS.OWNER] and user.privileges.can_restrict_members:
|
223 |
status = True
|
224 |
else:
|
225 |
status = False
|
|
|
219 |
|
220 |
user = await m.chat.get_member(m.from_user.id)
|
221 |
|
222 |
+
if user and user.status in [CMS.ADMINISTRATOR, CMS.OWNER] and user.privileges.can_restrict_members:
|
223 |
status = True
|
224 |
else:
|
225 |
status = False
|