-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforcesub.py
More file actions
61 lines (57 loc) · 2.71 KB
/
forcesub.py
File metadata and controls
61 lines (57 loc) · 2.71 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
import asyncio
from config import Config
from pyrogram import Client
from pyrogram.errors import FloodWait, UserNotParticipant
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
async def ForceSub(bot: Client, update: Message):
"""
Custom Pyrogram Based Telegram Bot's Force Subscribe Function by @ZauteKm.
If User is not Joined Force Sub Channel Bot to Send a Message & ask him to Join First.
:param bot: Pass Client.
:param event: Pass Message.
:return: It will return 200 if Successfully Got User in Force Sub Channel and 400 if Found that User Not Participant in Force Sub Channel or User is Kicked from Force Sub Channel it will return 400. Also it returns 200 if Unable to Find Channel.
"""
try:
invite_link = await bot.create_chat_invite_link(chat_id=(int(Config.AUTH_CHANNEL) if Config.AUTH_CHANNEL.startswith("-100") else Config.AUTH_CHANNEL))
except FloodWait as e:
await asyncio.sleep(e.x)
fix_ = await ForceSub(bot, update)
return fix_
except Exception as err:
print(f"Unable to do Force Subscribe to {Config.AUTH_CHANNEL}\n\nError: {err}\n\nContact Support Group: https://t.me/JOSPSupport")
return 200
try:
user = await bot.get_chat_member(chat_id=(int(Config.AUTH_CHANNEL) if Config.AUTH_CHANNEL.startswith("-100") else Config.AUTH_CHANNEL), user_id=update.from_user.id)
if user.status == "kicked":
await bot.send_message(
chat_id=update.from_user.id,
text="Sorry Sir, You are Banned to use me. Contact my [Support Group](https://t.me/JOSPSupport).",
parse_mode="markdown",
disable_web_page_preview=True,
reply_to_message_id=update.message_id
)
return 400
else:
return 200
except UserNotParticipant:
await bot.send_message(
chat_id=update.from_user.id,
text="**Please Join My Updates Channel to use this Bot!**\n\nDue to Overload, Only Channel Subscribers can use the Bot!",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("🤖 Join Updates Channel", url=invite_link.invite_link)
]
]
),
parse_mode="markdown",
reply_to_message_id=update.message_id
)
return 400
except FloodWait as e:
await asyncio.sleep(e.x)
fix_ = await ForceSub(bot, update)
return fix_
except Exception as err:
print(f"Something Went Wrong! Unable to do Force Subscribe.\nError: {err}\n\nContact Support Group: https://t.me/JOSPSupport")
return 200