Spaces:
Paused
Paused
teamx-cloner
commited on
Commit
·
66f0ff9
1
Parent(s):
42ba40f
Create gcast.py
Browse files- plugins/gcast.py +163 -0
plugins/gcast.py
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
import os
|
3 |
+
|
4 |
+
from telethon.errors.rpcerrorlist import ChatAdminRequiredError, FloodWaitError
|
5 |
+
from telethon.tl.functions.channels import EditAdminRequest
|
6 |
+
from telethon.tl.functions.contacts import BlockRequest, UnblockRequest
|
7 |
+
from telethon.tl.types import ChatAdminRights, User
|
8 |
+
|
9 |
+
from xteam.dB import DEVLIST
|
10 |
+
from xteam.dB.base import KeyManager
|
11 |
+
from xteam.dB.gban_mute_db import (
|
12 |
+
gban,
|
13 |
+
gmute,
|
14 |
+
is_gbanned,
|
15 |
+
is_gmuted,
|
16 |
+
list_gbanned,
|
17 |
+
ungban,
|
18 |
+
ungmute,
|
19 |
+
)
|
20 |
+
from xteam.fns.tools import create_tl_btn, format_btn, get_msg_button
|
21 |
+
|
22 |
+
from . import (
|
23 |
+
HNDLR,
|
24 |
+
LOGS,
|
25 |
+
NOSPAM_CHAT,
|
26 |
+
OWNER_NAME,
|
27 |
+
eod,
|
28 |
+
eor,
|
29 |
+
get_string,
|
30 |
+
inline_mention,
|
31 |
+
ultroid_bot,
|
32 |
+
ultroid_cmd,
|
33 |
+
)
|
34 |
+
from ._inline import something
|
35 |
+
|
36 |
+
_gpromote_rights = ChatAdminRights(
|
37 |
+
add_admins=False,
|
38 |
+
invite_users=True,
|
39 |
+
change_info=False,
|
40 |
+
ban_users=True,
|
41 |
+
delete_messages=True,
|
42 |
+
pin_messages=True,
|
43 |
+
)
|
44 |
+
|
45 |
+
_gdemote_rights = ChatAdminRights(
|
46 |
+
add_admins=False,
|
47 |
+
invite_users=False,
|
48 |
+
change_info=False,
|
49 |
+
ban_users=False,
|
50 |
+
delete_messages=False,
|
51 |
+
pin_messages=False,
|
52 |
+
)
|
53 |
+
|
54 |
+
keym = KeyManager("BLACKLIST_GCAST", cast=list)
|
55 |
+
|
56 |
+
|
57 |
+
@ultroid_cmd(pattern="Gcast( (.*)|$)", fullsudo=True)
|
58 |
+
async def gcast(event):
|
59 |
+
text, btn, reply = "", None, None
|
60 |
+
if xx := event.pattern_match.group(2):
|
61 |
+
msg, btn = get_msg_button(event.text.split(maxsplit=1)[1])
|
62 |
+
elif event.is_reply:
|
63 |
+
reply = await event.get_reply_message()
|
64 |
+
msg = reply.text
|
65 |
+
if reply.buttons:
|
66 |
+
btn = format_btn(reply.buttons)
|
67 |
+
else:
|
68 |
+
msg, btn = get_msg_button(msg)
|
69 |
+
else:
|
70 |
+
return await eor(
|
71 |
+
event, "Give some text to Globally Broadcast or reply a message.."
|
72 |
+
)
|
73 |
+
|
74 |
+
kk = await event.eor("Globally Broadcasting Msg...")
|
75 |
+
er = 0
|
76 |
+
done = 0
|
77 |
+
err = ""
|
78 |
+
if event.client._dialogs:
|
79 |
+
dialog = event.client._dialogs
|
80 |
+
else:
|
81 |
+
dialog = await event.client.get_dialogs()
|
82 |
+
event.client._dialogs.extend(dialog)
|
83 |
+
for x in dialog:
|
84 |
+
if x.is_group:
|
85 |
+
chat = x.entity.id
|
86 |
+
if (
|
87 |
+
not keym.contains(chat)
|
88 |
+
and int(f"-100{str(chat)}") not in NOSPAM_CHAT
|
89 |
+
and chat not in BLACKLIST_GCAST # Added blacklist check
|
90 |
+
and (
|
91 |
+
(
|
92 |
+
event.text[2:7] != "admin"
|
93 |
+
or (x.entity.admin_rights or x.entity.creator)
|
94 |
+
)
|
95 |
+
)
|
96 |
+
):
|
97 |
+
try:
|
98 |
+
if btn:
|
99 |
+
bt = create_tl_btn(btn)
|
100 |
+
await something(
|
101 |
+
event,
|
102 |
+
msg,
|
103 |
+
reply.media if reply else None,
|
104 |
+
bt,
|
105 |
+
chat=chat,
|
106 |
+
reply=False,
|
107 |
+
)
|
108 |
+
else:
|
109 |
+
await event.client.send_message(
|
110 |
+
chat, msg, file=reply.media if reply else None
|
111 |
+
)
|
112 |
+
done += 1
|
113 |
+
except FloodWaitError as fw:
|
114 |
+
await asyncio.sleep(fw.seconds + 10)
|
115 |
+
try:
|
116 |
+
if btn:
|
117 |
+
bt = create_tl_btn(btn)
|
118 |
+
await something(
|
119 |
+
event,
|
120 |
+
msg,
|
121 |
+
reply.media if reply else None,
|
122 |
+
bt,
|
123 |
+
chat=chat,
|
124 |
+
reply=False,
|
125 |
+
)
|
126 |
+
else:
|
127 |
+
await event.client.send_message(
|
128 |
+
chat, msg, file=reply.media if reply else None
|
129 |
+
)
|
130 |
+
done += 1
|
131 |
+
except Exception as rr:
|
132 |
+
err += f"• {rr}\n"
|
133 |
+
er += 1
|
134 |
+
except BaseException as h:
|
135 |
+
err += f"• {str(h)}" + "\n"
|
136 |
+
er += 1
|
137 |
+
text += f"Done in {done} chats, error in {er} chat(s)"
|
138 |
+
if err != "":
|
139 |
+
open("gcast-error.log", "w+").write(err)
|
140 |
+
text += f"\nYou can do {HNDLR}ul gcast-error.log to know error report."
|
141 |
+
await kk.edit(text)
|
142 |
+
|
143 |
+
# --- New functions for managing the gcast blacklist ---
|
144 |
+
|
145 |
+
BLACKLIST_GCAST = set()
|
146 |
+
|
147 |
+
@ultroid_cmd(pattern="addbl (\\d+)", fullsudo=True)
|
148 |
+
async def add_gblacklist(event):
|
149 |
+
chat_id = int(event.pattern_match.group(1))
|
150 |
+
if chat_id not in BLACKLIST_GCAST:
|
151 |
+
BLACKLIST_GCAST.add(chat_id)
|
152 |
+
await event.edit(f"Chat {chat_id} has been added to the gcast blacklist.")
|
153 |
+
else:
|
154 |
+
await event.edit(f"Chat {chat_id} is already in the gcast blacklist.")
|
155 |
+
|
156 |
+
@ultroid_cmd(pattern="unbl (\\d+)", fullsudo=True)
|
157 |
+
async def remove_gblacklist(event):
|
158 |
+
chat_id = int(event.pattern_match.group(1))
|
159 |
+
if chat_id in BLACKLIST_GCAST:
|
160 |
+
BLACKLIST_GCAST.remove(chat_id)
|
161 |
+
await event.edit(f"Chat {chat_id} has been removed from the gcast blacklist.")
|
162 |
+
else:
|
163 |
+
await event.edit(f"Chat {chat_id} is not in the gcast blacklist.")
|