-
Notifications
You must be signed in to change notification settings - Fork 5
/
gmute.py
74 lines (64 loc) · 2.28 KB
/
gmute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from pyrogram import Client, filters, errors, enums
from pyrogram.types import Message
from utils.misc import modules_help, prefix
from utils.db import db
def get_arg(message):
msg = message.text
msg = msg.replace(" ", "", 1) if msg[1] == " " else msg
split = msg[1:].replace("\n", " \n").split(" ")
if " ".join(split[1:]).strip() == "":
return ""
return " ".join(split[1:])
@Client.on_message(filters.command("gmute", prefix) & filters.me)
async def gmute(client, message):
if reply := message.reply_to_message:
user = reply.from_user.id
else:
user = get_arg(message)
if not user:
await message.edit(
"<b>Whom should I gmute?</b>", parse_mode=enums.ParseMode.HTML
)
return
get_user = await client.get_users(user)
gmuted_users = db.get("core.gmute", "gmuted_users", [])
gmuted_users.append(get_user.id)
db.set("custom.gmute", "gmuted_users", gmuted_users)
await message.edit(
f"<b>Gmuted {get_user.first_name}, LOL!</b>", parse_mode=enums.ParseMode.HTML
)
@Client.on_message(filters.command("ungmute", prefix) & filters.me)
async def ungmute(client, message):
if reply := message.reply_to_message:
user = reply.from_user.id
else:
user = get_arg(message)
if not user:
await message.edit(
"<b>Whom should I ungmute?</b>", parse_mode=enums.ParseMode.HTML
)
return
get_user = await client.get_users(user)
gmuted_users = db.get("core.gmute", "gmuted_users", [])
try:
gmuted_users.remove(get_user.id)
except ValueError:
pass
db.set("custom.gmute", "gmuted_users", gmuted_users)
await message.edit(
f"<b>Unmuted {get_user.first_name}, enjoy!</b>", parse_mode=enums.ParseMode.HTML
)
@Client.on_message(filters.group)
async def check_and_del(_, message: Message):
if message.from_user and message.from_user.id in db.get(
"custom.gmute", "gmuted_users", []
):
try:
await message.delete()
except errors.RPCError:
pass # you don't have delete rights
message.continue_propagation()
modules_help["gmute"] = {
"gmute": " global mute of user",
"ungmute": "unmute user from global ban",
}