当前位置: 首页>>代码示例>>Python>>正文


Python ext.CommandHandler方法代码示例

本文整理汇总了Python中telegram.ext.CommandHandler方法的典型用法代码示例。如果您正苦于以下问题:Python ext.CommandHandler方法的具体用法?Python ext.CommandHandler怎么用?Python ext.CommandHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在telegram.ext的用法示例。


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

示例1: __init__

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def __init__(self, mount_point, fallback):
        if not os.path.exists(mount_point + 'codeforces.json'):
            shutil.copy('codeforces.json', mount_point + 'codeforces.json')
        with open(mount_point + 'codeforces.json', 'r') as codeforces:
            self.qcf = json.load(codeforces)
        self.conv_handler10 = ConversationHandler(
            entry_points=[CommandHandler('randomcf', self.randomcf)],
            allow_reentry=True,
            states={
                QSELCF: [CallbackQueryHandler(self.qselcf, pattern=r'\w*cf1\b')]
            },
            fallbacks=[fallback]
        )

    # START OF CONVERSATION HANDLER FOR GETTING RANDOM QUESTION FROM CODEFORCES
    # FUNCTION TO GET INPUT ABOUT THE TYPE OF QUESTION FROM USER 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:18,代码来源:codeforces.py

示例2: __init__

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def __init__(self, mount_point, fallback):
        self.mount_point = mount_point
        self.conv_handler = ConversationHandler(
            entry_points=[CommandHandler('subscribe', self.subscribe)],
            allow_reentry=True,
            states={
                SUBSEL: [CallbackQueryHandler(self.subsel, pattern=r'\w*sub3\b', pass_user_data=True)],
                SUB: [CallbackQueryHandler(self.sub, pattern=r'\w*sub2\b', pass_user_data=True)]
            },
            fallbacks=[fallback]
        )
        self.conv_handler1 = ConversationHandler(
            entry_points=[CommandHandler('unsubscribe', self.unsubsel)],
            allow_reentry=True,
            states={
                UNSUB: [CallbackQueryHandler(self.unsub, pattern=r'\w*unsub4\b')]
            },
            fallbacks=[fallback]
        ) 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:21,代码来源:ques_of_the_day.py

示例3: __init__

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def __init__(self, mount_point, fallback):
        self.mount_point = mount_point
        self.utility = Utility(mount_point)
        self.conv_handler = ConversationHandler(
            entry_points=[CommandHandler('ranklist', self.ranklist)],
            allow_reentry=True,
            states={

                SELECTION: [CallbackQueryHandler(self.selection, pattern=r'\w*sel1\b')],
                HOLO: [CallbackQueryHandler(self.holo, pattern=r'\w*list6\b')],
                SOLO: [CallbackQueryHandler(self.solo, pattern=r'\w*list7\b')],
                POLO: [MessageHandler(Filters.text, self.polo, pass_user_data=True)],
                XOLO: [CallbackQueryHandler(self.xolo, pass_user_data=True, pattern=r'\w*list8\b')]
            },

            fallbacks=[fallback]
        ) 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:19,代码来源:ranklist.py

示例4: __init__

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def __init__(self, mount_point, admin_list, fallback):
        self.admin_list = admin_list
        self.mount_point = mount_point
        self.utility = Utility(mount_point)
        self.conv_handler1 = ConversationHandler(
            entry_points=[CommandHandler('broadcast', self.broadcast)],
            allow_reentry=True,
            states={
                BDC: [MessageHandler(Filters.text, self.broadcast_message)]
            },
            fallbacks=[fallback]
        )
        self.conv_handler2 = ConversationHandler(
            entry_points=[CommandHandler('senddb', self.getDb)],
            allow_reentry=True,
            states={
                DB: [MessageHandler(Filters.document, self.db)]
            },
            fallbacks=[fallback]
        )

    # START OF ADMIN CONVERSATION HANDLER TO BROADCAST MESSAGE 
开发者ID:Gotham13121997,项目名称:superCodingBot,代码行数:24,代码来源:admin.py

示例5: __init__

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
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,代码行数:27,代码来源:Server.py

