• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python ext.Updater类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中telegram.ext.Updater的典型用法代码示例。如果您正苦于以下问题:Python Updater类的具体用法?Python Updater怎么用?Python Updater使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Updater类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
    print("memers default value:")
    print(memers)

    load_memers()

    print("loaded memers:")
    print(memers)

    updater = Updater(apikey)
    dp = updater.dispatcher
    jqueue = updater.job_queue

    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))
    dp.add_handler(CommandHandler("test", test))
    dp.add_handler(CommandHandler("ping", ping))
    dp.add_handler(CommandHandler("time", time))
    dp.add_handler(CommandHandler("boat", boat))
    dp.add_handler(CommandHandler("ebin", ebin))
    dp.add_handler(CommandHandler("stats", stats))
    dp.add_handler(CommandHandler("chatinfo", chatinfo))
    dp.add_handler(CommandHandler("drop", drop))
    dp.add_handler(CommandHandler("shop", shop))
    updater.dispatcher.add_handler(CallbackQueryHandler(shopbutton))

    dp.add_handler(MessageHandler([Filters.text], parse))

    dp.add_error_handler(error)

    updater.start_polling(timeout=5)

    # Run the bot until the user presses Ctrl-C or the process receives SIGINT, SIGTERM or SIGABRT
    updater.idle()
开发者ID:Epowerj,项目名称:CancerBot,代码行数:34,代码来源:bot.py


示例2: main

def main():
    # Create the EventHandler and pass it your bot's token.
    updater = Updater(secrets.bot_token)

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Telegram
    dp.addHandler(CommandHandler("start", start))
    dp.addHandler(CommandHandler("help", help))
    dp.addHandler(CommandHandler("random", random))
    dp.addHandler(CommandHandler("suicide", suicide))
    dp.addHandler(CommandHandler("developer", developer))

    # inline query
    dp.addHandler(InlineQueryHandler(search))


    # on noncommand i.e message - echo the message on Telegram
    dp.addHandler(MessageHandler([Filters.text], echo))

    # log all errors
    dp.addErrorHandler(error)

    # Start the Bot
    updater.start_polling()

    # Run the bot until the you presses 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()
开发者ID:celisflen-bers,项目名称:TelegramSGirlsBot,代码行数:31,代码来源:app.py


示例3: main

def main():
    # Create the EventHandler and pass it your bot's token.
    updater = Updater(token="BOT_TOKEN")

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # simple start function
    dp.add_handler(CommandHandler("start", start_callback))

    # Add command handler to start the payment invoice
    dp.add_handler(CommandHandler("shipping", start_with_shipping_callback))
    dp.add_handler(CommandHandler("noshipping", start_without_shipping_callback))

    # Optional handler if your product requires shipping
    dp.add_handler(ShippingQueryHandler(shipping_callback))

    # Pre-checkout handler to final check
    dp.add_handler(PreCheckoutQueryHandler(precheckout_callback))

    # Success! Notify your user!
    dp.add_handler(MessageHandler(Filters.successful_payment, successful_payment_callback))

    # 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()
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:33,代码来源:paymentbot.py


示例4: main

def main():

    # Read secret token from file
    with open('easy_python_bot_token', 'r') as easy_python_bot_token_file:
        easy_python_bot_token = easy_python_bot_token_file.readline()

    # Create the EventHandler and pass it your bot's token.
    updater = Updater(easy_python_bot_token)

    # 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("help", help))

    # on noncommand i.e message - echo the message on Telegram
    dp.add_handler(MessageHandler([Filters.text], text_message_handler))

    # log all errors
    dp.add_error_handler(error)

    # Start the Bot
    updater.start_polling()

    # Run the bot until the you presses 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()
开发者ID:karfly,项目名称:easy_python_bot,代码行数:29,代码来源:easy_python_bot.py


示例5: main

def main():
    init()

    updater = Updater(TOKEN)

    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))
    dp.add_handler(CommandHandler("ping", ping))
    dp.add_handler(CommandHandler("nyang", nyang))
    dp.add_handler(CommandHandler("rand", rand))

    dp.add_handler(CommandHandler("sysstat", lambda x, y: stat(x, y, 'sys')))
    dp.add_handler(CommandHandler("cpustat", lambda x, y: stat(x, y, 'cpu')))
    dp.add_handler(CommandHandler("memstat", lambda x, y: stat(x, y, 'mem')))
    dp.add_handler(CommandHandler("webstat", lambda x, y: stat(x, y, 'web')))
    dp.add_handler(CommandHandler("diskstat", lambda x, y: stat(x, y, 'disk')))
    dp.add_handler(CommandHandler("procstat", lambda x, y: stat(x, y, 'proc')))
    dp.add_handler(CommandHandler("bakstat", lambda x, y: stat(x, y, 'bak')))
    dp.add_handler(MessageHandler([Filters.command], unknown))
    dp.add_handler(MessageHandler([Filters.text], echo))

    dp.add_error_handler(error)

    updater.start_polling()
    updater.idle()
