def main(): """Start the bot.""" # Create the Updater and pass it your bot's token. # Make sure to set use_context=True to use the new context based callbacks # Post version 12 this will no longer be necessary db = DBHelper(CONFIG["db_name"]) db.setup() updater = Updater(CONFIG["bot_token"], use_context=True) # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("newdl", new_deadline)) dp.add_handler(CommandHandler("chkdl", check_deadline)) dp.add_handler( ConversationHandler( entry_points=[CommandHandler("remdl", start_remove_deadline)], states={ CHOOSING: [ MessageHandler(Filters.regex(r"^/\d+(@shimekiribot)?$"), remove_deadline_by_index) ] }, fallbacks=[])) # log all errors dp.add_error_handler(error) # Start the Bot updater.start_polling() # Run the bot until you press Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle()
autolabel(p3) plt.savefig('report.png') context.bot.send_photo(chat_id=update.effective_chat.id, photo=open('report.png', 'rb')) return True if __name__ == "__main__": if len(sys.argv) > 1: try: if sys.argv[1] == "--reset-pin": db.seeder_admin(sys.argv[2]) print("Successfully reset pin") elif sys.argv[1] == "--create-table": print("Successfully create & seed table") db.setup() elif sys.argv[1] == "--change-token": db.change_token(sys.argv[2]) print("Successfully change token") except IndexError: raise IndexError("index error out of bond") if db.get_token()[0] == "": print("Token API kosong, tidak dapat menangani bot") else: print("Connecting to telegram server ...") up = Updater(db.get_token()[0], use_context=True) print("Connected to telegram server") print("Making conversation ...") conv = ConversationHandler( entry_points=[CommandHandler('start_adm1n', admin_start)], allow_reentry=True,