diff --git a/nana/assistant/inline.py b/nana/assistant/inline.py index ab442d07..f96093d6 100644 --- a/nana/assistant/inline.py +++ b/nana/assistant/inline.py @@ -1,7 +1,7 @@ import sys import traceback import random -import requests +import aiohttp import git import os from datetime import datetime @@ -305,53 +305,76 @@ async def inline_query_handler(client, query): return search = string.split(None, 1)[1] variables = {'search' : search} - json = requests.post(url, json={'query': anime_query, 'variables': variables}).json()['data'].get('Media', None) - if json: - msg = f"**{json['title']['romaji']}** (`{json['title']['native']}`)\n**Type**: {json['format']}\n**Status**: {json['status']}\n**Episodes**: {json.get('episodes', 'N/A')}\n**Duration**: {json.get('duration', 'N/A')} Per Ep.\n**Score**: {json['averageScore']}\n**Genres**: `" - for x in json['genres']: - msg += f"{x}, " - msg = msg[:-2] + '`\n' - msg += "**Studios**: `" - for x in json['studios']['nodes']: - msg += f"{x['name']}, " - msg = msg[:-2] + '`\n' - info = json.get('siteUrl') - trailer = json.get('trailer', None) - if trailer: - trailer_id = trailer.get('id', None) - site = trailer.get('site', None) - if site == "youtube": trailer = 'https://youtu.be/' + trailer_id - description = json.get('description', 'N/A').replace('', '').replace('', '').replace('
', '') - msg += shorten(description, info) - image = json.get('bannerImage', None) - if trailer: - buttons = [[InlineKeyboardButton("More Info", url=info), InlineKeyboardButton("Trailer 🎬", url=trailer)], - [InlineKeyboardButton('Add to Watchlist', callback_data=f'addfav_{json["title"]["romaji"]}')]] - else: - buttons = [[InlineKeyboardButton("More Info", url=info), - InlineKeyboardButton('Add to Watchlist', callback_data=f'addfav_{json["title"]["romaji"]}')]] - if image: - answers.append(InlineQueryResultPhoto( - caption=msg, - photo_url=image, - parse_mode="markdown", - title=f"{json['title']['romaji']}", - description=f"{json['format']}", - reply_markup=InlineKeyboardMarkup(buttons))) - await client.answer_inline_query(query.id, - results=answers, - cache_time=0 - ) - else: - answers.append(InlineQueryResultArticle( - title=f"{json['title']['romaji']}", - description=f"{json['averageScore']}", - input_message_content=InputTextMessageContent(msg, parse_mode="markdown", disable_web_page_preview=True), - reply_markup=InlineKeyboardMarkup(buttons))) - await client.answer_inline_query(query.id, - results=answers, - cache_time=0 - ) + async with aiohttp.ClientSession() as session: + async with session.post(url, json={'query': anime_query, 'variables': variables}) as resp: + r = await resp.json() + json = r['data'].get('Media', None) + if json: + msg = f"**{json['title']['romaji']}** (`{json['title']['native']}`)\n**Type**: {json['format']}\n**Status**: {json['status']}\n**Episodes**: {json.get('episodes', 'N/A')}\n**Duration**: {json.get('duration', 'N/A')} Per Ep.\n**Score**: {json['averageScore']}\n**Genres**: `" + for x in json['genres']: + msg += f"{x}, " + msg = msg[:-2] + '`\n' + msg += "**Studios**: `" + for x in json['studios']['nodes']: + msg += f"{x['name']}, " + msg = msg[:-2] + '`\n' + info = json.get('siteUrl') + trailer = json.get('trailer', None) + if trailer: + trailer_id = trailer.get('id', None) + site = trailer.get('site', None) + if site == "youtube": trailer = 'https://youtu.be/' + trailer_id + description = json.get('description', 'N/A').replace('', '').replace('', '').replace('
', '') + msg += shorten(description, info) + image = json.get('bannerImage', None) + if trailer: + buttons = [[InlineKeyboardButton("More Info", url=info), InlineKeyboardButton("Trailer 🎬", url=trailer)], + [InlineKeyboardButton('Add to Watchlist', callback_data=f'addfav_{json["title"]["romaji"]}')]] + else: + buttons = [[InlineKeyboardButton("More Info", url=info), + InlineKeyboardButton('Add to Watchlist', callback_data=f'addfav_{json["title"]["romaji"]}')]] + if image: + answers.append(InlineQueryResultPhoto( + caption=msg, + photo_url=image, + parse_mode="markdown", + title=f"{json['title']['romaji']}", + description=f"{json['format']}", + reply_markup=InlineKeyboardMarkup(buttons))) + else: + answers.append(InlineQueryResultArticle( + title=f"{json['title']['romaji']}", + description=f"{json['averageScore']}", + input_message_content=InputTextMessageContent(msg, parse_mode="markdown", disable_web_page_preview=True), + reply_markup=InlineKeyboardMarkup(buttons))) + await client.answer_inline_query(query.id, + results=answers, + cache_time=0 + ) + + elif string.split()[0] == "favourite": + fav = sql.get_fav(Owner) + if fav: + text = "**My watchlist:**\n" + for title in fav: + text += f" - {title.data}\n" + keyb = [ + [InlineKeyboardButton(text="Watched ✅", callback_data=f"remfav_{Owner}")] + ] + answers.append(InlineQueryResultArticle( + title="Favourites", + description="Anime", + input_message_content=InputTextMessageContent(text, parse_mode="markdown"), + reply_markup=InlineKeyboardMarkup(keyb))) + else: + answers.append(InlineQueryResultArticle( + title="Fabourites", + description="Anime", + input_message_content=InputTextMessageContent("**No favourites yet!**", parse_mode="markdown"))) + await client.answer_inline_query(query.id, + results=answers, + cache_time=0 + ) elif string.split()[0] == "favourite": fav = sql.get_fav(Owner) diff --git a/nana/assistant/updater.py b/nana/assistant/updater.py index 52a3e032..8c697368 100644 --- a/nana/assistant/updater.py +++ b/nana/assistant/updater.py @@ -1,5 +1,5 @@ import random - +import os from git import Repo from git.exc import GitCommandError, NoSuchPathError, InvalidGitRepositoryError from pyrogram import filters @@ -134,6 +134,16 @@ async def update_button(client, query): await client.send_message(Owner, "no heroku application found, but a key given? 😕 ") await client.send_message(Owner, "Build Unsuccess, Check heroku build log for more detail") return + else: + try: + os.system('git reset --hard') + os.system('git pull') + os.system('pip install -U -r requirements.txt') + await client.send_message(Owner, "Built Successfully, Please Restart Manually in /settings") + return + except Exception as e: + await client.send_message(Owner, f"Build Unsuccess,\nLog:{e}") + return try: upstream.pull(brname) await client.send_message(Owner, "Successfully Updated!\nBot is restarting...") diff --git a/nana/helpers/deldog.py b/nana/helpers/deldog.py index 9b9b0404..eda6a586 100644 --- a/nana/helpers/deldog.py +++ b/nana/helpers/deldog.py @@ -1,19 +1,9 @@ -import requests - +import aiohttp async def deldog(message, data): - BASE_URL = 'https://del.dog' - r = requests.post(f'{BASE_URL}/documents', data=data.encode('utf-8')) - if r.status_code == 404: - await message.edit('Failed to reach dogbin') - r.raise_for_status() - res = r.json() - if r.status_code != 200: - await message.edit(res['message']) - r.raise_for_status() - key = res['key'] - if res['isUrl']: - reply = f'Shortened URL: {BASE_URL}/{key}\nYou can view stats, etc. [here]({BASE_URL}/v/{key})' - else: - reply = f'{BASE_URL}/{key}' + BASE_URL = 'https://nekobin.com' + async with aiohttp.ClientSession() as session: + async with session.post(f'{BASE_URL}/api/documents', json={"content":data}, timeout=3) as response: + key = (await response.json())["result"]["key"] + reply = f'{BASE_URL}/raw/{key}' return reply \ No newline at end of file diff --git a/nana/modules/animelist.py b/nana/modules/animelist.py index 80c1097f..2345281f 100644 --- a/nana/modules/animelist.py +++ b/nana/modules/animelist.py @@ -74,20 +74,20 @@ def t(milliseconds: int) -> str: airing_query = ''' query ($id: Int,$search: String) { - Media (id: $id, type: ANIME,search: $search) { - id - episodes - title { - romaji - english - native + Media (id: $id, type: ANIME,search: $search) { + id + episodes + title { + romaji + english + native + } + nextAiringEpisode { + airingAt + timeUntilAiring + episode + } } - nextAiringEpisode { - airingAt - timeUntilAiring - episode - } - } } ''' @@ -233,8 +233,7 @@ async def character_search(client, message): return search = search[1] variables = {'query': search} - json = requests.post(url, json={'query': character_query, 'variables': variables}).json()[ - 'data'].get('Character', None) + json = requests.post(url, json={'query': character_query, 'variables': variables}).json()['data'].get('Character', None) if json: ms_g = f"**{json.get('name').get('full')}**(`{json.get('name').get('native')}`)\n" description = f"{json['description']}" diff --git a/nana/modules/lydia.py b/nana/modules/lydia.py index 9c5a8176..33b72770 100644 --- a/nana/modules/lydia.py +++ b/nana/modules/lydia.py @@ -91,11 +91,13 @@ async def chat_bot(client, message): async def check_message(_client, message): - reply_msg = message.reply_to_message - if message.text.lower() == f"@{OwnerUsername}": + if message.chat.type == 'private': return True - if reply_msg: - if reply_msg.from_user.id == Owner: - return True else: - return False + if message.text.lower() == f"@{OwnerUsername}": + return True + if message.reply_to_message: + if message.reply_to_message.from_user.id == Owner: + return True + else: + return False diff --git a/nana/modules/ocr.py b/nana/modules/ocr.py index 14b2b256..7872ac4a 100644 --- a/nana/modules/ocr.py +++ b/nana/modules/ocr.py @@ -64,11 +64,11 @@ async def ocr(client, message): try: ParsedText = test_file["ParsedResults"][0]["ParsedText"] except BaseException as e: - await message.reply(e) + await edrep(message, text=e) else: if ParsedText == 'ParsedResults': await message.delete() return else: - await message.reply(f"`{ParsedText}`") + await edrep(message, text=f"`{ParsedText}`") os.remove(downloaded_file_name) \ No newline at end of file diff --git a/nana/modules/updater.py b/nana/modules/updater.py index 6045ba12..d2b3621e 100644 --- a/nana/modules/updater.py +++ b/nana/modules/updater.py @@ -131,7 +131,7 @@ async def updater(client, message): file.write(changelog_str) file.close() await client.send_document(message.chat.id, "nana/cache/output.txt", reply_to_message_id=message.message_id, - caption="`Changelog file`") + caption="`Changelog file`") os.remove("nana/cache/output.txt") else: await edrep(message, text=changelog_str)