开发者ID:a1sams1a,项目名称:telebot-sso,代码行数:26,代码来源:core.py


示例6: main

def main():
    """Start the bot."""
    # Create the EventHandler and pass it your bot's token.
    updater = Updater("TOKEN")

    # 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("help", help))

    # on noncommand i.e message - echo the message on Telegram
    dp.add_handler(MessageHandler(Filters.text, echo))

    # 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()
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:25,代码来源:echobot2.py


示例7: main

def main():
    # Create the EventHandler and passs it your bot's token.
    updater = Updater(os.environ['LOGBOT'])

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Telegram
    dp.addHandler(CommandHandler("start", start))
    dp.addHandler(CommandHandler("help", help))

    # on noncommand i.e message - echo the message on Telegram
    dp.addHandler(MessageHandler([Filters.text],reply))

    # log all errors
    dp.addErrorHandler(error)

    # Start the Bot
    updater.start_polling()

    print 'Bot Started!!\n'

    # Run the bot until the you presses 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()
开发者ID:ChatAI,项目名称:dumbots,代码行数:26,代码来源:LogBot.py


示例8: main

def main():
    mybot = Updater("368736105:AAGLQaNZ_tWNOEg5kCQ4A0M8LEdgGFitKD8", request_kwargs=PROXY)
    dp = mybot.dispatcher
    dp.add_handler(CommandHandler("start", greet_user))
    dp.add_handler(MessageHandler(Filters.text, talk_to_me))
    mybot.start_polling()
    mybot.idle()
开发者ID:Guznin,项目名称:WhiteFox,代码行数:7,代码来源:bot.py


示例9: __init__

class Connector:
    """Connector class for the Telegram bot API."""

    def __init__(self, bot):
        """Will load the api token from $TELEGRAM_API_TOKEN."""
        self.bot = bot

        token = os.getenv('TELEGRAM_API_TOKEN')
        if token is None:
            print('TELEGRAM_API_TOKEN not set. Exiting...')
            sys.exit(1)

        self.updater = Updater(token=token)
        self.dispatcher = self.updater.dispatcher
        self.dispatcher.add_handler(MessageHandler(None, self.parse_incoming))

    def listen(self):
        """Listen for messages."""
        self.updater.start_polling()
        self.updater.idle()

    def parse_incoming(self, bot, incoming):
        """Transform incoming telegram info into format Chattie can parse."""
        resp = self.bot.parse_message(incoming.message.text)

        for r in resp:
            bot.sendMessage(chat_id=incoming.message.chat_id,
                            text=r)
开发者ID:chasinglogic,项目名称:Thorin,代码行数:28,代码来源:telegram.py


示例10: main

def main():
    # Create the EventHandler and pass it your bot's token.
    updater = Updater(telegram_token)

    # 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("help", helper))

    # on noncommand i.e message
    dp.add_handler(MessageHandler([Filters.text], chat))

    # log all errors
    dp.add_error_handler(error)

    # Start the Bot
    updater.start_webhook(listen='95.163.114.6', # 95.163.114.6
                      port=80,
                      url_path='MaraphonBot',
                      key='/home/user/cert/private.key',
                      cert='/home/user/cert/cert.pem',
                      webhook_url='https://95.163.114.6:80/MaraphonBot')
    updater.idle()
开发者ID:EremeykinS,项目名称:MaraphonBot,代码行数:25,代码来源:bot.py


示例11: main

def main():
    # Create the EventHandler and pass it your bot's token.
    updater = Updater()

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Telegram
    dp.add_handler(CommandHandler("start", c.startGame))
    dp.add_handler(CommandHandler("stop", c.stop))
    dp.add_handler(CommandHandler("creategame", c.createGame))
    dp.add_handler(CommandHandler("join", c.joinGame))
    dp.add_handler(CommandHandler("game", c.getGame))
    dp.add_handler(CommandHandler("hello", c.hello))

    # on noncommand i.e message - echo the message on Telegram
    dp.add_handler(MessageHandler([Filters.text], c.checkPlays))

    # Start the Bot
    updater.start_polling()

    # Run the bot until the you presses 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()
开发者ID:bruno-edo,项目名称:coupBot,代码行数:25,代码来源:CoupBot.py


示例12: main

