Skip to content

Commit

Permalink
customize buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
subinps committed Oct 31, 2021
1 parent 30ad6a1 commit bdfd02c
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 91 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
## Features

- [x] Auto Filter
- [x] Manuel Filter
- [x] Manual Filter
- [x] IMDB
- [x] Admin Commands
- [x] Broadcast
Expand Down
4 changes: 3 additions & 1 deletion info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
DATABASE_URI = environ.get('DATABASE_URI', "")
DATABASE_NAME = environ.get('DATABASE_NAME', "Rajappan")
COLLECTION_NAME = environ.get('COLLECTION_NAME', 'Telegram_files')

# Others
LOG_CHANNEL = int(environ.get('LOG_CHANNEL', ''))
SUPPORT_CHAT = environ.get('SUPPORT_CHAT', 'TeamEvamaria')

P_TTTI_SHOW_OFF = environ.get('P_TTTI_SHOW_OFF', False)
CUSTOM_FILE_CAPTION = environ.get("CUSTOM_FILE_CAPTION", None)
22 changes: 17 additions & 5 deletions plugins/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@

logger = logging.getLogger(__name__)

@Client.on_message(filters.private & filters.command("start"))
@Client.on_message(filters.command("start"))
async def start(client, message):
if message.chat.type in ['group', 'supergroup']:
buttons = [
[
InlineKeyboardButton('🤖 Updates', url='https://TeamEvamaria')
],
[
InlineKeyboardButton('ℹ️ Help', url=f"https://t.me/{temp.U_NAME}?start=help"),
]
]
reply_markup = InlineKeyboardMarkup(buttons)

if not await db.get_chat(message.chat.id):
total=await client.get_chat_members_count(message.chat.id)
await client.send_message(LOG_CHANNEL, script.LOG_TEXT_G.format(message.chat.title, message.chat.id, total, "Unknown"))
await db.add_chat(message.chat.id, message.chat.title)
return await message.reply(script.START_TXT.format(message.from_user.mention if message.from_user else message.chat.title), reply_markup=reply_markup)
if not await db.is_user_exist(message.from_user.id):
await db.add_user(message.from_user.id, message.from_user.first_name)
await client.send_message(LOG_CHANNEL, script.LOG_TEXT_P.format(message.from_user.id, message.from_user.mention))
Expand All @@ -34,8 +50,6 @@ async def start(client, message):
reply_markup=reply_markup,
parse_mode='html'
)
if not await db.is_user_exist(message.from_user.id):
await db.add_user(message.from_user.id, message.from_user.first_name)
return
if AUTH_CHANNEL and not await is_subscribed(client, message):
try:
Expand Down Expand Up @@ -77,8 +91,6 @@ async def start(client, message):
reply_markup=reply_markup,
parse_mode='html'
)
if not await db.is_user_exist(message.from_user.id):
await db.add_user(message.from_user.id, message.from_user.first_name)
return
file_id = message.command[1]
files = (await get_file_details(file_id))[0]
Expand Down
8 changes: 6 additions & 2 deletions plugins/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

@Client.on_message((filters.private | filters.group) & filters.command('connect'))
async def addconnection(client,message):
userid = message.from_user.id
userid = message.reply_to_message.from_user.id if message.from_user else None
if not userid:
return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
chat_type = message.chat.type

if chat_type == "private":
Expand Down Expand Up @@ -74,7 +76,9 @@ async def addconnection(client,message):

@Client.on_message((filters.private | filters.group) & filters.command('disconnect'))
async def deleteconnection(client,message):
userid = message.from_user.id
userid = message.reply_to_message.from_user.id if message.from_user else None
if not userid:
return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
chat_type = message.chat.type

if chat_type == "private":
Expand Down
16 changes: 12 additions & 4 deletions plugins/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

@Client.on_message(filters.command(['filter', 'add']) & filters.incoming)
async def addfilter(client, message):
userid = message.from_user.id
userid = message.from_user.id if message.from_user else None
if not userid:
return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
chat_type = message.chat.type
args = message.text.html.split(None, 1)

Expand Down Expand Up @@ -118,7 +120,9 @@ async def addfilter(client, message):
async def get_all(client, message):

chat_type = message.chat.type
userid = message.from_user.id
userid = message.reply_to_message.from_user.id if message.from_user else None
if not userid:
return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
if chat_type == "private":
userid = message.from_user.id
grpid = await active_connection(str(userid))
Expand Down Expand Up @@ -178,7 +182,9 @@ async def get_all(client, message):

@Client.on_message(filters.command('del') & filters.incoming)
async def deletefilter(client, message):
userid = message.from_user.id
userid = message.reply_to_message.from_user.id if message.from_user else None
if not userid:
return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
chat_type = message.chat.type

if chat_type == "private":
Expand Down Expand Up @@ -227,7 +233,9 @@ async def deletefilter(client, message):

