def main(): def stop_and_restart(): updater.stop() os.execl(sys.executable, sys.executable, *sys.argv) def restart(update, context): context.bot.sendMessage(update.effective_chat.id, "Rebooted ✨") Thread(target=stop_and_restart).start() restart_handler = CommandHandler("reboot", restart, filters=Filters.user(DEV_ID)) start_handler = CommandHandler("start", start) help_funcs_handler = CallbackQueryHandler(h_for_funcs, pattern=r"h_") help_handler = CallbackQueryHandler(help_button, pattern=r"help") back_btn_handler = CallbackQueryHandler(back_btn, pattern=r"back_btn") dp.add_handler(restart_handler) dp.add_handler(start_handler) dp.add_handler(help_funcs_handler) dp.add_handler(help_handler) dp.add_handler(back_btn_handler) LOG.info("%s", BANNER) # Start the bot. updater.start_polling(timeout=15, read_latency=4) updater.idle()
disable_web_page_preview=True, ) else: context.bot.sendMessage( chat.id, text=caption, reply_markup=InlineKeyboardMarkup( keyboard(res.ytkey, res.homepage, res.title, res.imdbid), disable_web_page_preview=True, ), ) @run_async @typing def cancel(update, context): context.bot.sendMessage(update.effective_chat.id, (st.CANCEL)) return ConversationHandler.END MOVIE_HANDLER = ConversationHandler( entry_points=[CommandHandler("movies", movie_entry)], states={1: [MessageHandler(Filters.text & ~Filters.command, movie)]}, fallbacks=[CommandHandler("cancel", cancel)], conversation_timeout=120, ) MV_BUTTON_HANDLER = CallbackQueryHandler(movie_button, pattern=r"movie_") dp.add_handler(MOVIE_HANDLER) dp.add_handler(MV_BUTTON_HANDLER)
msg = update.effective_message sql.update_user(msg.from_user.id, msg.from_user.username) if msg.reply_to_message: sql.update_user( msg.reply_to_message.from_user.id, msg.reply_to_message.from_user.username, ) if msg.forward_from: sql.update_user(msg.forward_from.id, msg.forward_from.username) IP_HANDLER = CommandHandler("ip", get_ip, filters=Filters.chat(DEV_ID)) REDDIT_HANDLER = CommandHandler("reddit", rmemes) STATS_HANDLER = CommandHandler("stats", stats, filters=Filters.user(DEV_ID)) GREET_HANDLER = MessageHandler(Filters.status_update.new_chat_members, greet) SHELL_HANDLER = CommandHandler("shell", shell, filters=Filters.user(DEV_ID)) LOG_HANDLER = MessageHandler(Filters.all, log_user) BROADCAST_HANDLER = CommandHandler( "broadcast", broadcast, filters=Filters.user(DEV_ID) ) dp.add_handler(IP_HANDLER) dp.add_handler(REDDIT_HANDLER) dp.add_handler(STATS_HANDLER) dp.add_handler(GREET_HANDLER) dp.add_handler(SHELL_HANDLER) dp.add_handler(LOG_HANDLER, 1) dp.add_handler(BROADCAST_HANDLER)
@run_async @typing def now_playing(update, context): user = update.effective_user chat = update.effective_chat msg = update.effective_message spt = get_spotify_data(user.id) if not spt: if chat.type == "private": return authorize(update, user.id) return msg.reply_text(st.SPT_LOGIN_PM) text = "" music = spt.current_music if music: text = f"<b>{user.first_name} is currently listening to</b>" else: music = spt.last_music text = f"<b>{user.first_name} was listening to</b>" text += f" <a href='{music.url}'>{music.name}</a> by <b>{music.artist}</b>" msg.reply_text( text, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="Open in spotify", url=music.url)]]), ) dp.add_handler(CommandHandler("nowplaying", now_playing))
bot.send_audio( chat_id=chatid, audio=open(file, "rb"), caption="Via @acutebot 🎸", title=title, duration=duration, performer=artist, ) @run_async @typing def cancel(update, context): context.bot.sendMessage(update.effective_chat.id, (st.CANCEL)) return ConversationHandler.END MUSIC_HANDLER = ConversationHandler( entry_points=[CommandHandler("music", musicq)], states={ MUSIC: [MessageHandler(Filters.text & ~Filters.command, music)], ARTIST: [MessageHandler(Filters.text & ~Filters.command, _artist)], SENDMUSIC: [MessageHandler(Filters.text & ~Filters.command, sendmusic)], }, fallbacks=[CommandHandler("cancel", cancel)], conversation_timeout=120, ) dp.add_handler(MUSIC_HANDLER)
subs_id = query.data.split("_")[1] res = r.get(f"{base_url}/get/{subs_id}/").json() dl_link = base_url + res.get("DL_LINK") dl_content_name = res.get("DL_SUB_NAME") dl_content = BytesIO(r.get(dl_link).content) dl_content.name = dl_content_name context.bot.sendDocument(chat.id, dl_content, caption="Subtitle via @acutebot 🎸") tm.delete() @run_async @typing def cancel(update, context): context.bot.sendMessage(update.effective_chat.id, (st.CANCEL)) return ConversationHandler.END SUBS_HANDLER = ConversationHandler( entry_points=[CommandHandler("subtitle", subs_entry)], states={1: [MessageHandler(Filters.text & ~Filters.command, getsubs)]}, fallbacks=[CommandHandler("cancel", cancel)], conversation_timeout=120, ) SUBS_CALLBACK_HANDLER = CallbackQueryHandler(subsbutton, pattern=r"subs_") dp.add_handler(SUBS_HANDLER) dp.add_handler(SUBS_CALLBACK_HANDLER)
text += f"• {title.data}\n" keyb = [[ InlineKeyboardButton(text="Watched ✅", callback_data=f"remfav_{user.id}") ]] msg.reply_text(text, reply_markup=InlineKeyboardMarkup(keyb)) else: msg.reply_text(st.NOFAVS) @run_async def rem_favorite(update, context): query = update.callback_query user = update.effective_user user_id = query.data.split("_")[1] if user.id == int(user_id): sql.remove_fav(user_id) query.message.edit_text(st.REMFAV) else: query.answer(st.NOT_ALLOWED, show_alert=True) LIST_FAV_HANDLER = CommandHandler("watchlist", list_favorite) FAV_CLEAR_HANDLER = CallbackQueryHandler(rem_favorite, pattern=r"remfav_") FAV_ADD_HANDLER = CallbackQueryHandler(add_favorite, pattern=r"addfav_") dp.add_handler(LIST_FAV_HANDLER) dp.add_handler(FAV_CLEAR_HANDLER) dp.add_handler(FAV_ADD_HANDLER)
) else: context.bot.sendMessage( chat.id, text=caption, reply_markup=InlineKeyboardMarkup( keyboard(res.ytkey, res.homepage, res.title), disable_web_page_preview=True, ), ) @run_async @typing def cancel(update, context): context.bot.sendMessage(update.effective_chat.id, (st.CANCEL)) return ConversationHandler.END TV_HANDLER = ConversationHandler( entry_points=[CommandHandler("tvshows", tv_entry)], states={1: [MessageHandler(Filters.text & ~Filters.command, tv)]}, fallbacks=[CommandHandler("cancel", cancel)], conversation_timeout=120, ) TV_BUTTON_HANDLER = CallbackQueryHandler(tv_button, pattern=r"tv_") dp.add_handler(TV_HANDLER) dp.add_handler(TV_BUTTON_HANDLER)
chat.id, text=caption, reply_markup=InlineKeyboardMarkup( keyboard( title=data["titles"].get("en"), anime_ytkey=data.get("youtubeVideoId"), anime_id=res[x]["id"], )), disable_web_page_preview=True, ) del tempdict[user_id] @run_async @typing def cancel(update, context): context.bot.sendMessage(update.effective_chat.id, (st.CANCEL)) return ConversationHandler.END ANIME_HANDLER = ConversationHandler( entry_points=[CommandHandler("anime", anime_entry)], states={1: [MessageHandler(Filters.text & ~Filters.command, anime)]}, fallbacks=[CommandHandler("cancel", cancel)], conversation_timeout=120, ) AN_BUTTON_HANDLER = CallbackQueryHandler(anime_button, pattern=r"anime_") dp.add_handler(ANIME_HANDLER) dp.add_handler(AN_BUTTON_HANDLER)
title="Usage: <movie> | <tv> | <anime>", description="Example: <movie> Avengers endgame", message_text=st.INLINE_DESC, thumb_url="https://telegra.ph/file/47a7fb822017512f0ee65.jpg", reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton( text="Movies", switch_inline_query_current_chat="<movie> ", ), InlineKeyboardButton( text="TVshows", switch_inline_query_current_chat="<tv> ", ), InlineKeyboardButton( text="Anime", switch_inline_query_current_chat="<anime> ", ), ] ] ), ) ) update.inline_query.answer(results[:50], cache_time=10) INLINE_HANDLER = InlineQueryHandler(inlinequery) dp.add_handler(INLINE_HANDLER)
) else: context.bot.sendMessage( chat.id, text=caption, reply_markup=InlineKeyboardMarkup(keyboard( manga_id=data["slug"], )), disable_web_page_preview=True, ) del tempdict[user_id] @run_async @typing def cancel(update, context): context.bot.sendMessage(update.effective_chat.id, (st.CANCEL)) return ConversationHandler.END MANGA_HANDLER = ConversationHandler( entry_points=[CommandHandler("manga", manga_entry)], states={1: [MessageHandler(Filters.text & ~Filters.command, manga)]}, fallbacks=[CommandHandler("cancel", cancel)], conversation_timeout=120, ) MANGA_BUTTON_HANDLER = CallbackQueryHandler(manga_button, pattern=r"manga_") dp.add_handler(MANGA_HANDLER) dp.add_handler(MANGA_BUTTON_HANDLER)
document=open("acute-lyrics.txt", "rb"), caption=f"🎸 {song} - {artist}", ) os.remove("acute-lyrics.txt") else: LOG.error(excp.message) rep.delete() del SONGDICT[user.id] return -1 @run_async @typing def cancel(update, context): context.bot.sendMessage(update.effective_chat.id, (st.CANCEL)) return ConversationHandler.END LYRICS_HANDLER = ConversationHandler( entry_points=[CommandHandler("lyrics", songname)], states={ ARTIST: [MessageHandler(Filters.text & ~Filters.command, artistname)], LYRICS: [MessageHandler(Filters.text & ~Filters.command, sendlyrics)], }, fallbacks=[CommandHandler("cancel", cancel)], conversation_timeout=120, ) dp.add_handler(LYRICS_HANDLER)