def main():
    # Create the EventHandler and pass it your bot's token.
    token = 'TOKEN'
    updater = Updater(token, workers=10)

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # This is how we add handlers for Telegram messages
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))
    # Message handlers only receive updates that don't contain commands
    dp.add_handler(MessageHandler([Filters.text], message))
    # Regex handlers will receive all updates on which their regex matches,
    # but we have to add it in a separate group, since in one group,
    # only one handler will be executed
    dp.add_handler(RegexHandler('.*', any_message), group=1)

    # String handlers work pretty much the same. Note that we have to tell
    # the handler to pass the args or update_queue parameter
    dp.add_handler(StringCommandHandler('reply', cli_reply, pass_args=True))
    dp.add_handler(StringRegexHandler('[^/].*', cli_noncommand,
                                      pass_update_queue=True))

    # All TelegramErrors are caught for you and delivered to the error
    # handler(s). Other types of Errors are not caught.
    dp.add_error_handler(error)

    # Start the Bot and store the update Queue, so we can insert updates
    update_queue = updater.start_polling(timeout=10)

    '''
    # Alternatively, run with webhook:

    update_queue = updater.start_webhook('0.0.0.0',
                                         443,
                                         url_path=token,
                                         cert='cert.pem',
                                         key='key.key',
                                         webhook_url='https://example.com/%s'
                                             % token)

    # Or, if SSL is handled by a reverse proxy, the webhook URL is already set
    # and the reverse proxy is configured to deliver directly to port 6000:

    update_queue = updater.start_webhook('0.0.0.0', 6000)
    '''

    # Start CLI-Loop
    while True:
        text = input()

        # Gracefully stop the event handler
        if text == 'stop':
            updater.stop()
            break

        # else, put the text into the update queue to be handled by our handlers
        elif len(text) > 0:
            update_queue.put(text)
开发者ID:Conectel,项目名称:python-telegram-bot,代码行数:60,代码来源:clibot.py


示例13: main

def main(): 
    # Create the Updater and pass it your bot's token.
    updater = Updater("181752127:AAFX10TTymBCbB4_0RKG5LxtoBJKgyYUulM")

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Telegram
    dp.addTelegramCommandHandler("start", start)
    dp.addTelegramCommandHandler("help", help)
    dp.addTelegramCommandHandler("pay", pay)
    dp.addTelegramCommandHandler("fee", fee)
    dp.addTelegramCommandHandler("history", history)
    dp.addTelegramCommandHandler("confirm", confirm)

    # on noncommand i.e message - echo the message on Telegram
    dp.addTelegramInlineHandler(inlinequery)

    # log all errors
    dp.addErrorHandler(error)

    # Start the Bot
    updater.start_polling()

    # Block until the user presses 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()
开发者ID:melnychukJS,项目名称:TWHack2016Finals,代码行数:28,代码来源:bot.py


示例14: main

def main():
    logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)

    random.seed(time.time())

    config = load_configuration()

#    db.init(config['db_url'])

    updater = Updater(token=config['auth_token'])

    dispatcher = updater.dispatcher
    dispatcher.add_handler(funyreplies.comrade_handler)
    dispatcher.add_handler(funyreplies.its_not_handler)

    dispatcher.add_handler(misc.leave_chat_handler)
    #dispatcher.add_handler(misc.status_update_handler)
    #dispatcher.add_handler(misc.roulette_handler)
    dispatcher.add_handler(misc.help_handler)
    dispatcher.add_handler(misc.until_ny_handler)

    dispatcher.add_handler(timers.set_timer_handler)
    dispatcher.add_handler(timers.clear_all_timers_handler)

    dispatcher.add_handler(misc.log_handler, -1)

    updater.start_polling(clean=True)
开发者ID:mortido,项目名称:EpicBot,代码行数:27,代码来源:run.py


示例15: main

def main():
    config = configparser.ConfigParser()
    config.read('config.ini')
    # Create the EventHandler and pass it your bot's token.
    updater = Updater(config['init']['token'])

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Telegram
    dp.addTelegramCommandHandler("start", start)
    dp.addTelegramCommandHandler("add", add)
    dp.addTelegramCommandHandler("help", help)

    # on noncommand i.e message - echo the message on Telegram
    dp.addTelegramMessageHandler(message)

    # log all errors
    dp.addErrorHandler(error)

    # Start the Bot
    updater.start_polling()

    # Run the bot until the you presses 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()
开发者ID:Virusmater,项目名称:StreetArtView-python-telegram-bot,代码行数:27,代码来源:StreetArtViewBot.py


示例16: main

