我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用telegram.ext.Filters.all()。
def main(): test_handler = MessageHandler(Filters.all, test, edited_updates=True, message_updates=False) start_handler = CommandHandler("start", start) help_handler = CommandHandler("help", get_help) migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) # dispatcher.add_handler(test_handler) dispatcher.add_handler(start_handler) dispatcher.add_handler(help_handler) dispatcher.add_handler(migrate_handler) # dispatcher.add_error_handler(error_callback) if HEROKU: port = int(os.environ.get('PORT', 5000)) updater.start_webhook(listen="0.0.0.0", port=port, url_path=TOKEN) updater.bot.set_webhook("https://tgpolbot.herokuapp.com/" + TOKEN) else: updater.start_polling() updater.idle()
def main(): updater = Updater(token=config.TELEGRAM_TOKEN) print(updater.bot.get_me()) logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) jarvis = Jarvis(updater) interval = datetime.timedelta(seconds=EVENT_TRIGGER_INTERVAL_IN_SECONDS) updater.job_queue.run_repeating(jarvis.events, interval, first=0) handlers = [ CommandHandler('start', jarvis.hello), MessageHandler(Filters.all, jarvis.receive) ] dispatcher = updater.dispatcher for handler in handlers: dispatcher.add_handler(handler) updater.start_polling() updater.idle()
def main(): updater = Updater(AUTHTOKEN, workers=10) dp = updater.dispatcher dp.add_handler(CommandHandler('start', start)) dp.add_handler(CommandHandler('help', help)) dp.add_handler(CommandHandler('info', info)) dp.add_handler(CommandHandler('support', support, pass_chat_data=True)) dp.add_handler(CommandHandler('getStats', getMessageStats)) dp.add_handler(CommandHandler('chooselang', chooseLanguage, pass_chat_data=True, pass_args=True)) dp.add_handler(MessageHandler(Filters.voice, receiveMessage, pass_chat_data=True)) dp.add_handler(MessageHandler(Filters.all, countme)) dp.add_handler(CallbackQueryHandler(callbackHandler, pass_chat_data=True)) dp.add_error_handler(error) updater.start_polling() logger.debug("Setiup complete, Idling.") updater.idle()
def main(): updater = Updater(config['token']) updater.dispatcher.add_handler(CommandHandler('start', start)) updater.dispatcher.add_handler(CommandHandler('restart', restart_qq)) updater.dispatcher.add_handler(CommandHandler('setme', set_remark)) updater.dispatcher.add_handler(CommandHandler('resetme', reset_remark)) updater.dispatcher.add_handler(MessageHandler(Filters.all, handle_message)) ts = TelegramSender() ts.start() logger.info('Sync started') start_new_thread(app.run, ('127.0.0.1', config['tg_port'])) updater.start_polling(clean=True)
def add_handlers(self, add_handler): add_handler(MessageHandler(Filters.all, self._run))
def add_handlers(self, add_handler): add_handler(CommandHandler('ktozloy', self._kto_zloy)) add_handler(MessageHandler(Filters.all, self._update_last_users))
def error_callback(bot, update, error): try: raise error except Unauthorized: print("no nono1") print(error) # remove update.message.chat_id from conversation list except BadRequest: print("no nono2") print("BadRequest caught") print(error) # handle malformed requests - read more below! except TimedOut: print("no nono3") # handle slow connection problems except NetworkError: print("no nono4") # handle other connection problems except ChatMigrated as err: print("no nono5") print(err) # the chat_id of a group has changed, use e.new_chat_id instead except TelegramError: print(error) # handle all other telegram related errors
def main(): # logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) updater = Updater(config.token) updater.dispatcher.add_handler(MessageHandler(FilterPr(), pr)) updater.dispatcher.add_handler(MessageHandler(FilterPrOther(), pr_other)) # updater.dispatcher.add_handler(MessageHandler(Filters.all, debug)) updater.start_polling() updater.idle()
def forwardToAll(bot, list_of_chats, from_chat_id, message_id): logger.debug("List of chats to forward a message to: %s" % list_of_chats) if not list_of_chats: #If there are no chats to foward to. return for chat in list_of_chats: try: bot.forward_message(chat_id=chat, from_chat_id=from_chat_id, message_id=message_id) except TelegramError as te: logger.debug("Unable to send message to %s from %s. May want to remove it, or resolve the thread." %(chat, from_chat_id)) logger.debug("Error from forward to all: %s" % te)
def alertAdmins(bot, username): admins = [] logger.debug('alerting admins:') for group in MDB.groups.find(): logger.debug("Admins in group %s: %s" %(group['title'], group['admins'])) admins += group['admins'] admins = set(admins) for admin in admins: try: bot.send_message(chat_id=admin, text="%s is sending feedback, send /cancel to select and respond to them." % username) except TelegramError as te: logger.debug("Not all admins are interacting with the bot.") logger.debug("Error in alert Admins: %s" % te)
def main(): global mClient, mDatabase mClient = MongoClient(mongoURI) mDatabase = mClient[mDatabase] try: serverInfo = mClient.server_info() logger.info("Mongo Connection Achieved") logger.debug("Connected to Mongo Server: %s" % serverInfo) except: logger.error("Could not connect to Mongo Server at %s" % mongoURI) raise updater = Updater(authToken) dp = updater.dispatcher dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help)) charCreationHandler = ConversationHandler( entry_points=[CommandHandler('meAbout',meAbout, pass_user_data=True)], states={ TEXTRESP:[MessageHandler(Filters.text, meTextResp, pass_user_data=True), MessageHandler(Filters.all, redoState, pass_user_data=True)], PHOTORESP:[MessageHandler(Filters.photo or Filters.sticker, mePhotoResp, pass_user_data=True), MessageHandler(Filters.all, redoState, pass_user_data=True)], CHOOSE:[RegexHandler("^(Name, Discription, Photo, Bio, Cancel)$", meChoose, pass_user_data=True)] }, fallbacks=[CommandHandler('cancel',meAboutCancel, pass_user_data=True)] ) structCreationHandler = ConversationHandler( entry_points=[CommandHandler('newStruct', editStructStart, pass_user_data=True)], states={STRUCTNAME:[MessageHandler(Filters.text, editStructSetName, pass_user_data=True), MessageHandler(Filters.all, redoState, pass_user_data=True)] STRUCTDESC:[MessageHandler(Filters.text, editStructSetDesc, pass_user_data=True), MessageHandler(Filters.all, redoState, pass_user_data=True)], STRUCTDOOR:[MessageHandler(Filters.text, editStructSetDoor, pass_user_data=True), MessageHandler(Filters.all, redoState, pass_user_data=True)]}, fallbacks=[CommandHandler("cancel", cancel)]) roomCreationHandler = ConversationHandler( entry_points=[ConversationHandler("editRoom", editRoomStart)], states={}, fallbacks=[CommandHandler("cancel", cancel)]) dp.add_handler(CommandHandler("roomAddObjDisc", roomAddObjDisc, allow_edited=True)) dp.add_handler(CommandHandler("roomRemObjDisc", roomRemObjDisc)) dp.add_handler(CommandHandler("roomAddTempDisc", roomAddTempDisc, allow_edited=True)) dp.add_handler(CommandHandler("roomRemTempDisc", roomRemTempDisc)) dp.add_handler(CommandHandler("doorLock",doorLock)) dp.add_handler(CommandHandler("doorUnlock", doorUnlock)) dp.add_handler(CommandHandler("doorKnock", doorKnock)) updater.start_polling() updater.idle() mClient.close()