示例6: register_handlers

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def register_handlers(dispatcher, mode):
    assert mode in ('production', 'test')

    dispatcher.add_handler(MessageHandler(
        Filters.status_update.new_chat_members, handle_new_chat_members
    ))
    dispatcher.add_handler(CommandHandler(
        ['start', 'help'], handle_start_help
    ))
    dispatcher.add_handler(CommandHandler('stat', handle_stat))
    dispatcher.add_handler(CommandHandler(
        ['daysandbox_set', 'daysandbox_get'], handle_set_get
    ))
    dispatcher.add_handler(RegexHandler(
        r'^/setlogformat ', handle_setlogformat, channel_post_updates=True
    ))
    dispatcher.add_handler(CommandHandler('setlog', handle_setlog))
    dispatcher.add_handler(CommandHandler('unsetlog', handle_unsetlog))
    dispatcher.add_handler(MessageHandler(
        Filters.all, partial(handle_any_message, mode), edited_updates=True
    )) 
开发者ID:lorien,项目名称:daysandbox_bot,代码行数:23,代码来源:daysandbox_bot.py

示例7: main

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def main():
    # Create the Updater and pass it your bot's token.
    updater = Updater(TOKEN, workers=10, use_context=True)

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

    dp.add_handler(CommandHandler("start", help))
    dp.add_handler(CommandHandler("help", help))
    dp.add_handler(CommandHandler("welcome", set_welcome))
    dp.add_handler(CommandHandler("goodbye", set_goodbye))
    dp.add_handler(CommandHandler("disable_goodbye", disable_goodbye))
    dp.add_handler(CommandHandler("lock", lock))
    dp.add_handler(CommandHandler("unlock", unlock))
    dp.add_handler(CommandHandler("quiet", quiet))
    dp.add_handler(CommandHandler("unquiet", unquiet))

    dp.add_handler(MessageHandler(Filters.status_update, empty_message))

    dp.add_error_handler(error)

    updater.start_polling(timeout=30, clean=True)
    updater.idle() 
开发者ID:jh0ker,项目名称:welcomebot,代码行数:25,代码来源:bot.py

示例8: main

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def main():
    updater = Updater(token=Token)
    job_queue = updater.job_queue
    dp = updater.dispatcher

    dp.add_handler(CommandHandler("add", cmd_rss_add, pass_args=True))
    dp.add_handler(CommandHandler("help", cmd_help))
    dp.add_handler(CommandHandler("test", cmd_test, pass_args=True))
    dp.add_handler(CommandHandler("list", cmd_rss_list))
    dp.add_handler(CommandHandler("remove", cmd_rss_remove, pass_args=True))

    # try to create a database if missing
    try:
        init_sqlite()
    except sqlite3.OperationalError:
        pass
    rss_load()

    job_queue.run_repeating(rss_monitor, delay)

    updater.start_polling()
    updater.idle()
    conn.close() 
开发者ID:BoKKeR,项目名称:RSS-to-Telegram-Bot,代码行数:25,代码来源:telegramrss.py

示例9: __init__

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def __init__(self, TOKEN, NAME):
        super(BotComm, self).__init__()
        self.TOKEN = TOKEN
        self.NAME=NAME
        self.bot = telegram.Bot(self.TOKEN)
        try:
            self.bot.setWebhook("https://{}.herokuapp.com/{}".format(self.NAME, self.TOKEN))
        except:
            raise RuntimeError("Failed to set the webhook")

        self.update_queue = Queue()
        self.dp = Dispatcher(self.bot, self.update_queue)

        self.dp.add_handler(CommandHandler("start", self._start))
        self.dp.add_handler(MessageHandler(Filters.text, self._echo))
        self.dp.add_error_handler(self._error) 
开发者ID:Eldinnie,项目名称:ptb-heroku-skeleton,代码行数:18,代码来源:herokubotcp.py

示例10: __init__

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def __init__(self):
        self.history = {}

        self.updater = Updater(TOKEN)
        self.name = str(self).split(' ')[-1][:-1]

        self.dp = self.updater.dispatcher

        self.dp.add_handler(CommandHandler("start", start))
        self.dp.add_handler(CommandHandler("help", help))

        self.dp.add_handler(MessageHandler([Filters.text], echo))

        self.dp.add_error_handler(error)
        self.stories = StoriesHandler()
        logger.info('I\'m alive!') 
开发者ID:deepmipt,项目名称:ConvAI-baseline,代码行数:18,代码来源:bot.py

示例11: main

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def main():
    logging_location = log_location + log_name
    logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level= logging.INFO, filename= logging_location)
    logging.info("Bot server started")
    print(token_val)
    try:
        if token_val == "":
            raise ValueError("Not found")
        command_filter = CommandFilter()
        updater = Updater(token= token_val, use_context= True)
        dispatcher = updater.dispatcher
        start_handler = CommandHandler('start',start)
        command_message_handler = MessageHandler(command_filter, exec_command)
        dispatcher.add_handler(start_handler)
        dispatcher.add_handler(command_message_handler)
        logging.info("Successfully initialized handlers")
    except ValueError as ex:
        print('It seems your token is empty!')
        return
    except Exception as e:
        logging.warning("Error intializing handlers")
        logging.error(str(e))
    updater.start_polling() 
开发者ID:krishnanunnir,项目名称:server_monitor_bot,代码行数:25,代码来源:start.py

示例12: main

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def main():
    logger.info("Loading handlers for telegram bot")
    
    # Default dispatcher (this is related to the first bot in settings.TELEGRAM_BOT_TOKENS)
    dp = DjangoTelegramBot.dispatcher
    # To get Dispatcher related to a specific bot
    # dp = DjangoTelegramBot.getDispatcher('BOT_n_token')     #get by bot token
    # dp = DjangoTelegramBot.getDispatcher('BOT_n_username')  #get by bot username
    
    # 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)

    # log all errors
    dp.addErrorHandler(error) 
开发者ID:JungDev,项目名称:django-telegrambot,代码行数:23,代码来源:telegrambot.py

示例13: main

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def main():
    logger.info("Loading handlers for telegram bot")

    # Default dispatcher (this is related to the first bot in settings.TELEGRAM_BOT_TOKENS)
    dp = DjangoTelegramBot.dispatcher
    # To get Dispatcher related to a specific bot
    # dp = DjangoTelegramBot.getDispatcher('BOT_n_token')     #get by bot token
    # dp = DjangoTelegramBot.getDispatcher('BOT_n_username')  #get by bot username

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

    dp.add_handler(CommandHandler("startgroup", startgroup))
    dp.add_handler(CommandHandler("me", me))
    dp.add_handler(CommandHandler("chat", chat))
    dp.add_handler(MessageHandler(Filters.forwarded , forwarded))

    # 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) 
开发者ID:JungDev,项目名称:django-telegrambot,代码行数:25,代码来源:telegrambot.py

示例14: __init__

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def __init__(self, token):
        self._bot = telegram.Bot(token)
        self._updater = Updater(bot=self._bot)

        dp = self._updater.dispatcher
        dp.add_handler(CommandHandler("start", self._start_cmd))
        dp.add_handler(CommandHandler("reset", self._reset_cmd))
        dp.add_handler(CommandHandler("stop", self._reset_cmd))
        dp.add_handler(CommandHandler("help", self._help_cmd))
        dp.add_handler(CommandHandler("text", self._text_cmd))
        dp.add_handler(CommandHandler("evaluation_start", self._evaluation_start_cmd))
        dp.add_handler(CommandHandler("evaluation_end", self._evaluation_end_cmd))

        dp.add_handler(MessageHandler(Filters.text, self._echo_cmd))

        dp.add_handler(CallbackQueryHandler(self._eval_keyboard))
        dp.add_error_handler(self._error)

        self._users_fsm = {}
        self._users = {}
        self._text_and_qas = load_text_and_qas('data/squad-25-qas.json')
        self._text_ind = 0
        self._evaluation = {}
        self._eval_suggestions = None 
开发者ID:sld,项目名称:convai-bot-1337,代码行数:26,代码来源:telegram_main.py

示例15: main

# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import CommandHandler [as 别名]
def main():
	updater = Updater(token=TOKEN, workers = 8)
	dispatcher = updater.dispatcher
	start_cmd = CommandHandler("start" , start)
	help_cmd = CommandHandler("help" , help)
	donate_cmd = CommandHandler("donate" , donate)
	dispatcher.add_handler(start_cmd)
	dispatcher.add_handler(help_cmd)
	dispatcher.add_handler(donate_cmd)
	if ADMIN_MODULE:
		extras.add_extra_commands(dispatcher)
	else:
		print("ADMIN_MODULE not found. (Won't effect the bot though.)")
		start_handler = MessageHandler((Filters.all) , start_bot)
		dispatcher.add_handler(start_handler)
	updater.start_polling() 
开发者ID:atulkadian,项目名称:gdrivemirror_bot,代码行数:18,代码来源:bot.py


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