def main():
    # Create the EventHandler and pass it your bot's token.
    updater = Updater("181560082:AAHbTzTUj6_onF8p_iClYODVjFyreSvAEZg")

    # 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("help", help))
    dp.add_handler(CommandHandler("temperatura", obtentemp))
    dp.add_handler(CommandHandler("luz", obtenluz))

    # on noncommand i.e message - echo the message on Telegram
    dp.add_handler(MessageHandler([Filters.text], echo))

    # log all errors
    dp.add_error_handler(error)

    # Start the Bot
    updater.start_polling()

    # Run the bot until the you presses 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()
开发者ID:rsolisuaz,项目名称:TheIoTLearningInitiative,代码行数:26,代码来源:echobot2.py


示例17: __init__

    def __init__(self):
        self.config_instance = self.config_init()
        updater = Updater(self.config_instance.TELEGRAM_BOT_KEY)
        dp = updater.dispatcher

        logging.basicConfig(
            format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
            filename=self.config_instance.LOG_FILE
        )

        dp.add_handler(MessageHandler(
            [Filters.text], self.command_check_resps))
        dp.add_handler(CommandHandler("start", self.command_start))
        dp.add_handler(CommandHandler(
            "roll", self.command_roll, pass_args=True))
        dp.add_handler(CommandHandler("leaderboard", self.command_leaderboard))
        dp.add_error_handler(self.error)

        jq = updater.job_queue
        jq.put(self.update_all_timers, 1)

        self.logger.info("Started... ")

        updater.start_polling()
        updater.idle()
开发者ID:toymak3r,项目名称:CineMonster,代码行数:25,代码来源:Server.py


示例18: main

def main():

	# Read config file
	with open("/home/pi/telegram-secretsanta/token.txt") as f:
		bot_token = f.readline().strip()

	# Create the Updater and pass it your bot's token.
	updater = Updater(bot_token)

	# Get the dispatcher to register handlers
	dp = updater.dispatcher

	# on noncommand i.e message - echo the message on Telegram
	dp.add_handler(InlineQueryHandler(new_secret_santa))
	dp.add_handler(CallbackQueryHandler(button_click_callback))

	# on different commands - answer in Telegram
	dp.add_handler(CommandHandler("start", help))
	dp.add_handler(CommandHandler("help", help))

	# log all errors
	dp.add_error_handler(error)

	# Start the Bot
	updater.start_polling()

	# Block until the user presses 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()
开发者ID:MakeTrumpGreatAgain,项目名称:telegram-secretsanta,代码行数:30,代码来源:AmigoInvisibleBot.py


示例19: main

def main():
    print 'start'
    # Create the EventHandler and pass it your bot's token.
    updater = Updater(BOT_TOKEN)
    print 'updated'

    # Get the dispatcher to register handlers
    dp = updater.dispatcher
    print 'get dispatcher'

    # on different commands - answer in Telegram
    dp.addHandler(CommandHandler("start", start))
    dp.addHandler(CommandHandler("help", help))
    dp.addHandler(CommandHandler("vn-search", vn_search))
    print 'add handlers'

    # on noncommand i.e message - echo the message on Telegram
    dp.addHandler(MessageHandler([filters.TEXT], echo))
    print 'message handler'

    # log all errors
    dp.addErrorHandler(error)
    print 'add error'

    # Start the Bot
    updater.start_polling()
    print 'polling'

    # Run the bot until the you presses 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()
开发者ID:jgpacker,项目名称:vnbot,代码行数:32,代码来源:vnbot.py


示例20: main

def main():	
	global update_queue
	global screen
	
	#@VideoBoxBot
	updater = Updater("145378027:AAFB2YiOzHnCQ55xD1VDjGTprwKhGI2VLlk")	
	
	# Get the dispatcher to register handlers
	dp = updater.dispatcher

	# Definisce gli handler di gestione dei comandi
	dp.add_handler(CommandHandler("start",   cmd_start))
	dp.add_handler(CommandHandler("cancel",  cmd_cancel))	
		
	dp.add_handler(MessageHandler([Filters.text], text_handler))
	dp.add_handler(MessageHandler([Filters.video], video_handler))
	dp.add_handler(MessageHandler([Filters.document], document_handler))

	# log all errors
	dp.add_error_handler(error)

	# Start the Bot
	update_queue = updater.start_polling()

	try:  
		# Run the bot until the you presses 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()

	except KeyboardInterrupt:  
		print "Exit"	
开发者ID:tanzilli,项目名称:digitalsign,代码行数:32,代码来源:led.py



注:本文中的telegram.ext.Updater类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python request.post函数代码示例发布时间:2022-05-27
下一篇:
Python ext.JobQueue类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap