forked from Rishikesh-Sharma09/Auto-Filter-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinline.py
73 lines (63 loc) · 2.78 KB
/
inline.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
import logging, time
from pyrogram import Client, emoji, filters
from pyrogram.errors.exceptions.bad_request_400 import QueryIdInvalid
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultCachedDocument, InlineQuery
from database.ia_filterdb import get_search_results
from database.users_chats_db import db
from utils import is_subscribed, get_size, temp, get_verify_status, update_verify_status
from info import CACHE_TIME, AUTH_CHANNEL, SUPPORT_LINK, UPDATES_LINK, FILE_CAPTION, IS_VERIFY, VERIFY_EXPIRE
cache_time = 0 if AUTH_CHANNEL else CACHE_TIME
def is_banned(query: InlineQuery):
return query.from_user and query.from_user.id in temp.BANNED_USERS
@Client.on_inline_query()
async def inline_search(bot, query):
"""Show search results for given inline query"""
if is_banned(query):
await query.answer(results=[],
cache_time=0,
switch_pm_text="You're banned user :(",
switch_pm_parameter="start")
return
results = []
string = query.query
offset = int(query.offset or 0)
files, next_offset, total = await get_search_results(string, offset=offset)
for file in files:
reply_markup = get_reply_markup()
f_caption=FILE_CAPTION.format(
file_name=file.file_name,
file_size=get_size(file.file_size),
caption=file.caption
)
results.append(
InlineQueryResultCachedDocument(
title=file.file_name,
document_file_id=file.file_id,
caption=f_caption,
description=f'Size: {get_size(file.file_size)}',
reply_markup=reply_markup))
if results:
switch_pm_text = f"{emoji.FILE_FOLDER} Results - {total}"
if string:
switch_pm_text += f' For: {string}'
await query.answer(results=results,
is_personal = True,
cache_time=cache_time,
switch_pm_text=switch_pm_text,
switch_pm_parameter="start",
next_offset=str(next_offset))
else:
switch_pm_text = f'{emoji.CROSS_MARK} No Results'
if string:
switch_pm_text += f' For: {string}'
await query.answer(results=[],
is_personal = True,
cache_time=cache_time,
switch_pm_text=switch_pm_text,
switch_pm_parameter="start")
def get_reply_markup():
buttons = [[
InlineKeyboardButton('⚡️ ᴜᴘᴅᴀᴛᴇs ᴄʜᴀɴɴᴇʟ ⚡️', url=UPDATES_LINK),
InlineKeyboardButton('💡 Support Group 💡', url=SUPPORT_LINK)
]]
return InlineKeyboardMarkup(buttons)