本文整理汇总了Python中telegram.ext.Updater类的典型用法代码示例。如果您正苦于以下问题:Python Updater类的具体用法?Python Updater怎么用?Python Updater使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Updater类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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)
示例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()
示例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()
示例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)
示例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()
示例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)
示例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()