本文整理汇总了Python中telegram.ext.MessageHandler方法的典型用法代码示例。如果您正苦于以下问题:Python ext.MessageHandler方法的具体用法?Python ext.MessageHandler怎么用?Python ext.MessageHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.ext
的用法示例。
在下文中一共展示了ext.MessageHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [as 别名]
def __init__(self, api_key, fallback):
self.compiler = HackerRankAPI(api_key=api_key)
self.conv_handler = ConversationHandler(
entry_points=[CommandHandler('compiler', self.compilers)],
allow_reentry=True,
states={
LANG: [CallbackQueryHandler(self.lang, pass_user_data=True, pattern=r'\w*comp1\b')],
CODE: [CallbackQueryHandler(self.code, pass_user_data=True, pattern=r'\w*so1\b')],
DECODE: [MessageHandler(Filters.text, self.decode, pass_user_data=True)],
TESTCASES: [MessageHandler(Filters.text, self.testcases, pass_user_data=True)],
OTHER: [MessageHandler(Filters.text, self.other, pass_user_data=True)],
FILE: [MessageHandler(Filters.document, self.filer, pass_user_data=True)],
FILETEST: [MessageHandler(Filters.document, self.filetest, pass_user_data=True)]
},
fallbacks=[fallback]
)
示例2: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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]
)
示例3: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [as 别名]
def __init__(self, mount_point, fallback):
self.mount_point = mount_point
self.conv_handler = ConversationHandler(
entry_points=[CommandHandler('register', self.register)],
allow_reentry=True,
states={
NAME: [MessageHandler(Filters.text, self.name, pass_user_data=True)],
JUDGE: [CallbackQueryHandler(self.judge, pass_user_data=True, pattern=r'\w*reg1\b')],
HANDLE: [MessageHandler(Filters.text, self.handle, pass_user_data=True)]
},
fallbacks=[fallback]
)
示例4: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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
示例5: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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()
示例6: register_handlers
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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
))
示例7: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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()
示例8: __register_handlers
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [as 别名]
def __register_handlers(self):
functional.apply_fn(
self.message_handlers.items(),
lambda h: self.__add_handler(MessageHandler(
h[0],
lambda b, u, **kwargs: self.__pre__hook(h[1], b, u, **kwargs)))
)
functional.apply_fn(
self.command_handlers.items(),
lambda h: self.__add_handler(ChannelCommandHandler(
h[0],
lambda b, u, **kwargs: self.__pre__hook(h[1][0], b, u, **kwargs),
filters=h[1][1]))
)
functional.apply_fn(
self.callback_handlers.items(),
lambda h: self.__add_handler(CallbackQueryHandler(h[1]))
)
# Decorators for adding callbacks
示例9: run
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [as 别名]
def run(self):
# noinspection PyPackageRequirements
from telegram.ext import MessageHandler, Filters
super().run()
telegram = self._plugin.get_telegram()
dispatcher = telegram.dispatcher
dispatcher.add_handler(MessageHandler(Filters.group, self._group_hook()))
dispatcher.add_handler(MessageHandler(Filters.text, self._msg_hook(TextMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.photo, self._msg_hook(PhotoMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.video, self._msg_hook(VideoMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.contact, self._msg_hook(ContactMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.location, self._msg_hook(LocationMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.document, self._msg_hook(DocumentMessageEvent)))
dispatcher.add_handler(MessageHandler(Filters.command, self._command_hook()))
self.logger.info('Initialized Telegram backend')
telegram.start_polling()
# vim:sw=4:ts=4:et:
示例10: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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)
示例11: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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!')
示例12: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
if (proxy_url is None):
updater = Updater(api_key, workers=64)
else:
updater = Updater(token=api_key, workers=64, request_kwargs={'proxy_url': proxy_url, 'urllib3_proxy_kwargs': {'username': proxy_user, 'password': proxy_pass}})
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on noncommand i.e message - return not found
dp.add_handler(MessageHandler(Filters.command, maintenance))
dp.add_handler(MessageHandler(Filters.text, maintenance))
# log all errors
dp.add_error_handler(error)
# Start the Bot
#updater.start_polling()
updater.start_webhook(listen='127.0.0.1', port=int(listen_port), url_path=api_key)
updater.bot.setWebhook('https://{0}/{1}'.format(domain, api_key))
# 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()
示例13: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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()
示例14: add_towel_mode
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [as 别名]
def add_towel_mode(upd: Updater, handlers_group: int):
logger.info("registering towel-mode handlers")
dp = upd.dispatcher
# catch all new users and drop the towel
dp.add_handler(MessageHandler(Filters.status_update.new_chat_members, catch_new_user),
handlers_group)
# check for reply or remove messages
dp.add_handler(MessageHandler(
Filters.group & ~Filters.status_update, catch_reply),
handlers_group
)
# "i am a bot button"
dp.add_handler(CallbackQueryHandler(i_am_a_bot_btn), handlers_group)
# ban quarantine users, if time is gone
upd.job_queue.run_repeating(ban_user, interval=60, first=60, context={
"chat_id": get_config()["GROUP_CHAT_ID"]
})
示例15: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import MessageHandler [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)