mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2026-01-07 20:34:52 +00:00
Learn Pagination
This commit is contained in:
parent
389a4faa75
commit
f3f5f250fe
2 changed files with 107 additions and 3 deletions
104
misskaty/plugins/tes pagination.py
Normal file
104
misskaty/plugins/tes pagination.py
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from pykeyboard import InlineKeyboard
|
||||||
|
from pyrogram import filters
|
||||||
|
from misskaty.helper.http import http
|
||||||
|
from misskaty import app
|
||||||
|
from misskaty.vars import COMMAND_HANDLER
|
||||||
|
|
||||||
|
def split_arr(arr, size):
|
||||||
|
arrs = []
|
||||||
|
while len(arr) > size:
|
||||||
|
pice = arr[:size]
|
||||||
|
arrs.append(pice)
|
||||||
|
arr = arr[size:]
|
||||||
|
arrs.append(arr)
|
||||||
|
return arrs
|
||||||
|
|
||||||
|
async def getDatalk21(chat_id, message_id, kueri, CurrentPage):
|
||||||
|
lk21json = (await http.get(
|
||||||
|
f'https://yasirapi.eu.org/lk21?q={kueri}')).json()
|
||||||
|
res = split_arr(lk21json["result"], 6)
|
||||||
|
if not lk21json.get("result"):
|
||||||
|
return await app.send_message(
|
||||||
|
chat_id=chat_id,
|
||||||
|
reply_to_message_id=message_id,
|
||||||
|
text=(
|
||||||
|
f"Kueri: {kueri}\n"
|
||||||
|
"Results: Sorry could not find any matching results!"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
index = int(CurrentPage - 1)
|
||||||
|
PageLen = len(res)
|
||||||
|
|
||||||
|
lkResult = (
|
||||||
|
f"**Tes of {kueri}**\n"
|
||||||
|
f"{res[index]['judul']}\n\n"
|
||||||
|
"**📌 Link**\n"
|
||||||
|
f"__{res[index]['link']}__"
|
||||||
|
)
|
||||||
|
|
||||||
|
IGNORE_CHAR = "[]"
|
||||||
|
lkResult = ''.join(i for i in lkResult if not i in IGNORE_CHAR)
|
||||||
|
|
||||||
|
return (
|
||||||
|
lkResult,
|
||||||
|
PageLen
|
||||||
|
)
|
||||||
|
|
||||||
|
except (
|
||||||
|
IndexError
|
||||||
|
or KeyError
|
||||||
|
):
|
||||||
|
await app.send_message(
|
||||||
|
chat_id=chat_id,
|
||||||
|
reply_to_message_id=message_id,
|
||||||
|
text=(
|
||||||
|
f"Kueri: {kueri}\n"
|
||||||
|
"Results: Sorry could not find any matching results!"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@app.on_message(filters.command(['lktes'], COMMAND_HANDLER))
|
||||||
|
async def lk21tes(client, message):
|
||||||
|
message_id = message.id
|
||||||
|
chat_id = message.chat.id
|
||||||
|
kueri = ' '.join(message.command[1:])
|
||||||
|
if not kueri:
|
||||||
|
message = await app.ask(
|
||||||
|
message.chat.id,
|
||||||
|
'Now give any word for query!'
|
||||||
|
)
|
||||||
|
kueri = message.text
|
||||||
|
|
||||||
|
CurrentPage = 1
|
||||||
|
lkres, PageLen = await getDatalk21(chat_id, message_id, kueri, CurrentPage)
|
||||||
|
|
||||||
|
keyboard = InlineKeyboard()
|
||||||
|
keyboard.paginate(PageLen, CurrentPage, 'pagination_lk21#{number}' + f'#{kueri}')
|
||||||
|
await message.reply(
|
||||||
|
text=f"{lkres}",
|
||||||
|
reply_markup=keyboard
|
||||||
|
)
|
||||||
|
|
||||||
|
@app.on_callback_query(filters.create(lambda _, __, query: 'pagination_lk21#' in query.data))
|
||||||
|
async def lk21page_callback(client, callback_query):
|
||||||
|
message_id = callback_query.message.id
|
||||||
|
chat_id = callback_query.message.chat.id
|
||||||
|
CurrentPage = int(callback_query.data.split('#')[1])
|
||||||
|
kueri = callback_query.data.split('#')[2]
|
||||||
|
|
||||||
|
try:
|
||||||
|
lkres, PageLen = await getDatalk21(chat_id, message_id, kueri, CurrentPage)
|
||||||
|
except TypeError:
|
||||||
|
return
|
||||||
|
|
||||||
|
keyboard = InlineKeyboard()
|
||||||
|
keyboard.paginate(PageLen, CurrentPage, 'pagination_lk21#{number}' + f'#{kueri}')
|
||||||
|
await app.edit_message_text(
|
||||||
|
chat_id=chat_id,
|
||||||
|
message_id=message_id,
|
||||||
|
text=lkres,
|
||||||
|
reply_markup=keyboard
|
||||||
|
)
|
||||||
|
|
@ -73,13 +73,13 @@ async def urbanDictionary(client, message):
|
||||||
UDReasult, PageLen = await getData(chat_id, message_id, GetWord, CurrentPage)
|
UDReasult, PageLen = await getData(chat_id, message_id, GetWord, CurrentPage)
|
||||||
|
|
||||||
keyboard = InlineKeyboard()
|
keyboard = InlineKeyboard()
|
||||||
keyboard.paginate(PageLen, CurrentPage, 'pagination_keyboard#{number}' + f'#{GetWord}')
|
keyboard.paginate(PageLen, CurrentPage, 'pagination_urban#{number}' + f'#{GetWord}')
|
||||||
await message.reply(
|
await message.reply(
|
||||||
text=f"{UDReasult}",
|
text=f"{UDReasult}",
|
||||||
reply_markup=keyboard
|
reply_markup=keyboard
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.on_callback_query(filters.create(lambda _, __, query: 'pagination_keyboard#' in query.data))
|
@app.on_callback_query(filters.create(lambda _, __, query: 'pagination_urban#' in query.data))
|
||||||
async def ud_callback(client, callback_query):
|
async def ud_callback(client, callback_query):
|
||||||
|
|
||||||
message_id = callback_query.message.id
|
message_id = callback_query.message.id
|
||||||
|
|
@ -93,7 +93,7 @@ async def ud_callback(client, callback_query):
|
||||||
return
|
return
|
||||||
|
|
||||||
keyboard = InlineKeyboard()
|
keyboard = InlineKeyboard()
|
||||||
keyboard.paginate(PageLen, CurrentPage, 'pagination_keyboard#{number}' + f'#{GetWord}')
|
keyboard.paginate(PageLen, CurrentPage, 'pagination_urban#{number}' + f'#{GetWord}')
|
||||||
await app.edit_message_text(
|
await app.edit_message_text(
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
message_id=message_id,
|
message_id=message_id,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue