forked from HA-Bots/Auto-Filter-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_ttishow.py
238 lines (226 loc) · 9.53 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
import random, os, sys
from pyrogram import Client, filters, enums
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from pyrogram.errors.exceptions.bad_request_400 import MessageTooLong, PeerIdInvalid
from info import ADMINS, LOG_CHANNEL, PICS, SUPPORT_LINK, UPDATES_LINK
from database.users_chats_db import db
from database.ia_filterdb import Media
from utils import get_size, temp, get_settings
from Script import script
from pyrogram.errors import ChatAdminRequired
@Client.on_chat_member_updated(filters.group)
async def welcome(bot, message):
if message.new_chat_member and not message.old_chat_member:
if message.new_chat_member.user.id == temp.ME:
buttons = [[
InlineKeyboardButton('ᴜᴘᴅᴀᴛᴇ', url=UPDATES_LINK),
InlineKeyboardButton('ꜱᴜᴘᴘᴏʀᴛ', url=SUPPORT_LINK)
]]
reply_markup=InlineKeyboardMarkup(buttons)
user = message.from_user.mention if message.from_user else "Dear"
await bot.send_photo(chat_id=message.chat.id, photo=random.choice(PICS), caption=f"👋 Hello {user},\n\nThank you for adding me to the <b>'{message.chat.title}'</b> group, Don't forget to make me admin. If you want to know more ask the support group. 😘</b>", reply_markup=reply_markup)
if not await db.get_chat(message.chat.id):
total = await bot.get_chat_members_count(message.chat.id)
username = f'@{message.chat.username}' if message.chat.username else 'Private'
await bot.send_message(LOG_CHANNEL, script.NEW_GROUP_TXT.format(message.chat.title, message.chat.id, username, total))
await db.add_chat(message.chat.id, message.chat.title)
return
settings = await get_settings(message.chat.id)
if settings["welcome"]:
WELCOME = settings['welcome_text']
welcome_msg = WELCOME.format(
mention = message.new_chat_member.user.mention,
title = message.chat.title
)
await bot.send_message(chat_id=message.chat.id, text=welcome_msg)
@Client.on_message(filters.command('restart') & filters.user(ADMINS))
async def restart_bot(bot, message):
msg = await message.reply("Restarting...")
with open('restart.txt', 'w+') as file:
file.write(f"{msg.chat.id}\n{msg.id}")
os.execl(sys.executable, sys.executable, "bot.py")
@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')
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:
chat = chat
try:
buttons = [[
InlineKeyboardButton('Support Group', url=SUPPORT_LINK)
]]
reply_markup=InlineKeyboardMarkup(buttons)
await bot.send_message(
chat_id=chat,
text=f'Hello Friends,\nMy owner has told me to leave from group so i go! If you need add me again contact my support group.\nReason - <code>{reason}</code>',
reply_markup=reply_markup,
)
await bot.leave_chat(chat)
await message.reply(f"<b>✅️ Successfully bot left from this group - `{chat}`</b>")
except Exception as e:
await message.reply(f'Error - {e}')
@Client.on_message(filters.command('ban_grp') & 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 database")
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 Group', url=SUPPORT_LINK)
]]
reply_markup=InlineKeyboardMarkup(buttons)
await bot.send_message(
chat_id=chat_,
text=f'Hello Friends,\nMy owner has told me to leave from group so i go! If you need add me again contact my support group.\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('unban_grp') & 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 database")
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('invite_link') & filters.user(ADMINS))
async def gen_invite_link(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 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_user') & filters.user(ADMINS))
async def ban_a_user(bot, message):
if len(message.command) == 1:
return await message.reply('Give me a user ID or 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 Exception as e:
return await message.reply(f'Error - {e}')
else:
if k.id in ADMINS:
return await message.reply('You ADMINS')
jar = await db.get_ban_status(k.id)
if jar['is_banned']:
return await message.reply(f"{k.mention} is already banned.\nReason - <code>{jar['ban_reason']}</code>")
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_user') & filters.user(ADMINS))
async def unban_a_user(bot, message):
if len(message.command) == 1:
return await message.reply('Give me a user ID or Username')
r = message.text.split(None)
if len(r) > 2:
chat = message.text.split(None, 2)[1]
else:
chat = message.command[1]
try:
chat = int(chat)
except:
pass
try:
k = await bot.get_users(chat)
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):
raju = await message.reply('Getting list of users')
users = await db.get_all_users()
out = "Users saved in database are:\n\n"
async for user in users:
out += f"**Name:** {user['name']}\n**ID:** `{user['id']}`"
if user['ban_status']['is_banned']:
out += ' (Banned User)'
if user['verify_status']['is_verified']:
out += ' (Verified User)'
out += '\n\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")
await raju.delete()
os.remove('users.txt')
@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 database are:\n\n"
async for chat in chats:
out += f"**Title:** {chat['title']}\n**ID:** `{chat['id']}`"
if chat['chat_status']['is_disabled']:
out += ' (Disabled Chat)'
out += '\n\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")
await raju.delete()
os.remove('chats.txt')