async def anime_view_more(bot: Amime, callback: CallbackQuery): message = callback.message user = callback.from_user lang = callback._lang anime_id = int(callback.matches[0].group(1)) user_id = int(callback.matches[0].group(2)) if user_id != user.id: return async with anilist.AsyncClient() as client: anime = await client.get(anime_id, "anime") buttons = [ (lang.description_button, f"anime description {anime_id} {user_id} 1"), (lang.characters_button, f"anime characters {anime_id} {user_id}"), (lang.studios_button, f"anime studios {anime_id} {user_id}"), ] if hasattr(anime, "trailer"): if hasattr(anime.trailer, "url"): buttons.append((lang.trailer_button, anime.trailer.url, "url")) buttons.append(("🐢 Anilist", anime.url, "url")) keyboard = array_chunk(buttons, 2) keyboard.append([(lang.back_button, f"anime {anime_id} {user_id}")]) await message.edit_text( lang.view_more_text, reply_markup=ikb(keyboard), )
async def sudoers_interface(cq): lang = cq._lang c = cq._client text = lang.setting_sudoers_text + "\n" buttons = [] added = [] for user_id in sudoers: try: user_obj = await c.get_users(user_id) except: import traceback traceback.print_exc() user_obj = None id = user_obj.id if user_obj else user_id if id in added: continue added.append(id) mention = user_id if user_obj: mention = f'@{user_obj.username}' if user_obj.username else user_obj.first_name text += f"\n👤 {mention}" if id not in ['me', user.me.id, cq.from_user.id]: buttons.append((f"🗑 {mention}", f'remove_sudoer {user_id}')) lines = array_chunk(buttons, 2) if bot.me.username: lines.append([ (lang.add_sudoer, f"https://t.me/{bot.me.username}?start=add_sudoer", 'url') ]) lines.append([(lang.back, 'settings')]) keyboard = ikb(lines) return text, keyboard
async def request_episodes(bot: Amime, callback: CallbackQuery): message = callback.message user = callback.from_user lang = callback._lang anime_id = int(callback.matches[0].group(1)) language = callback.matches[0].group(2) buttons = [] for code, obj in lang.strings.items(): text, data = ((f"✅ {obj['LANGUAGE_NAME']}", "noop") if code == language else ( obj["LANGUAGE_NAME"], f"request episodes {anime_id} {code}", )) buttons.append((text, data)) keyboard = array_chunk(buttons, 2) keyboard.append([ (lang.confirm_button, f"request episodes confirm {anime_id} {language}"), (lang.back_button, f"anime {anime_id} {user.id}"), ]) await message.edit_text( lang.request_content_text, reply_markup=ikb(keyboard), )
async def manga_view_more(bot: Amime, callback: CallbackQuery): message = callback.message user = callback.from_user lang = callback._lang manga_id = int(callback.matches[0].group(1)) user_id = int(callback.matches[0].group(2)) if user_id != user.id: return async with anilist.AsyncClient() as client: manga = await client.get(manga_id, "manga") buttons = [ (lang.description_button, f"manga description {manga_id} {user_id} 1"), (lang.characters_button, f"manga characters {manga_id} {user_id}"), (lang.studios_button, f"manga studios {manga_id} {user_id}"), ] buttons.append(("🐢 Anilist", manga.url, "url")) keyboard = array_chunk(buttons, 2) keyboard.append([(lang.back_button, f"manga {manga_id} {user_id}")]) await message.edit_text( lang.view_more_text, reply_markup=ikb(keyboard), )
async def on_setting_language(c, cq): lang = cq._lang buttons = [] for code, obj in lang.strings.items(): text, data = ((f"✅ {obj['NAME']}", "noop") if obj["LANGUAGE_CODE"] == lang.code else (obj["NAME"], f"set_language {obj['LANGUAGE_CODE']}")) buttons.append((text, data)) lines = array_chunk(buttons, 2) lines.append([(lang.back, "settings")]) keyboard = ikb(lines) await cq.edit(lang.choose_language, keyboard)
async def anime_season(bot: Amime, callback: CallbackQuery): message = callback.message lang = callback._lang anime_id = int(callback.matches[0].group(1)) season = int(callback.matches[0].group(2)) subtitled = bool(int(callback.matches[0].group(3))) language = callback.matches[0].group(4) page = int(callback.matches[0].group(5)) episodes = await Episodes.filter(anime=anime_id, language=language, subtitled=subtitled) episodes = sorted(episodes, key=lambda episode: episode.number) seasons = [0] for episode in episodes: if episode.season not in seasons: seasons.append(episode.season) seasons.sort() if season not in seasons: seasons.append(season) keyboard = [ [( lang.add_button, f"manage anime {anime_id} {seasons[-1] + 1} {int(subtitled)} {language} 1", )], ] buttons = [] for _season in seasons: text = ("✅" if _season == season else "") + f" {_season}" data = ( "noop" if _season == season else f"manage anime season {anime_id} {_season} {int(subtitled)} {language} 1" ) buttons.append((text, data)) keyboard += array_chunk(buttons, 2) keyboard.append([( lang.back_button, f"manage anime {anime_id} {season} {int(subtitled)} {language} {page}", )]) await message.edit_text( lang.season_text, reply_markup=ikb(keyboard), )
async def on_setting_env(c, cq): if cq.message: cq.message.chat.cancel_listener() lang = cq._lang buttons = [] async for row in Config.all(): btn = (f'👁🗨 {row.key}', f'view_env {row.key}') if cq.message and cq.message.from_user.id == bot.me.id: btn = (f'📝 {row.key}', f'edit_env {row.key}') buttons.append(btn) lines = array_chunk(buttons, 2) lines.append([(lang.back, 'settings')]) keyboard = ikb(lines) await cq.edit(lang.settings_env_text, keyboard)
async def on_set_language(c, cq): lang = cq._lang match = cq.matches[0] lang = lang.get_language(match["code"]) await Config.get(key="LANGUAGE").update(value=lang.code) os.environ["LANGUAGE"] = lang.code buttons = [] for code, obj in lang.strings.items(): text, data = ((f"✅ {obj['NAME']}", "noop") if obj["LANGUAGE_CODE"] == lang.code else (obj["NAME"], f"set_language {obj['LANGUAGE_CODE']}")) buttons.append((text, data)) lines = array_chunk(buttons, 2) lines.append([(lang.back, "settings")]) keyboard = ikb(lines) await cq.edit(lang.choose_language, keyboard, {"text": lang.language_chosen})
async def episodes_season(bot: Amime, callback: CallbackQuery): message = callback.message chat = message.chat user = callback.from_user lang = callback._lang anime_id = int(callback.matches[0].group(1)) season = int(callback.matches[0].group(2)) page = int(callback.matches[0].group(3)) user_db = await Users.get(id=user.id) language = user_db.language_anime episodes = await Episodes.filter(anime=anime_id, language=language) episodes = sorted(episodes, key=lambda episode: episode.number) seasons = [] for episode in episodes: if episode.season not in seasons: seasons.append(episode.season) seasons.sort() buttons = [] for _season in seasons: text = ("✅" if _season == season else "") + f" {_season}" data = ("noop" if _season == season else f"episodes season {anime_id} {_season} 1") buttons.append((text, data)) keyboard = array_chunk(buttons, 2) keyboard.append([(lang.back_button, f"episodes {anime_id} {season} {page}") ]) await message.edit_text( lang.season_text, reply_markup=ikb(keyboard), )
async def user_collaborator(bot: Amime, callback: CallbackQuery): message = callback.message lang = callback._lang user = await bot.get_users(callback.matches[0].group(1)) buttons = [] for code, obj in lang.strings.items(): in_language = await Collaborators.get_or_none(user=user.id, language=code) text = ("✅ " if in_language is not None else "") + obj["LANGUAGE_NAME"] data = f"user collaborator edit {user.id} {code}" buttons.append((text, data)) keyboard = array_chunk(buttons, 2) text = f"<b>{user.mention()}</b>" text += f"\n{lang.language_text}" await message.edit_text( text, reply_markup=ikb(keyboard), )
async def anime_manage(bot: Amime, callback: CallbackQuery): message = callback.message chat = message.chat user = callback.from_user lang = callback._lang anime_id = int(callback.matches[0].group(1)) season = int(callback.matches[0].group(2)) subtitled = bool(int(callback.matches[0].group(3))) language = callback.matches[0].group(4) page = int(callback.matches[0].group(5)) if str(user.id) in VIDEOS.keys() and str(anime_id) in VIDEOS[str( user.id)].keys(): chat.cancel_listener() del VIDEOS[str(user.id)][str(anime_id)] buttons = [ ( f"{lang.language_button}: {lang.strings[language]['LANGUAGE_NAME']}", f"manage anime language {anime_id} {season} {int(subtitled)} {language} {page}", ), ( f"{lang.season_button}: {season}", f"manage anime season {anime_id} {season} {int(subtitled)} {language} {page}", ), ( f"{lang.subtitled_button}: {lang.yes if subtitled else lang.no}", f"manage anime {anime_id} {season} {int(not subtitled)} {language} {page}", ), ( lang.add_button, f"manage episode {anime_id} {season} -1 {int(subtitled)} {language} {page}", ), ] episodes = await Episodes.filter(anime=anime_id, season=season, language=language, subtitled=subtitled) episodes = sorted(episodes, key=lambda episode: episode.number) if len(episodes) >= 2: buttons.append(( lang.del_season_button, f"manage episode delete {anime_id} {season} -1 {int(subtitled)} {language} {page}", )) else: if page > 0: page -= 1 matches = re.search( r"(\d+) (\d+) (\d+) (\w+) (\d+)", f"{anime_id} {season} {int(subtitled)} {language} {page}", ) callback.matches = [matches] await anime_manage(bot, callback) return buttons.append(( lang.add_in_batch_button, f"manage episode batch {anime_id} {season} {int(subtitled)} {language} {page}", )) notifications = await Notifications.filter( item=anime_id, type="anime", language=language, ) if len(notifications) > 0: buttons.append(( lang.notify_users_button, f"notify episodes {anime_id} {season} {int(subtitled)} {language} {page}", )) keyboard = array_chunk(buttons, 2) layout = Pagination( episodes, item_data=lambda i, pg: f"manage episode {i.anime} {i.season} {i.number} {int(subtitled)} {language} {pg}", item_title=lambda i, pg: f"📝 {i.number}", page_data=lambda pg: f"manage anime {anime_id} {season} {int(subtitled)} {language} {pg}", ) lines = layout.create(page, lines=5, columns=3) if len(lines) > 0: keyboard += lines keyboard.append([(lang.back_button, f"anime {anime_id}")]) if bool(message.photo): await message.edit_text( lang.manage_anime_text, reply_markup=ikb(keyboard), ) else: await callback.edit_message_media( InputMediaPhoto( f"https://img.anili.st/media/{anime_id}", caption=lang.manage_anime_text, ), reply_markup=ikb(keyboard), )
async def anime_episode(bot: Amime, callback: CallbackQuery): message = callback.message chat = message.chat user = callback.from_user lang = callback._lang anime_id = int(callback.matches[0].group(1)) season = int(callback.matches[0].group(2)) number = int(callback.matches[0].group(3)) subtitled = bool(int(callback.matches[0].group(4))) language = callback.matches[0].group(5) page = int(callback.matches[0].group(6)) if str(user.id) not in EPISODES.keys(): EPISODES[str(user.id)] = {} if str(anime_id) not in EPISODES[str(user.id)].keys(): EPISODES[str(user.id)][str(anime_id)] = {} chat.cancel_listener() episode = EPISODES[str(user.id)][str(anime_id)] episode_db = await Episodes.get_or_none( anime=anime_id, season=season, number=number, language=language, subtitled=subtitled, ) if episode_db is not None: if not ("id" in episode.keys() and episode["id"] == episode_db.id): episode["id"] = episode_db.id episode["video"] = episode_db.file_id episode["name"] = episode_db.name episode["notes"] = episode_db.notes episode["duration"] = episode_db.duration episode["unified_until"] = episode_db.unified_until EPISODES[str(user.id)][str(anime_id)] = episode elif number == -1: EPISODES[str(user.id)][str(anime_id)] = {} episode = EPISODES[str(user.id)][str(anime_id)] episodes = await Episodes.filter( anime=anime_id, season=season, language=language, subtitled=subtitled, ) episodes = sorted(episodes, key=lambda episode: episode.number) if len(episodes) > 0: number = episodes[-1].number + 1 else: number = 1 episode["subtitled"] = subtitled async with anilist.AsyncClient() as client: anime = await client.get(anime_id, "anime") if anime is None: return logger.debug( "%s is editing/adding episode %s of the anime %s (%s)", user.first_name, number, anime_id, language, ) text = lang.manage_episode_text text += f"\n<b>{anime.title.romaji}</b> (<code>{anime.title.native}</code>)\n" buttons = [] if "name" in episode.keys() and len(episode["name"]) > 0: text += f"\n<b>{lang.name}</b>: <code>{episode['name']}</code>" buttons.append(( f"✏️ {lang.name}", f"manage episode edit name {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) else: buttons.append(( f"➕ {lang.name}", f"manage episode edit name {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) if season > 0: text += f"\n<b>{lang.season}</b>: <code>{season}</code>" if number != -1: episode_number = str(number) if "unified_until" in episode.keys() and int( episode["unified_until"]) > 0: episode_number += f"-{episode['unified_until']}" text += f"\n<b>{lang.episode}</b>: <code>{episode_number}</code>" buttons.append(( f"✏️ {lang.episode}", f"manage episode edit number {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) else: buttons.append(( f"➕ {lang.episode}", f"manage episode edit number {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) if "video" in episode.keys(): buttons.append(( f"✏️ {lang.video}", f"manage episode edit video {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) else: buttons.append(( f"➕ {lang.video}", f"manage episode edit video {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) if "duration" in episode.keys(): text += f"\n<b>{lang.duration}</b>: <code>{episode['duration']}m</code>" buttons.append(( f"✏️ {lang.duration}", f"manage episode edit duration {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) else: buttons.append(( f"➕ {lang.duration}", f"manage episode edit duration {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) text += f"\n<b>{lang.language}</b>: <code>{lang.strings[language]['LANGUAGE_NAME']}</code>" if "notes" in episode.keys() and len(episode["notes"]) > 0: text += f"\n<b>{lang.notes}</b>: <i>{episode['notes']}</i>" buttons.append(( f"✏️ {lang.notes}", f"manage episode edit notes {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) else: buttons.append(( f"➕ {lang.notes}", f"manage episode edit notes {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) keyboard = array_chunk(buttons, 2) buttons = [] if number != -1 and "video" in episode.keys(): episode["number"] = number buttons.append(( lang.confirm_button, f"manage episode save {anime_id} {season} {int(subtitled)} {language} {page}", )) if "id" in episode.keys(): buttons.append(( lang.del_button, f"manage episode delete {anime_id} {season} {number} {int(subtitled)} {language} {page}", )) buttons.append(( lang.back_button, f"manage anime {anime_id} {season} {int(subtitled)} {language} {page}", )) keyboard += array_chunk(buttons, 2) if "video" in episode.keys(): file_id = False if isinstance(episode["video"], str) and len(episode["video"]) > 0: file_id = episode["video"] elif isinstance(episode["video"], Video): file_id = episode["video"].file_id if file_id is not False: try: await callback.edit_message_media( InputMediaVideo( file_id, caption=text, ), reply_markup=ikb(keyboard), ) return except BaseException: pass await callback.edit_message_media( InputMediaPhoto( f"https://img.anili.st/media/{anime_id}", caption=text, ), reply_markup=ikb(keyboard), )
async def anime_view(bot: Amime, union: Union[CallbackQuery, Message]): is_callback = isinstance(union, CallbackQuery) message = union.message if is_callback else union chat = message.chat user = union.from_user lang = union._lang is_private = await filters.private(bot, message) is_collaborator = await filters.collaborator( bot, union) or await filters.sudo(bot, union) query = union.matches[0].group(1) if is_callback: user_id = union.matches[0].group(2) if user_id is not None: user_id = int(user_id) if user_id != user.id: return to_delete = union.matches[0].group(3) if bool(to_delete) and not is_private: await message.delete() if not bool(query): return async with anilist.AsyncClient() as client: if not query.isdecimal(): results = await client.search(query, "anime", 10) if results is None: await asyncio.sleep(0.5) results = await client.search(query, "anime", 10) if results is None: return if len(results) == 1: anime_id = results[0].id else: keyboard = [] for result in results: keyboard.append([(result.title.romaji, f"anime {result.id} {user.id} 1")]) await message.reply_text( lang.search_results_text(query=query, ), reply_markup=ikb(keyboard), ) return else: anime_id = int(query) anime = await client.get(anime_id, "anime") if anime is None: return user_db = await Users.get(id=user.id) language = user_db.language_anime episodes = await Episodes.filter(anime=anime.id) episodes = sorted(episodes, key=lambda episode: episode.number) episodes = [ *filter(lambda episode: len(episode.file_id) > 0, episodes) ] text = f"<b>{anime.title.romaji}</b>" if hasattr(anime.title, "native"): text += f" (<code>{anime.title.native}</code>)" text += f"\n\n<b>ID</b>: <code>{anime.id}</code>" if hasattr(anime, "score"): if hasattr(anime.score, "average"): text += f"\n<b>{lang.score}</b>: <code>{anime.score.average}</code>" text += f"\n<b>{lang.status}</b>: <code>{anime.status}</code>" if hasattr(anime, "genres"): text += f"\n<b>{lang.genres}</b>: <code>{', '.join(anime.genres)}</code>" if hasattr(anime, "studios"): text += f"\n<b>{lang.studios}</b>: <code>{', '.join(anime.studios)}</code>" text += f"\n<b>{lang.format}</b>: <code>{anime.format}</code>" if hasattr(anime, "duration"): text += f"\n<b>{lang.duration}</b>: <code>{anime.duration}m</code>" if not anime.format.lower() == "movie" and hasattr(anime, "episodes"): text += f"\n<b>{lang.episode}s</b>: <code>{anime.episodes}</code>" if not anime.status.lower() == "not_yet_released": text += f"\n<b>{lang.start_date}</b>: <code>{anime.start_date.day if hasattr(anime.start_date, 'day') else 0}/{anime.start_date.month if hasattr(anime.start_date, 'month') else 0}/{anime.start_date.year if hasattr(anime.start_date, 'year') else 0}</code>" if not anime.status.lower() in ["not_yet_released", "releasing"]: text += f"\n<b>{lang.end_date}</b>: <code>{anime.end_date.day if hasattr(anime.end_date, 'day') else 0}/{anime.end_date.month if hasattr(anime.end_date, 'month') else 0}/{anime.end_date.year if hasattr(anime.end_date, 'year') else 0}</code>" buttons = [ (lang.view_more_button, f"anime more {anime.id} {user.id}"), ] if is_private: buttons.append(await get_favorite_button(lang, user, "anime", anime.id)) if len(episodes) > 0: if is_private: if anime.format.lower() == "movie": buttons.append( (lang.watch_button, f"episode {anime.id} 0 1")) else: buttons.append(( lang.watch_button, f"episodes {anime.id} {episodes[0].season} 1", )) else: buttons.append(( lang.watch_button, f"https://t.me/{bot.me.username}/?start=anime_{anime.id}", "url", )) buttons.append(await get_notify_button(lang, user if is_private else chat, "anime", anime.id)) if is_private and is_collaborator: buttons.append(( lang.manage_button, f"manage anime {anime.id} 0 1 {language} 1", )) if is_private and not anime.status.lower() == "not_yet_released": button = ( lang.request_content_button, f"request episodes {anime.id} {language}", ) if anime.status.lower() == "releasing": if hasattr(anime, "next_airing"): next_episode = anime.next_airing.episode if len(episodes) < (next_episode - 1): buttons.append(button) else: buttons.append(button) elif hasattr(anime, "episodes"): if len(episodes) < anime.episodes: buttons.append(button) keyboard = array_chunk(buttons, 2) photo = f"https://img.anili.st/media/{anime.id}" if bool(message.video) and is_callback: await union.edit_message_media( InputMediaPhoto( photo, caption=text, ), reply_markup=ikb(keyboard), ) elif bool(message.photo) and not bool(message.via_bot): await message.edit_text( text, reply_markup=ikb(keyboard), ) else: await message.reply_photo( photo, caption=text, reply_markup=ikb(keyboard), )
async def anime_episodes(bot: Amime, callback: CallbackQuery): message = callback.message user = callback.from_user lang = callback._lang anime_id = int(callback.matches[0].group(1)) season = int(callback.matches[0].group(2)) page = int(callback.matches[0].group(3)) user_db = await Users.get(id=user.id) language = user_db.language_anime subtitled = user_db.subtitled_anime buttons = [ ( f"{lang.language_button}: {lang.strings[language]['LANGUAGE_NAME']}", f"episodes language {anime_id} {season} {language} {page}", ), ] if season > 0: buttons.append(( f"{lang.season_button}: {season}", f"episodes season {anime_id} {season} {page}", )) buttons.append(( f"{lang.subtitled_button}: {lang.yes if subtitled else lang.no}", f"episodes subtitled {anime_id} {season} {page}", )) keyboard = array_chunk(buttons, 2) episodes = await Episodes.filter(anime=anime_id, season=season, language=language, subtitled=subtitled) episodes = sorted(episodes, key=lambda episode: episode.number) episodes = [*filter(lambda episode: len(episode.file_id) > 0, episodes)] for index, episode in enumerate( sorted(episodes, key=lambda episode: episode.number, reverse=True)): if await Watched.get_or_none(user=user.id, episode=episode.id) is not None: episode = episodes[-index] if index == 0: break if math.ceil(episode.number / (5 * 3)) != page: keyboard.append([( f"{lang.next_episode_button}: {lang.episode[0]}{episode.number}", f"episode {anime_id} {episode.season} {episode.number}", )]) break episodes_list = [] for episode in episodes: viewed = bool(await Viewed.get_or_none(user=user.id, item=episode.id)) watched = bool(await Watched.get_or_none(user=user.id, episode=episode.id)) episodes_list.append((episode, viewed, watched)) layout = Pagination( episodes_list, item_data=lambda i, pg: f"episode {i[0].anime} {i[0].season} {i[0].number}", item_title=lambda i, pg: ("✅" if i[2] else "👁️" if i[1] else "🙈") + f" {i[0].number}" + (f"-{i[0].unified_until}" if i[0].unified_until > 0 else ""), page_data=lambda pg: f"episodes {anime_id} {season} {pg}", ) lines = layout.create(page, lines=5, columns=3) if len(lines) > 0: keyboard += lines keyboard.append([(lang.back_button, f"anime {anime_id}")]) await callback.edit_message_media( InputMediaPhoto( f"https://img.anili.st/media/{anime_id}", caption=lang.watch_list_anime_text, ), reply_markup=ikb(keyboard), )
async def report_episode(bot: Amime, callback: CallbackQuery): message = callback.message user = callback.from_user lang = callback._lang anime_id = int(callback.matches[0].group(1)) season = int(callback.matches[0].group(2)) number = int(callback.matches[0].group(3)) report_type = int(callback.matches[0].group(4)) if str(user.id) not in REPORTING.keys(): REPORTING[str(user.id)] = {} if str(anime_id) not in REPORTING[str(user.id)].keys(): REPORTING[str(user.id)][str(anime_id)] = {} reporting = REPORTING[str(user.id)][str(anime_id)] buttons = [] for index, r_type in enumerate(REPORT_TYPES): text = ("✅ " if index == report_type else "") + lang.strings[lang.code][r_type] data = f"report episode {anime_id} {season} {number} {index}" buttons.append((text, data)) text = lang.report_text + "\n" if report_type != -1: text += f"\n<b>{lang.type}</b>: {lang.strings[lang.code][REPORT_TYPES[report_type]]}" if "notes" in reporting.keys(): text += f"\n\n<b>{lang.notes}</b>: <i>{reporting['notes']}</i>" buttons.append(( f"🗑️ {lang.notes}", f"report episode edit notes {anime_id} {season} {number} {report_type}", )) else: buttons.append(( f"➕ {lang.notes}", f"report episode edit notes {anime_id} {season} {number} {report_type}", )) keyboard = array_chunk(buttons, 2) buttons = [] if (report_type == 3 and "notes" in reporting.keys()) or (report_type > -1 and report_type < 3): buttons.append(( lang.confirm_button, f"report episode confirm {anime_id} {season} {number} {report_type}", )) buttons.append((lang.back_button, f"episode {anime_id} {season} {number}")) keyboard += array_chunk(buttons, 2) await message.edit_text( text, reply_markup=ikb(keyboard), )
async def manga_view(bot: Amime, union: Union[CallbackQuery, Message]): is_callback = isinstance(union, CallbackQuery) message = union.message if is_callback else union chat = message.chat user = union.from_user lang = union._lang is_private = await filters.private(bot, message) query = union.matches[0].group(1) if is_callback: user_id = union.matches[0].group(2) if user_id is not None: user_id = int(user_id) if user_id != user.id: return is_search = union.matches[0].group(3) if bool(is_search) and not is_private: await message.delete() if not bool(query): return async with anilist.AsyncClient() as client: if not query.isdecimal(): results = await client.search(query, "manga", 10) if results is None: await asyncio.sleep(0.5) results = await client.search(query, "manga", 10) if results is None: return if len(results) == 1: manga_id = results[0].id else: keyboard = [] for result in results: keyboard.append([(result.title.romaji, f"manga {result.id} {user.id} 1")]) await message.reply_text( lang.search_results_text(query=query, ), reply_markup=ikb(keyboard), ) return else: manga_id = int(query) manga = await client.get(manga_id, "manga") if manga is None: return photo: str = "" if hasattr(manga, "banner"): photo = manga.banner elif hasattr(manga, "cover"): if hasattr(manga.cover, "extra_large"): photo = manga.cover.extra_large elif hasattr(manga.cover, "large"): photo = manga.cover.large elif hasattr(manga.cover, "medium"): photo = manga.cover.medium text = f"<b>{manga.title.romaji}</b>" if hasattr(manga.title, "native"): text += f" (<code>{manga.title.native}</code>)" text += f"\n\n<b>ID</b>: <code>{manga.id}</code>" if hasattr(manga, "score"): if hasattr(manga.score, "average"): text += f"\n<b>{lang.score}</b>: <code>{manga.score.average}</code>" text += f"\n<b>{lang.status}</b>: <code>{manga.status}</code>" if hasattr(manga, "genres"): text += f"\n<b>{lang.genres}</b>: <code>{', '.join(manga.genres)}</code>" if hasattr(manga, "volumes"): text += f"\n<b>{lang.volume}s</b>: <code>{manga.volumes}</code>" if hasattr(manga, "chapters"): text += f"\n<b>{lang.chapter}s</b>: <code>{manga.chapters}</code>" if not manga.status.lower() == "not_yet_released": text += f"\n<b>{lang.start_date}</b>: <code>{manga.start_date.day if hasattr(manga.start_date, 'day') else 0}/{manga.start_date.month if hasattr(manga.start_date, 'month') else 0}/{manga.start_date.year if hasattr(manga.start_date, 'year') else 0}</code>" if not manga.status.lower() in ["not_yet_released", "releasing"]: text += f"\n<b>{lang.end_date}</b>: <code>{manga.end_date.day if hasattr(manga.end_date, 'day') else 0}/{manga.end_date.month if hasattr(manga.end_date, 'month') else 0}/{manga.end_date.year if hasattr(manga.end_date, 'year') else 0}</code>" buttons = [ (lang.view_more_button, f"manga more {manga.id} {user.id}"), ] if is_private: buttons.append(await get_favorite_button(lang, user, "manga", manga.id)) buttons.append(await get_notify_button(lang, user if is_private else chat, "manga", manga.id)) keyboard = array_chunk(buttons, 2) if bool(message.photo) and not bool(message.via_bot): await message.edit_text( text, reply_markup=ikb(keyboard), ) else: await message.reply_photo( photo, caption=text, reply_markup=ikb(keyboard), )