@Client.on_message(filters.command('delall') & filters.incoming)
async def delallconfirm(client, message):
userid = message.from_user.id
userid = message.reply_to_message.from_user.id if message.from_user else None
if not userid:
return await message.reply(f"You are anonymous admin. Use /connect {message.chat.id} in PM")
chat_type = message.chat.type

if chat_type == "private":
Expand Down
2 changes: 0 additions & 2 deletions plugins/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
logger = logging.getLogger(__name__)
lock = asyncio.Lock()



@Client.on_callback_query(filters.regex(r'^index'))
async def index_files(bot, query):
if query.data.startswith('index_cancel'):
Expand Down
115 changes: 57 additions & 58 deletions plugins/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ async def showid(client, message):
if message.reply_to_message:
_id += (
"<b>➲ User ID</b>: "
f"<code>{message.from_user.id}</code>\n"
f"<code>{message.from_user.id if message.from_user else 'Anonymous'}</code>\n"
"<b>➲ Replied User ID</b>: "
f"<code>{message.reply_to_message.from_user.id}</code>\n"
f"<code>{message.reply_to_message.from_user.id if message.reply_to_message.from_user else 'Anonymous'}</code>\n"
)
file_info = get_file_id(message.reply_to_message)
else:
_id += (
"<b>➲ User ID</b>: "
f"<code>{message.from_user.id}</code>\n"
f"<code>{message.from_user.id if message.from_user else 'Anonymous'}</code>\n"
)
file_info = get_file_id(message)
if file_info:
Expand Down Expand Up @@ -67,62 +67,61 @@ async def who_is(client, message):
await status_message.edit(str(error))
return
if from_user is None:
await status_message.edit("no valid user_id / message specified")
else:
message_out_str = ""
message_out_str += f"<b>➲First Name:</b> {from_user.first_name}\n"
last_name = from_user.last_name or "<b>None</b>"
message_out_str += f"<b>➲Last Name:</b> {last_name}\n"
message_out_str += f"<b>➲Telegram ID:</b> <code>{from_user.id}</code>\n"
username = from_user.username or "<b>None</b>"
dc_id = from_user.dc_id or "[User Doesnt Have A Valid DP]"
message_out_str += f"<b>➲Data Centre:</b> <code>{dc_id}</code>\n"
message_out_str += f"<b>➲User Name:</b> @{username}\n"
message_out_str += f"<b>➲User 𝖫𝗂𝗇𝗄:</b> <a href='tg://user?id={from_user.id}'><b>Click Here</b></a>\n"
if message.chat.type in (("supergroup", "channel")):
try:
chat_member_p = await message.chat.get_member(from_user.id)
joined_date = datetime.fromtimestamp(
chat_member_p.joined_date or time.time()
).strftime("%Y.%m.%d %H:%M:%S")
message_out_str += (
"<b>➲Joined this Chat on:</b> <code>"
f"{joined_date}"
"</code>\n"
)
except UserNotParticipant:
pass
chat_photo = from_user.photo
if chat_photo:
local_user_photo = await client.download_media(
message=chat_photo.big_file_id
)
buttons = [[
InlineKeyboardButton('🔐 Close', callback_data='close_data')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await message.reply_photo(
photo=local_user_photo,
quote=True,
reply_markup=reply_markup,
caption=message_out_str,
parse_mode="html",
disable_notification=True
)
os.remove(local_user_photo)
else:
buttons = [[
InlineKeyboardButton('🔐 Close', callback_data='close_data')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await message.reply_text(
text=message_out_str,
reply_markup=reply_markup,
quote=True,
parse_mode="html",
disable_notification=True
return await status_message.edit("no valid user_id / message specified")
message_out_str = ""
message_out_str += f"<b>➲First Name:</b> {from_user.first_name}\n"
last_name = from_user.last_name or "<b>None</b>"
message_out_str += f"<b>➲Last Name:</b> {last_name}\n"
message_out_str += f"<b>➲Telegram ID:</b> <code>{from_user.id}</code>\n"
username = from_user.username or "<b>None</b>"
dc_id = from_user.dc_id or "[User Doesnt Have A Valid DP]"
message_out_str += f"<b>➲Data Centre:</b> <code>{dc_id}</code>\n"
message_out_str += f"<b>➲User Name:</b> @{username}\n"
message_out_str += f"<b>➲User 𝖫𝗂𝗇𝗄:</b> <a href='tg://user?id={from_user.id}'><b>Click Here</b></a>\n"
if message.chat.type in (("supergroup", "channel")):
try:
chat_member_p = await message.chat.get_member(from_user.id)
joined_date = datetime.fromtimestamp(
chat_member_p.joined_date or time.time()
).strftime("%Y.%m.%d %H:%M:%S")
message_out_str += (
"<b>➲Joined this Chat on:</b> <code>"
f"{joined_date}"
"</code>\n"
)
await status_message.delete()
except UserNotParticipant:
pass
chat_photo = from_user.photo
if chat_photo:
local_user_photo = await client.download_media(
message=chat_photo.big_file_id
)
buttons = [[
InlineKeyboardButton('🔐 Close', callback_data='close_data')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await message.reply_photo(
photo=local_user_photo,
quote=True,
reply_markup=reply_markup,
caption=message_out_str,
parse_mode="html",
disable_notification=True
)
os.remove(local_user_photo)
else:
buttons = [[
InlineKeyboardButton('🔐 Close', callback_data='close_data')
]]
reply_markup = InlineKeyboardMarkup(buttons)
await message.reply_text(
text=message_out_str,
reply_markup=reply_markup,
quote=True,
parse_mode="html",
disable_notification=True
)
await status_message.delete()

@Client.on_message(filters.command(["imdb", 'search']))
async def imdb_search(client, message):
Expand Down
55 changes: 37 additions & 18 deletions plugins/pm_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from Script import script
import pyrogram
from database.connections_mdb import active_connection, all_connections, delete_connection, if_active, make_active, make_inactive
from info import ADMINS, AUTH_CHANNEL, AUTH_USERS, CUSTOM_FILE_CAPTION, AUTH_GROUPS
from info import ADMINS, AUTH_CHANNEL, AUTH_USERS, CUSTOM_FILE_CAPTION, AUTH_GROUPS, P_TTTI_SHOW_OFF
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram import Client, filters
from pyrogram.errors import FloodWait, UserIsBlocked, MessageNotModified, PeerIdInvalid
Expand Down Expand Up @@ -80,19 +80,28 @@ async def next_page(bot, query):
if not search:
await query.answer("You are using this for one of my old message, please send the request again.",show_alert=True)
return
btn=[]

files, n_offset, total = await get_search_results(search, offset=offset, filter=True)
try:
n_offset = int(n_offset)
except:
n_offset = 0
if files:
for file in files:
file_id = file.file_id
btn.append(
[InlineKeyboardButton(text=f"{file.file_name}", callback_data=f'files#{file_id}'), InlineKeyboardButton(text=f"{get_size(file.file_size)}", callback_data=f'files_#{file_id}')]
)

if not files:
return
btn = [
[
InlineKeyboardButton(
text=f"{file.file_name}", callback_data=f'files#{file.file_id}'
),
InlineKeyboardButton(
text=f"{get_size(file.file_size)}",
callback_data=f'files_#{file.file_id}',
),
]
for file in files
]

if 0 < offset <= 10:
off_set = 0
elif offset == 0:
Expand Down Expand Up @@ -320,6 +329,9 @@ async def cb_handler(client: Client, query: CallbackQuery):
if AUTH_CHANNEL and not await is_subscribed(client, query):
await query.answer(url=f"https://t.me/{temp.U_NAME}?start={file_id}")
return
elif P_TTTI_SHOW_OFF:
await query.answer(url=f"https://t.me/{temp.U_NAME}?start={file_id}")
return
else:
await client.send_cached_media(
chat_id=query.from_user.id,
Expand Down Expand Up @@ -378,7 +390,7 @@ async def cb_handler(client: Client, query: CallbackQuery):
)
elif query.data == "help":
buttons = [[
InlineKeyboardButton('Manuel Filter', callback_data='manuelfilter'),
InlineKeyboardButton('Manual Filter', callback_data='manuelfilter'),
InlineKeyboardButton('Auto Filter', callback_data='autofilter')
],[
InlineKeyboardButton('Connection', callback_data='coct'),
Expand Down Expand Up @@ -522,18 +534,25 @@ async def cb_handler(client: Client, query: CallbackQuery):
async def auto_filter(client, message):
if re.findall("((^\/|^,|^!|^\.|^[\U0001F600-\U000E007F]).*)", message.text):
return
if 2 < len(message.text) < 100:
btn = []
if 2 < len(message.text) < 100:

search = message.text
files, offset, total_results = await get_search_results(search.lower(), offset=0)
if files:
for file in files:
file_id = file.file_id
btn.append(
[InlineKeyboardButton(text=f"{file.file_name}", callback_data=f'files#{file_id}'), InlineKeyboardButton(text=f"{get_size(file.file_size)}", callback_data=f'files_#{file_id}')]
)
if not btn:
if not files:
return
btn = [
[
InlineKeyboardButton(
text=f"{file.file_name}",
callback_data=f'files#{file.file_id}',
),
InlineKeyboardButton(
text=f"{get_size(file.file_size)}",
callback_data=f'files_#{file.file_id}',
),
]
for file in files
]

if offset != "":
key = f"{message.chat.id}-{message.message_id}"
Expand Down

0 comments on commit bdfd02c

Please sign in to comment.