forked from TechyShreyansh/FileStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_fsub.py
More file actions
300 lines (251 loc) · 11.3 KB
/
request_fsub.py
File metadata and controls
300 lines (251 loc) · 11.3 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# Don't Remove Credit @Tech_Shreyansh29, @MrGhostsx
# Ask Doubt on telegram @astroub_chat
#
# Copyright (C) 2025 by MrGhostsx@Github, < https://github.com/TechyShreyansh>.
#
# This file is part of < https://github.com/TechyShreyansh > project,
# and is released under the MIT License.
# Please see < https://github.com/TechyShreyansh/blob/master/LICENSE >
#
# All rights reserved.
#
import asyncio
import os
import random
import sys
import time
from pyrogram import Client, filters, __version__
from pyrogram.enums import ParseMode, ChatAction, ChatMemberStatus, ChatType
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, ReplyKeyboardMarkup, ChatMemberUpdated, ChatPermissions
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant, InviteHashEmpty, ChatAdminRequired, PeerIdInvalid, UserIsBlocked, InputUserDeactivated, UserNotParticipant
from bot import Bot
from config import *
from helper_func import *
from database.database import *
# Don't Remove Credit @Tech_Shreyansh29, @MrGhostsx
# Ask Doubt on telegram @astroub_chat
#
# Copyright (C) 2025 by MrGhostsx@Github, < https://github.com/TechyShreyansh>.
#
# This file is part of < https://github.com/TechyShreyansh > project,
# and is released under the MIT License.
# Please see < https://github.com/TechyShreyansh/blob/master/LICENSE >
#
# All rights reserved.
#
#Request force sub mode commad,,,,,,
@Bot.on_message(filters.command('fsub_mode') & filters.private & admin)
async def change_force_sub_mode(client: Client, message: Message):
temp = await message.reply("<b><i>ᴡᴀɪᴛ ᴀ sᴇᴄ..</i></b>", quote=True)
channels = await db.show_channels()
if not channels:
return await temp.edit("<b>❌ No force-sub channels found.</b>")
buttons = []
for ch_id in channels:
try:
chat = await client.get_chat(ch_id)
mode = await db.get_channel_mode(ch_id)
status = "🟢" if mode == "on" else "🔴"
title = f"{status} {chat.title}"
buttons.append([InlineKeyboardButton(title, callback_data=f"rfs_ch_{ch_id}")])
except:
buttons.append([InlineKeyboardButton(f"⚠️ {ch_id} (Unavailable)", callback_data=f"rfs_ch_{ch_id}")])
buttons.append([InlineKeyboardButton("Close ✖️", callback_data="close")])
await temp.edit(
"<b>⚡ Select a channel to toggle Force-Sub Mode:</b>",
reply_markup=InlineKeyboardMarkup(buttons),
disable_web_page_preview=True
)
# This handler captures membership updates (like when a user leaves, banned)
@Bot.on_chat_member_updated()
async def handle_Chatmembers(client, chat_member_updated: ChatMemberUpdated):
chat_id = chat_member_updated.chat.id
if await db.reqChannel_exist(chat_id):
old_member = chat_member_updated.old_chat_member
if not old_member:
return
if old_member.status == ChatMemberStatus.MEMBER:
user_id = old_member.user.id
if await db.req_user_exist(chat_id, user_id):
await db.del_req_user(chat_id, user_id)
# This handler will capture any join request to the channel/group where the bot is an admin
@Bot.on_chat_join_request()
async def handle_join_request(client, chat_join_request):
chat_id = chat_join_request.chat.id
user_id = chat_join_request.from_user.id
#print(f"[JOIN REQUEST] User {user_id} sent join request to {chat_id}")
# Print the result of db.reqChannel_exist to check if the channel exists
channel_exists = await db.reqChannel_exist(chat_id)
#print(f"Channel {chat_id} exists in the database: {channel_exists}")
if channel_exists:
if not await db.req_user_exist(chat_id, user_id):
await db.req_user(chat_id, user_id)
#print(f"Added user {user_id} to request list for {chat_id}")
# Don't Remove Credit @Tech_Shreyansh29, @MrGhostsx
# Ask Doubt on telegram @astroub_chat
#
# Copyright (C) 2025 by MrGhostsx@Github, < https://github.com/TechyShreyansh>.
#
# This file is part of < https://github.com/TechyShreyansh > project,
# and is released under the MIT License.
# Please see < https://github.com/TechyShreyansh/blob/master/LICENSE >
#
# All rights reserved.
#
# Add channel
@Bot.on_message(filters.command('addchnl') & filters.private & admin)
async def add_force_sub(client: Client, message: Message):
temp = await message.reply("Wait a sec...", quote=True)
args = message.text.split(maxsplit=1)
if len(args) != 2:
return await temp.edit(
"Usage:\n<code>/addchnl -100xxxxxxxxxx</code>"
)
try:
chat_id = int(args[1])
except ValueError:
return await temp.edit("❌ Invalid chat ID!")
all_chats = await db.show_channels()
if chat_id in [c if isinstance(c, int) else c[0] for c in all_chats]:
return await temp.edit(f"Already exists:\n<code>{chat_id}</code>")
try:
chat = await client.get_chat(chat_id)
if chat.type not in [ChatType.CHANNEL, ChatType.SUPERGROUP]:
return await temp.edit("❌ Only channels/supergroups allowed.")
bot_member = await client.get_chat_member(chat.id, "me")
if bot_member.status not in [ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER]:
return await temp.edit("❌ Bot must be admin in that chat.")
# Try to get invite link
try:
link = await client.export_chat_invite_link(chat.id)
except Exception:
link = f"https://t.me/{chat.username}" if chat.username else f"https://t.me/c/{str(chat.id)[4:]}"
await db.add_channel(chat_id)
return await temp.edit(
f"✅ Added Successfully!\n\n"
f"<b>Name:</b> <a href='{link}'>{chat.title}</a>\n"
f"<b>ID:</b> <code>{chat_id}</code>",
disable_web_page_preview=True
)
except Exception as e:
return await temp.edit(f"❌ Failed to add chat:\n<code>{chat_id}</code>\n\n<i>{e}</i>")
# Don't Remove Credit @Tech_Shreyansh29, @MrGhostsx
# Ask Doubt on telegram @astroub_chat
#
# Copyright (C) 2025 by MrGhostsx@Github, < https://github.com/TechyShreyansh>.
#
# This file is part of < https://github.com/TechyShreyansh > project,
# and is released under the MIT License.
# Please see < https://github.com/TechyShreyansh/blob/master/LICENSE >
#
# All rights reserved.
#
# Delete channel
@Bot.on_message(filters.command('delchnl') & filters.private & admin)
async def del_force_sub(client: Client, message: Message):
temp = await message.reply("<b><i>ᴡᴀɪᴛ ᴀ sᴇᴄ..</i></b>", quote=True)
args = message.text.split(maxsplit=1)
all_channels = await db.show_channels()
if len(args) != 2:
return await temp.edit("<b>Usage:</b> <code>/delchnl <channel_id | all></code>")
if args[1].lower() == "all":
if not all_channels:
return await temp.edit("<b>❌ No force-sub channels found.</b>")
for ch_id in all_channels:
await db.del_channel(ch_id)
return await temp.edit("<b>✅ All force-sub channels have been removed.</b>")
try:
ch_id = int(args[1])
except ValueError:
return await temp.edit("<b>❌ Invalid Channel ID</b>")
if ch_id in all_channels:
await db.rem_channel(ch_id)
return await temp.edit(f"<b>✅ Channel removed:</b> <code>{ch_id}</code>")
else:
return await temp.edit(f"<b>❌ Channel not found in force-sub list:</b> <code>{ch_id}</code>")
# View all channels
@Bot.on_message(filters.command('listchnl') & filters.private & admin)
async def list_force_sub_channels(client: Client, message: Message):
temp = await message.reply("<b><i>ᴡᴀɪᴛ ᴀ sᴇᴄ..</i></b>", quote=True)
channels = await db.show_channels()
if not channels:
return await temp.edit("<b>❌ No force-sub channels found.</b>")
result = "<b>⚡ Force-sub Channels:</b>\n\n"
for ch_id in channels:
try:
chat = await client.get_chat(ch_id)
link = chat.invite_link or await client.export_chat_invite_link(chat.id)
result += f"<b>•</b> <a href='{link}'>{chat.title}</a> [<code>{ch_id}</code>]\n"
except Exception:
result += f"<b>•</b> <code>{ch_id}</code> — <i>Unavailable</i>\n"
await temp.edit(result, disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Close ✖️", callback_data="close")]]))
# Don't Remove Credit @Tech_Shreyansh29, @MrGhostsx
# Ask Doubt on telegram @astroub_chat
#
# Copyright (C) 2025 by MrGhostsx@Github, < https://github.com/TechyShreyansh>.
#
# This file is part of < https://github.com/TechyShreyansh > project,
# and is released under the MIT License.
# Please see < https://github.com/TechyShreyansh/blob/master/LICENSE >
#
# All rights reserved.
#
@Bot.on_message(filters.command('delreq') & filters.private & admin)
async def delete_requested_users(client, message: Message):
if len(message.command) < 2:
return await message.reply("⚠️ Usᴀɢᴇ: `/delreq <channel_id>`", quote=True)
try:
channel_id = int(message.command[1])
except ValueError:
return await message.reply("❌ Iɴᴠᴀʟɪᴅ ᴄʜᴀɴɴᴇʟ ID.", quote=True)
# Get channel request data
channel_data = await db.rqst_fsub_Channel_data.find_one({'_id': channel_id})
if not channel_data:
return await message.reply("ℹ️ Nᴏ ʀᴇǫᴜᴇsᴛ ᴄʜᴀɴɴᴇʟ ғᴏᴜɴᴅ ғᴏʀ ᴛʜɪs ᴄʜᴀɴɴᴇʟ.", quote=True)
user_ids = channel_data.get("user_ids", [])
if not user_ids:
return await message.reply("✅ Nᴏ ᴜsᴇʀs ᴛᴏ ᴘʀᴏᴄᴇss.", quote=True)
removed = 0
skipped = 0
left_users = 0
for user_id in user_ids:
try:
member = await client.get_chat_member(channel_id, user_id)
if member.status in (
ChatMemberStatus.MEMBER,
ChatMemberStatus.ADMINISTRATOR,
ChatMemberStatus.OWNER
):
skipped += 1 # Still a participant, and in req list
continue
else:
await db.del_req_user(channel_id, user_id)
left_users += 1
except UserNotParticipant:
await db.del_req_user(channel_id, user_id)
left_users += 1
except Exception as e:
print(f"[!] Error checking user {user_id}: {e}")
skipped += 1
for user_id in user_ids:
if not await db.req_user_exist(channel_id, user_id):
await db.del_req_user(channel_id, user_id)
removed += 1
return await message.reply(
f"✅ Cʟᴇᴀɴᴜᴘ ᴄᴏᴍᴘʟᴇᴛᴇᴅ ғᴏʀ ᴄʜᴀɴɴᴇʟ `{channel_id}`\n\n"
f"👤 Rᴇᴍᴏᴠᴇᴅ ᴜsᴇʀs ɴᴏᴛ ɪɴ ᴄʜᴀɴɴᴇʟ: `{left_users}`\n"
f"🗑️ Rᴇᴍᴏᴠᴇᴅ ʟᴇғᴛᴏᴠᴇʀ ɴᴏɴ-ʀᴇǫᴜᴇsᴛ ᴜsᴇʀs: `{removed}`\n"
f"✅ Sᴛɪʟʟ ᴍᴇᴍʙᴇʀs: `{skipped}`",
quote=True
)
# Don't Remove Credit @Tech_Shreyansh29, @MrGhostsx
# Ask Doubt on telegram @astroub_chat
#
# Copyright (C) 2025 by MrGhostsx@Github, < https://github.com/TechyShreyansh>.
#
# This file is part of < https://github.com/TechyShreyansh > project,
# and is released under the MIT License.
# Please see < https://github.com/TechyShreyansh/blob/master/LICENSE >
#
# All rights reserved.
#