|
2 | 2 | import json, ssl |
3 | 3 | from pathlib import Path |
4 | 4 | from os import path, remove |
| 5 | +from ast import literal_eval |
5 | 6 | from time import sleep, time |
6 | 7 |
|
7 | 8 | import pyshorteners |
@@ -213,7 +214,7 @@ def result(response, userLanguage, torrentType, page, category=None, week=None, |
213 | 214 | markup.add(telebot.types.InlineKeyboardButton(language['previousBtn'][userLanguage], callback_data=cb)) |
214 | 215 |
|
215 | 216 | if query: |
216 | | - markup.add(telebot.types.InlineKeyboardButton(text='Pirate Bay 🔎', switch_inline_query_current_chat=f"!pb {query}")) |
| 217 | + markup.add(telebot.types.InlineKeyboardButton(text='Pirate Bay 🔎', switch_inline_query_current_chat=f"!pb {query}"), telebot.types.InlineKeyboardButton(text='Nyaa 🔎', switch_inline_query_current_chat=f"!nyaa {query}")) |
217 | 218 | elif torrentType == 'top': |
218 | 219 | markup.add(telebot.types.InlineKeyboardButton(text='Pirate Bay 🔎', switch_inline_query_current_chat=f"!pb --top")) |
219 | 220 |
|
@@ -807,6 +808,21 @@ def query_text(inline_query): |
807 | 808 | else: |
808 | 809 | bot.answer_inline_query(inline_query.id, [telebot.types.InlineQueryResultArticle(id=0, title=language['noResults'][userLanguage], url='https://t.me/h9youtube', hide_url=True, thumb_url='https://image.freepik.com/free-vector/error-404-found-glitch-effect_8024-4.jpg', input_message_content=telebot.types.InputTextMessageContent(language['noResults'][userLanguage], parse_mode='HTML'))], is_personal=True) |
809 | 810 |
|
| 811 | + elif inline_query.query[:5] == '!nyaa': |
| 812 | + page = int(inline_query.offset) if inline_query.offset else 0 |
| 813 | + results = literal_eval(requests.get('https://api.api-zero.workers.dev/nyaasi/'+inline_query.query[6:]).text) |
| 814 | + |
| 815 | + if 'error' not in results: |
| 816 | + results = results[page*50:(page+1)*50] |
| 817 | + queryResult = [] |
| 818 | + for count, item in enumerate(results): |
| 819 | + queryResult.append(telebot.types.InlineQueryResultArticle(id=count, title=item['Name'], url=item['Url'], hide_url=True, thumb_url='https://i.pinimg.com/736x/2d/8d/5c/2d8d5c5e953fd50493e388da2759ac41.jpg', thumb_width='123', thumb_height='182', description=f"{item['Size']} size {item['Seeder']} seeders {item['Leecher']} leechers", input_message_content=telebot.types.InputTextMessageContent(queryMessageContent(userId=inline_query.from_user.id, torrentz=item, source='nyaa'), parse_mode='HTML'))) |
| 820 | + |
| 821 | + bot.answer_inline_query(inline_query.id, queryResult, next_offset=page+1 if len(results) else None, is_personal=True, cache_time=0) |
| 822 | + |
| 823 | + else: |
| 824 | + bot.answer_inline_query(inline_query.id, [telebot.types.InlineQueryResultArticle(id=0, title=language['noResults'][userLanguage], url='https://t.me/h9youtube', hide_url=True, thumb_url='https://image.freepik.com/free-vector/error-404-found-glitch-effect_8024-4.jpg', input_message_content=telebot.types.InputTextMessageContent(language['noResults'][userLanguage], parse_mode='HTML'))], is_personal=True) |
| 825 | + |
810 | 826 | else: |
811 | 827 | offset = int(inline_query.offset.split(':')[0]) if inline_query.offset else 0 |
812 | 828 | page = int(inline_query.offset.split(':')[1]) if inline_query.offset else 1 |
@@ -849,6 +865,9 @@ def queryMessageContent(userId, torrentz, source): |
849 | 865 | elif source == 'tpb': |
850 | 866 | msg = f"<b>✨ {torrentz.title}</b>\n\n{language['size'][userLanguage]}{torrentz.filesize}\n{language['seeders'][userLanguage]}{torrentz.seeds}\n{language['leechers'][userLanguage]}{torrentz.leeches}\n{language['uploadedBy'][userLanguage]}{torrentz.uploader}\n{language['uploadedOn'][userLanguage]}{torrentz.upload_date}\n\n<b>Magnet Link: </b><code>{torrentz.magnetlink}</code>" |
851 | 867 |
|
| 868 | + elif source == 'nyaa': |
| 869 | + msg = f"<b>✨ {torrentz['Name']}</b>\n\n{language['size'][userLanguage]}{torrentz['Size']}\n{language['seeders'][userLanguage]}{torrentz['Seeder']}\n{language['leechers'][userLanguage]}{torrentz['Leecher']}\n{language['uploadedOn'][userLanguage]}{torrentz['Date']}\n\n<b>Magnet Link: </b><code>{torrentz['Magnet']}</code>" |
| 870 | + |
852 | 871 | return msg |
853 | 872 |
|
854 | 873 | # Polling Bot |
|
0 commit comments