forked from Joelkb/DQ-the-file-donor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_ttishow.py
298 lines (275 loc) · 12.4 KB
/
p_ttishow.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
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
from pyrogram import Client, filters, enums
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery
from pyrogram.errors.exceptions.bad_request_400 import MessageTooLong, PeerIdInvalid
from info import ADMINS, LOG_CHANNEL, SUPPORT_CHAT, MELCOW_NEW_USERS, MELCOW_VID, CHNL_LNK, GRP_LNK
from database.users_chats_db import db
from database.ia_filterdb import Media, Media2, db as clientDB, db2 as clientDB2
from utils import get_size, temp, get_settings
from Script import script
from pyrogram.errors import ChatAdminRequired
import asyncio
"""-----------------------------------------https://t.me/GetTGLink/4179 --------------------------------------"""
@Client.on_message(filters.new_chat_members & filters.group)
async def save_group(bot, message):
r_j_check = [u.id for u in message.new_chat_members]
if temp.ME in r_j_check:
if not await db.get_chat(message.chat.id):
total=await bot.get_chat_members_count(message.chat.id)
r_j = message.from_user.mention if message.from_user else "Anonymous"
await bot.send_message(LOG_CHANNEL, script.LOG_TEXT_G.format(message.chat.title, message.chat.id, total, r_j))
await db.add_chat(message.chat.id, message.chat.title)
if message.chat.id in temp.BANNED_CHATS:
# Inspired from a boat of a banana tree
buttons = [[
InlineKeyboardButton('Support', url=f'https://t.me/{SUPPORT_CHAT}')
]]
reply_markup=InlineKeyboardMarkup(buttons)
k = await message.reply(
text='<b>CHAT NOT ALLOWED 🐞\n\nMy admins has restricted me from working here ! If you want to know more about it contact support..</b>',
reply_markup=reply_markup,
)
try:
await k.pin()
except:
pass
await bot.leave_chat(message.chat.id)
return
buttons = [[
InlineKeyboardButton('Sᴜᴘᴘᴏʀᴛ Gʀᴏᴜᴘ', url=GRP_LNK),
InlineKeyboardButton('Uᴘᴅᴀᴛᴇs Cʜᴀɴɴᴇʟ', url=CHNL_LNK)
],[
InlineKeyboardButton("Bᴏᴛ Oᴡɴᴇʀ", url="t.me/creatorbeatz")
]]
reply_markup=InlineKeyboardMarkup(buttons)
await message.reply_text(
text=f"<b>Thankyou For Adding Me In {message.chat.title} ❣️\n\nIf you have any questions & doubts about using me contact support.</b>",
reply_markup=reply_markup)
else:
settings = await get_settings(message.chat.id)
if settings["welcome"]:
for u in message.new_chat_members:
if (temp.MELCOW).get('welcome') is not None:
try:
await (temp.MELCOW['welcome']).delete()
except:
pass
temp.MELCOW['welcome'] = await message.reply_video(
video=(MELCOW_VID),
caption=(script.MELCOW_ENG.format(u.mention, message.chat.title)),
reply_markup=InlineKeyboardMarkup(
[[
InlineKeyboardButton('Sᴜᴘᴘᴏʀᴛ Gʀᴏᴜᴘ', url=GRP_LNK),
InlineKeyboardButton('Uᴘᴅᴀᴛᴇs Cʜᴀɴɴᴇʟ', url=CHNL_LNK)
],[
InlineKeyboardButton("Bᴏᴛ Oᴡɴᴇʀ", url="t.me/creatorbeatz")
]]
),
parse_mode=enums.ParseMode.HTML
)
if settings["auto_delete"]:
await asyncio.sleep(600)
await (temp.MELCOW['welcome']).delete()
@Client.on_message(filters.command('leave') & filters.user(ADMINS))
async def leave_a_chat(bot, message):
if len(message.command) == 1:
return await message.reply('Give me a chat id')
chat = message.command[1]
try:
chat = int(chat)
except:
chat = chat
try:
buttons = [[
InlineKeyboardButton('Support', url=f'https://t.me/{SUPPORT_CHAT}')
]]
reply_markup=InlineKeyboardMarkup(buttons)
await bot.send_message(
chat_id=chat,
text='<b>Hello Friends, \nMy admin has told me to leave from group so i go! If you wanna add me again contact my support group.</b>',
reply_markup=reply_markup,
)
await bot.leave_chat(chat)
await message.reply(f"left the chat `{chat}`")
except Exception as e:
await message.reply(f'Error - {e}')
@Client.on_message(filters.command('disable') & filters.user(ADMINS))
async def disable_chat(bot, message):
if len(message.command) == 1:
return await message.reply('Give me a chat id')
r = message.text.split(None)
if len(r) > 2:
reason = message.text.split(None, 2)[2]
chat = message.text.split(None, 2)[1]
else:
chat = message.command[1]
reason = "No reason Provided"
try:
chat_ = int(chat)
except:
return await message.reply('Give Me A Valid Chat ID')
cha_t = await db.get_chat(int(chat_))
if not cha_t:
return await message.reply("Chat Not Found In DB")
if cha_t['is_disabled']:
return await message.reply(f"This chat is already disabled:\nReason-<code> {cha_t['reason']} </code>")
await db.disable_chat(int(chat_), reason)
temp.BANNED_CHATS.append(int(chat_))
await message.reply('Chat Successfully Disabled')
try:
buttons = [[
InlineKeyboardButton('Support', url=f'https://t.me/{SUPPORT_CHAT}')
]]
reply_markup=InlineKeyboardMarkup(buttons)
await bot.send_message(
chat_id=chat_,
text=f'<b>Hello Friends, \nMy admin has told me to leave from group so i go! If you wanna add me again contact my support group.</b> \nReason : <code>{reason}</code>',
reply_markup=reply_markup)
await bot.leave_chat(chat_)
except Exception as e:
await message.reply(f"Error - {e}")
@Client.on_message(filters.command('enable') & filters.user(ADMINS))
async def re_enable_chat(bot, message):
if len(message.command) == 1:
return await message.reply('Give me a chat id')
chat = message.command[1]
try:
chat_ = int(chat)
except:
return await message.reply('Give Me A Valid Chat ID')
sts = await db.get_chat(int(chat))
if not sts:
return await message.reply("Chat Not Found In DB !")
if not sts.get('is_disabled'):
return await message.reply('This chat is not yet disabled.')
await db.re_enable_chat(int(chat_))
temp.BANNED_CHATS.remove(int(chat_))
await message.reply("Chat Successfully re-enabled")
@Client.on_message(filters.command('stats') & filters.incoming)
async def get_ststs(bot, message):
rju = await message.reply('Fetching stats..')
#users and chats
total_users = await db.total_users_count()
totl_chats = await db.total_chat_count()
#primary db
filesp = await Media.count_documents()
#secondary db
totalsec = await Media2.count_documents()
#primary
stats = await clientDB.command('dbStats')
used_dbSize = (stats['dataSize']/(1024*1024))+(stats['indexSize']/(1024*1024))
free_dbSize = 512-used_dbSize
#secondary
stats2 = await clientDB2.command('dbStats')
used_dbSize2 = (stats2['dataSize']/(1024*1024))+(stats2['indexSize']/(1024*1024))
free_dbSize2 = 512-used_dbSize2
await rju.edit(script.STATUS_TXT.format((int(filesp)+int(totalsec)), total_users, totl_chats, filesp, round(used_dbSize, 2), round(free_dbSize, 2), totalsec, round(used_dbSize2, 2), round(free_dbSize2, 2)))
@Client.on_message(filters.command('invite') & filters.user(ADMINS))
async def gen_invite(bot, message):
if len(message.command) == 1:
return await message.reply('Give me a chat id')
chat = message.command[1]
try:
chat = int(chat)
except:
return await message.reply('Give Me A Valid Chat ID')
try:
link = await bot.create_chat_invite_link(chat)
except ChatAdminRequired:
return await message.reply("Invite Link Generation Failed, Iam Not Having Sufficient Rights")
except Exception as e:
return await message.reply(f'Error {e}')
await message.reply(f'Here is your Invite Link {link.invite_link}')
@Client.on_message(filters.command('ban') & filters.user(ADMINS))
async def ban_a_user(bot, message):
# https://t.me/GetTGLink/4185
if len(message.command) == 1:
return await message.reply('Give me a user id / username')
r = message.text.split(None)
if len(r) > 2:
reason = message.text.split(None, 2)[2]
chat = message.text.split(None, 2)[1]
else:
chat = message.command[1]
reason = "No reason Provided"
try:
chat = int(chat)
except:
pass
try:
k = await bot.get_users(chat)
except PeerIdInvalid:
return await message.reply("This is an invalid user, make sure ia have met him before.")
except IndexError:
return await message.reply("This might be a channel, make sure its a user.")
except Exception as e:
return await message.reply(f'Error - {e}')
else:
jar = await db.get_ban_status(k.id)
if jar['is_banned']:
return await message.reply(f"{k.mention} is already banned\nReason: {jar['ban_reason']}")
await db.ban_user(k.id, reason)
temp.BANNED_USERS.append(k.id)
await message.reply(f"Successfully banned {k.mention}")
@Client.on_message(filters.command('unban') & filters.user(ADMINS))
async def unban_a_user(bot, message):
if len(message.command) == 1:
return await message.reply('Give me a user id / username')
r = message.text.split(None)
if len(r) > 2:
reason = message.text.split(None, 2)[2]
chat = message.text.split(None, 2)[1]
else:
chat = message.command[1]
reason = "No reason Provided"
try:
chat = int(chat)
except:
pass
try:
k = await bot.get_users(chat)
except PeerIdInvalid:
return await message.reply("This is an invalid user, make sure ia have met him before.")
except IndexError:
return await message.reply("Thismight be a channel, make sure its a user.")
except Exception as e:
return await message.reply(f'Error - {e}')
else:
jar = await db.get_ban_status(k.id)
if not jar['is_banned']:
return await message.reply(f"{k.mention} is not yet banned.")
await db.remove_ban(k.id)
temp.BANNED_USERS.remove(k.id)
await message.reply(f"Successfully unbanned {k.mention}")
@Client.on_message(filters.command('users') & filters.user(ADMINS))
async def list_users(bot, message):
# https://t.me/GetTGLink/4184
raju = await message.reply('Getting List Of Users')
users = await db.get_all_users()
out = "Users Saved In DB Are:\n\n"
for user in users:
out += f"<a href=tg://user?id={user['id']}>{user['name']}</a>"
if user['ban_status']['is_banned']:
out += '( Banned User )'
out += '\n'
try:
await raju.edit_text(out)
except MessageTooLong:
with open('users.txt', 'w+') as outfile:
outfile.write(out)
await message.reply_document('users.txt', caption="List Of Users")
@Client.on_message(filters.command('chats') & filters.user(ADMINS))
async def list_chats(bot, message):
raju = await message.reply('Getting List Of chats')
chats = await db.get_all_chats()
out = "Chats Saved In DB Are:\n\n"
for chat in chats:
out += f"**Title:** `{chat['title']}`\n**- ID:** `{chat['id']}`"
if chat['chat_status']['is_disabled']:
out += '( Disabled Chat )'
out += '\n'
try:
await raju.edit_text(out)
except MessageTooLong:
with open('chats.txt', 'w+') as outfile:
outfile.write(out)
await message.reply_document('chats.txt', caption="List Of Chats")