-
Notifications
You must be signed in to change notification settings - Fork 94
/
bot.py
191 lines (171 loc) · 9.2 KB
/
bot.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
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
from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery
from pyrogram import filters, Client, errors, enums
from pyrogram.errors import UserNotParticipant
from pyrogram.errors.exceptions.flood_420 import FloodWait
from database import add_user, add_group, all_users, all_groups, users, remove_user
from configs import cfg
import random, asyncio
app = Client(
"approver",
api_id=cfg.API_ID,
api_hash=cfg.API_HASH,
bot_token=cfg.BOT_TOKEN
)
gif = [
'https://telegra.ph/file/a5a2bb456bf3eecdbbb99.mp4',
'https://telegra.ph/file/03c6e49bea9ce6c908b87.mp4',
'https://telegra.ph/file/9ebf412f09cd7d2ceaaef.mp4',
'https://telegra.ph/file/293cc10710e57530404f8.mp4',
'https://telegra.ph/file/506898de518534ff68ba0.mp4',
'https://telegra.ph/file/dae0156e5f48573f016da.mp4',
'https://telegra.ph/file/3e2871e714f435d173b9e.mp4',
'https://telegra.ph/file/714982b9fedfa3b4d8d2b.mp4',
'https://telegra.ph/file/876edfcec678b64eac480.mp4',
'https://telegra.ph/file/6b1ab5aec5fa81cf40005.mp4',
'https://telegra.ph/file/b4834b434888de522fa49.mp4'
]
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Main process ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@app.on_chat_join_request(filters.group | filters.channel & ~filters.private)
async def approve(_, m : Message):
op = m.chat
kk = m.from_user
try:
add_group(m.chat.id)
await app.approve_chat_join_request(op.id, kk.id)
img = random.choice(gif)
await app.send_video(kk.id,img, "**Hello {}!\nWelcome To {}\n\n__Powerd By : @SdBotz__**".format(m.from_user.mention, m.chat.title))
add_user(kk.id)
except errors.PeerIdInvalid as e:
print("user isn't start bot(means group)")
except Exception as err:
print(str(err))
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Start ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@app.on_message(filters.command("start"))
async def op(_, m :Message):
try:
await app.get_chat_member(cfg.CHID, m.from_user.id)
if m.chat.type == enums.ChatType.PRIVATE:
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("🗯 Channel", url="https://t.me/SDBOTs_inifinity"),
InlineKeyboardButton("💬 Support", url="https://t.me/SDBOTz")
],[
InlineKeyboardButton("➕ Add me to your Chat ➕", url="https://t.me/SDAutoApproveBot?startgroup")
]
]
)
add_user(m.from_user.id)
await m.reply_photo("https://telegra.ph/file/a782e3bbbe40df8a4bb67.jpg", caption="**🦊 Hello {}!\nI'm an auto approve [Admin Join Requests]({}) Bot.\nI can approve users in Groups/Channels.Add me to your chat and promote me to admin with add members permission.\n\n__Powerd By : @SdBotz__**".format(m.from_user.mention, "https://t.me/telegram/153"), reply_markup=keyboard)
elif m.chat.type == enums.ChatType.GROUP or enums.ChatType.SUPERGROUP:
keyboar = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("💁♂️ Start me private 💁♂️", url="https://t.me/SDAutoApproveBot?start=start")
]
]
)
add_group(m.chat.id)
await m.reply_text("**🦊 Hello {}!\nwrite me private for more details**".format(m.from_user.first_name), reply_markup=keyboar)
print(m.from_user.first_name +" Is started Your Bot!")
except UserNotParticipant:
key = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("🍀 Check Again 🍀", "chk")
]
]
)
await m.reply_text("**⚠️Access Denied!⚠️\n\nPlease Join @{} to use me.If you joined click check again button to confirm.**".format(cfg.FSUB), reply_markup=key)
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ callback ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@app.on_callback_query(filters.regex("chk"))
async def chk(_, cb : CallbackQuery):
try:
await app.get_chat_member(cfg.CHID, cb.from_user.id)
if cb.message.chat.type == enums.ChatType.PRIVATE:
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("🗯 Channel", url="https://t.me/SDBOTs_inifinity"),
InlineKeyboardButton("💬 Support", url="https://t.me/SDBOTz")
],[
InlineKeyboardButton("➕ Add me to your Chat ➕", url="https://t.me/SDAutoApproveBot?startgroup")
]
]
)
add_user(cb.from_user.id)
await cb.message.edit("**🦊 Hello {}!\nI'm an auto approve [Admin Join Requests]({}) Bot.\nI can approve users in Groups/Channels.Add me to your chat and promote me to admin with add members permission.\n\n__Powerd By : @SdBotz__**".format(cb.from_user.mention, "https://t.me/telegram/153"), reply_markup=keyboard, disable_web_page_preview=True)
print(cb.from_user.first_name +" Is started Your Bot!")
except UserNotParticipant:
await cb.answer("🙅♂️ You are not joined to channel join and try again. 🙅♂️")
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ info ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@app.on_message(filters.command("users") & filters.user(cfg.SUDO))
async def dbtool(_, m : Message):
xx = all_users()
x = all_groups()
tot = int(xx + x)
await m.reply_text(text=f"""
🍀 Chats Stats 🍀
🙋♂️ Users : `{xx}`
👥 Groups : `{x}`
🚧 Total users & groups : `{tot}` """)
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Broadcast ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@app.on_message(filters.command("bcast") & filters.user(cfg.SUDO))
async def bcast(_, m : Message):
allusers = users
lel = await m.reply_text("`⚡️ Processing...`")
success = 0
failed = 0
deactivated = 0
blocked = 0
for usrs in allusers.find():
try:
userid = usrs["user_id"]
#print(int(userid))
if m.command[0] == "bcast":
await m.reply_to_message.copy(int(userid))
success +=1
except FloodWait as ex:
await asyncio.sleep(ex.value)
if m.command[0] == "bcast":
await m.reply_to_message.copy(int(userid))
except errors.InputUserDeactivated:
deactivated +=1
remove_user(userid)
except errors.UserIsBlocked:
blocked +=1
except Exception as e:
print(e)
failed +=1
await lel.edit(f"✅Successfull to `{success}` users.\n❌ Faild to `{failed}` users.\n👾 Found `{blocked}` Blocked users \n👻 Found `{deactivated}` Deactivated users.")
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Broadcast Forward ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@app.on_message(filters.command("fcast") & filters.user(cfg.SUDO))
async def fcast(_, m : Message):
allusers = users
lel = await m.reply_text("`⚡️ Processing...`")
success = 0
failed = 0
deactivated = 0
blocked = 0
for usrs in allusers.find():
try:
userid = usrs["user_id"]
#print(int(userid))
if m.command[0] == "fcast":
await m.reply_to_message.forward(int(userid))
success +=1
except FloodWait as ex:
await asyncio.sleep(ex.value)
if m.command[0] == "fcast":
await m.reply_to_message.forward(int(userid))
except errors.InputUserDeactivated:
deactivated +=1
remove_user(userid)
except errors.UserIsBlocked:
blocked +=1
except Exception as e:
print(e)
failed +=1
await lel.edit(f"✅Successfull to `{success}` users.\n❌ Faild to `{failed}` users.\n👾 Found `{blocked}` Blocked users \n👻 Found `{deactivated}` Deactivated users.")
print("I'm Alive Now!")
app.run()