Skip to content

Commit

Permalink
added MAX_RESUTLS & CACHE_TIME variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh0253 committed Sep 13, 2020
1 parent e1fe2fd commit a02a934
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
10 changes: 10 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
"description": "Name of the collections. Defaults to Telegram_files. If you going to use same database, then use different collection name for each bot",
"value": "Telegram_files",
"required": false
},
"MAX_RESULTS": {
"description": "Maximum limit for inline search results",
"value": "10",
"required": false
},
"CACHE_TIME": {
"description": "The maximum amount of time in seconds that the result of the inline query may be cached on the server",
"value": "300",
"required": false
}
},
"addons": [],
Expand Down
4 changes: 4 additions & 0 deletions info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
API_HASH = environ['API_HASH']
BOT_TOKEN = environ['BOT_TOKEN']

# Bot settings
MAX_RESULTS = int(environ.get('MAX_RESULTS', 10))
CACHE_TIME = int(environ.get('CACHE_TIME', 300))

# Admins & Channels
ADMINS = [int(admin) if re.search('^\d+$', admin) else admin for admin in environ['ADMINS'].split()]
CHANNELS = [int(channel) if re.search('^-100\d+$', channel) else channel for channel in environ['CHANNELS'].split()]
Expand Down
4 changes: 3 additions & 1 deletion plugins/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ async def start(bot, message):
InlineKeyboardButton('Go Inline', switch_inline_query=''),
]]
reply_markup = InlineKeyboardMarkup(buttons)
await message.reply(START_MSG, reply_markup=reply_markup)
await message.reply(
text=START_MSG.format(username=bot.username),
reply_markup=reply_markup)


@Client.on_message(filters.command('channel') & filters.chat(ADMINS))
Expand Down
12 changes: 5 additions & 7 deletions plugins/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from pyrogram import Client, filters, emoji
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultCachedDocument
from utils import get_search_results
from info import SHARE_BUTTON_TEXT

CACHE_TIME = 60
from info import MAX_RESULTS, CACHE_TIME, SHARE_BUTTON_TEXT


@Client.on_inline_query()
Expand All @@ -14,7 +12,7 @@ async def answer(bot, query):
results = []
string = query.query
reply_markup = get_reply_markup(bot.username)
files = await get_search_results(string)
files = await get_search_results(string, max_results=MAX_RESULTS)

for file in files:
results.append(
Expand All @@ -32,13 +30,13 @@ async def answer(bot, query):
switch_pm_text = f"{emoji.FILE_FOLDER} {count} Result{'s' if count > 1 else ''}"
if string:
switch_pm_text += f" for {string}"

await query.answer(results=results,
cache_time=CACHE_TIME,
switch_pm_text=switch_pm_text,
switch_pm_parameter="start")
else:

switch_pm_text = f'{emoji.CROSS_MARK} No results'
if string:
switch_pm_text += f' for "{string}"'
Expand All @@ -54,7 +52,7 @@ def get_reply_markup(username):
buttons = [[
InlineKeyboardButton('Search again', switch_inline_query_current_chat=''),
InlineKeyboardButton(
text='Share bot',
text='Share bot',
url='tg://msg?text='+ quote(SHARE_BUTTON_TEXT.format(username=username))),
]]
return InlineKeyboardMarkup(buttons)
Expand Down
4 changes: 4 additions & 0 deletions sample_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
API_HASH = '0123456789abcdef0123456789abcdef'
BOT_TOKEN = '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11'

# Bot settings
MAX_RESULTS = 10
CACHE_TIME = 300

# Admins & Channels
ADMINS = [12345789, 'admin123', 98765432]
CHANNELS = [-10012345678, -100987654321, 'channelusername']
Expand Down

0 comments on commit a02a934

Please sign in to comment.