本文整理汇总了Python中telegram.Updater.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Updater.stop方法的具体用法?Python Updater.stop怎么用?Python Updater.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.Updater
的用法示例。
在下文中一共展示了Updater.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
token = os.environ["TOKEN"]
updater = Updater(token, workers=10)
# Get the dispatcher to register handlers
dp = updater.dispatcher
dp.addTelegramCommandHandler("start", start)
dp.addTelegramCommandHandler("blue", blue)
dp.addStringCommandHandler("reply", cli_reply)
dp.addUnknownStringCommandHandler(unknown_cli_command)
dp.addStringRegexHandler("[^/].*", cli_noncommand)
dp.addErrorHandler(error)
# Start the Bot and store the update Queue, so we can insert updates
update_queue = updater.start_polling(poll_interval=0.1, timeout=20)
# Start CLI-Loop
while True:
try:
text = raw_input()
except NameError:
text = input()
# Gracefully stop the event handler
if text == "stop":
updater.stop()
break
# else, put the text into the update queue
elif len(text) > 0:
update_queue.put(text) # Put command into queue
示例2: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
updater = Updater(man.settings["authkey"])
dp = updater.dispatcher
dp.addTelegramCommandHandler("reactio", reactio)
dp.addTelegramCommandHandler("kuva", kuva)
#dp.addTelegramCommandHandler("kiusua", insult)
#dp.addTelegramCommandHandler("new_insult", new_insult)
dp.addTelegramMessageHandler(jutku)
dp.addErrorHandler(error)
update_queue = updater.start_polling(poll_interval=0.1, timeout=10)
while True:
try:
text = input()
except NameError:
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)
示例3: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
### Updater será vinculado ao token informado,
### no caso, o token do grupo Brail Linux se não
### for mais release candidate
if RELEASE_CANDIDATE:
TOKEN2USE = TOKEN['rc']
else:
TOKEN2USE = TOKEN['released']
updater = Updater(TOKEN2USE , workers=10)
# Get the dispatcher to register handlers (funcoes...)
dp = updater.dispatcher
### Adiciona comandos ao handler...
### Loop pela lista com todos comandos
for lc in ALL_COMMANDS:
add_handler(dp, lc, isADM=False)
### Adiciona comandos adm ao handler
### É preciso por o flag isADM como true...
for lca in ALL_COMMANDS_ADMS:
add_handler(dp, lca, isADM=True)
### aqui tratamos comandos não reconhecidos.
### Tipicamente comandos procedidos por "/" que é o caracter
### default para comandos telegram
dp.addUnknownTelegramCommandHandler(showUnknowncommand)
### Loga todas mensagens para o terminal
### Pode ser util para funcoes anti-flood
dp.addTelegramMessageHandler(message)
### Aqui logamos todos erros que possam vir a acontecer...
dp.addErrorHandler(errosHandler)
# Start the Bot and store the update Queue, so we can insert updates
update_queue = updater.start_polling(poll_interval=0.1, timeout=10)
### Aqui lemos o dicionarios de usuarios do disco
##- global USERS
##- USERS =
logging.info('Quantia de users no DB: {udb}.'.format(udb=len(USERS)))
for u in USERS:
logging.info('User {un}, id: {uid}'.format(un=USERS[u]['username'],uid=u))
# Start CLI-Loop and heartbeat
while True:
try:
text = raw_input()
except NameError:
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)
示例4: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
config = configparser.ConfigParser()
config.read('info.ini')
token = config.get("Connection","Token")
updater = Updater(token, workers=10)
dp = updater.dispatcher
dp.addUnknownTelegramCommandHandler(unknown_command)
dp.addTelegramMessageHandler(message)
dp.addTelegramRegexHandler('.*', any_message)
dp.addStringCommandHandler('reply', cli_reply)
dp.addUnknownStringCommandHandler(unknown_cli_command)
dp.addStringRegexHandler('[^/].*', cli_noncommand)
dp.addErrorHandler(error)
update_queue = updater.start_polling(poll_interval=0.1, timeout=10)
# Start CLI-Loop
while True:
try:
text = raw_input()
except NameError:
text = input()
if text == 'stop':
fileids.close()
updater.stop()
break
elif len(text) > 0:
update_queue.put(text)
示例5: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
#Get bot token.
Config = ConfigParser.ConfigParser()
Config.read("./jabberwocky.cfg")
#Create event handler
updater = Updater(Config.get("BotApi", "Token"))
dp = updater.dispatcher
#Add handlers
dp.addTelegramMessageHandler(parseMessage)
dp.addTelegramCommandHandler("apologize", apologize)
#Start up bot.
updater.start_polling()
while True:
if debug:
cmd = raw_input("Enter command...\n")
if cmd == 'list':
print 'Nouns:'
print nouns.values
print 'Verbs:'
print verbs.values
print 'Adverbs:'
print adverbs.values
print 'Numbers:'
print numbers.values
print 'Adjectives:'
print adjectives.values
print 'Garbage:'
print garbage.values
#Force generation of a random sentence.
elif cmd == 'forceprint':
m = markov.Markov(nouns, adjectives, verbs, adverbs, numbers, pronouns, prepositions, conjunctions, vowels, garbage)
print m.string
#Shutdown bot.
elif cmd == 'quit':
updater.stop()
sys.exit()
elif cmd == 'help':
print 'Commands are: list, forceprint, quit.'
else:
print 'Commmand not recognized.'
else:
time.sleep(1)
示例6: test_inUpdater
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def test_inUpdater(self):
u = Updater(bot="MockBot", job_queue_tick_interval=0.005)
u.job_queue.put(self.job1, 0.5)
sleep(0.75)
self.assertEqual(1, self.result)
u.stop()
sleep(2)
self.assertEqual(1, self.result)
示例7: test_inUpdater
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def test_inUpdater(self):
print('Testing job queue created by updater')
u = Updater(bot="MockBot", job_queue_tick_interval=0.005)
u.job_queue.put(self.job1, 0.1)
sleep(0.15)
self.assertEqual(1, self.result)
u.stop()
sleep(0.4)
self.assertEqual(1, self.result)
示例8: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
token = 'token'
updater = Updater(token, workers=2)
# Get the dispatcher to register handlers
dp = updater.dispatcher
dp.addTelegramCommandHandler("start", start)
dp.addTelegramCommandHandler("help", help)
dp.addUnknownTelegramCommandHandler(unknown_command)
dp.addTelegramMessageHandler(message)
dp.addTelegramRegexHandler('.*', any_message)
dp.addStringCommandHandler('reply', cli_reply)
dp.addUnknownStringCommandHandler(unknown_cli_command)
dp.addStringRegexHandler('[^/].*', cli_noncommand)
dp.addErrorHandler(error)
# Start the Bot and store the update Queue, so we can insert updates
update_queue = updater.start_polling(poll_interval=0.1, timeout=20)
'''
# Alternatively, run with webhook:
updater.bot.setWebhook(webhook_url='https://example.com/%s' % token,
certificate=open('cert.pem', 'rb'))
update_queue = updater.start_webhook('0.0.0.0',
443,
url_path=token,
cert='cert.pem',
key='key.key')
# 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:
try:
text = raw_input()
except NameError:
text = input()
# Gracefully stop the event handler
if text == 'stop':
updater.stop()
break
# else, put the text into the update queue
elif len(text) > 0:
update_queue.put(text) # Put command into queue
示例9: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
# Create the Updater and pass it your bot's token.
updater = Updater(TOKEN, workers=2)
# Get the dispatcher to register handlers
dp = updater.dispatcher
dp.addTelegramCommandHandler("start", help)
dp.addTelegramCommandHandler("help", help)
dp.addTelegramCommandHandler('welcome', set_welcome)
dp.addTelegramCommandHandler('goodbye', set_goodbye)
dp.addTelegramCommandHandler('disable_goodbye', disable_goodbye)
dp.addTelegramCommandHandler("lock", lock)
dp.addTelegramCommandHandler("unlock", unlock)
dp.addTelegramCommandHandler("quiet", quiet)
dp.addTelegramCommandHandler("unquiet", unquiet)
dp.addTelegramRegexHandler('^$', empty_message)
dp.addStringCommandHandler('broadcast', broadcast)
dp.addStringCommandHandler('level', set_log_level)
dp.addStringCommandHandler('count', chatcount)
dp.addErrorHandler(error)
# Start the Bot and store the update Queue, so we can insert updates
update_queue = updater.start_polling(poll_interval=1, timeout=5)
'''
# Alternatively, run with webhook:
updater.bot.setWebhook(webhook_url='https://%s/%s' % (BASE_URL, 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(HOST, PORT, url_path=TOKEN)
'''
# 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
elif len(text) > 0:
update_queue.put(text) # Put command into queue
示例10: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater("TOKEN", workers=2)
# Get the dispatcher to register handlers
dp = updater.dispatcher
dp.addTelegramCommandHandler("start", start)
dp.addTelegramCommandHandler("help", help)
dp.addUnknownTelegramCommandHandler(unknown_command)
dp.addTelegramMessageHandler(message)
dp.addTelegramRegexHandler('.*', any_message)
dp.addStringCommandHandler('reply', cli_reply)
dp.addUnknownStringCommandHandler(unknown_cli_command)
dp.addStringRegexHandler('[^/].*', cli_noncommand)
dp.addErrorHandler(error)
# Start the Bot and store the update Queue, so we can insert updates
update_queue = updater.start_polling(poll_interval=0.1, timeout=20)
'''
# Alternatively, run with webhook:
update_queue = updater.start_webhook('example.com',
443,
'cert.pem',
'key.key',
listen='0.0.0.0')
'''
# Start CLI-Loop
while True:
try:
text = raw_input()
except NameError:
text = input()
# Gracefully stop the event handler
if text == 'stop':
updater.stop()
break
# else, put the text into the update queue
elif len(text) > 0:
update_queue.put(text) # Put command into queue
示例11: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
updater = Updater(man.settings["authkey"]) #brew bot
#updater = Updater(man.settings["authkey_gmfrpg"]) #gmf rpg
dp = updater.dispatcher
j_que = updater.job_queue
j_que.put(brew_timer, 1)
j_que.put(illumi_time, 2)
j_que.put(msg_que, 10)
print("Brew 0.8 + Items&Drops DLC + ILLUMICOFFEE")
dp.addTelegramCommandHandler("brew", brew)
dp.addTelegramCommandHandler("brew_stats", brew_stats)
dp.addTelegramCommandHandler("brew_score", brew_score)
dp.addTelegramCommandHandler("brew_check", brew_check)
dp.addTelegramCommandHandler("brew_inventory", brew_inventory)
dp.addTelegramCommandHandler("brew_remove", brew_remove)
dp.addTelegramCommandHandler("brew_cons", brew_cons)
dp.addTelegramCommandHandler("brew_help", brew_help)
dp.addTelegramCommandHandler("brew_status", brew_status)
dp.addTelegramCommandHandler("rahka", rahka)
dp.addTelegramCommandHandler("illuminati", illuminati)
dp.addTelegramCommandHandler("illumi_shop", illumi_shop)
dp.addTelegramCommandHandler("give_money", give_money)
dp.addTelegramCommandHandler("terästä", terasta)
dp.addTelegramCommandHandler("brew_notify", brew_notify)
dp.addTelegramCommandHandler("brew_cancel", brew_cancel)
dp.addErrorHandler(error)
update_queue = updater.start_polling(poll_interval=2, timeout=10)
while True:
try:
text = input()
except NameError:
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)
示例12: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
def main():
settings = file('minecraftsettings.yml', 'r')
yaml_data = yaml.load(settings)
token = yaml_data['telegram-apikey']
updater = Updater(token)
disp = updater.dispatcher
updater.start_polling()
# Register commands
disp.addTelegramCommandHandler('ping', ping_command)
disp.addTelegramCommandHandler('start', start_command)
# CLI
while True:
try:
text = raw_input()
except NameError:
text = input()
if text == 'stop':
updater.stop()
break
示例13: UpdaterTest
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
class UpdaterTest(BaseTest, unittest.TestCase):
"""
This object represents Tests for Updater, Dispatcher, WebhookServer and
WebhookHandler
"""
def setUp(self):
self.updater = None
self.received_message = None
self.message_count = 0
self.lock = Lock()
def _setup_updater(self, *args, **kwargs):
bot = MockBot(*args, **kwargs)
self.updater = Updater(workers=2, bot=bot)
def tearDown(self):
if self.updater is not None:
self.updater.stop()
def reset(self):
self.message_count = 0
self.received_message = None
def telegramHandlerTest(self, bot, update):
self.received_message = update.message.text
self.message_count += 1
def telegramInlineHandlerTest(self, bot, update):
self.received_message = (update.inline_query,
update.chosen_inline_result)
self.message_count += 1
@run_async
def asyncHandlerTest(self, bot, update, **kwargs):
sleep(1)
with self.lock:
self.received_message = update.message.text
self.message_count += 1
def stringHandlerTest(self, bot, update):
self.received_message = update
self.message_count += 1
def regexGroupHandlerTest(self, bot, update, groups=None, groupdict=None):
self.received_message = (groups, groupdict)
self.message_count += 1
def additionalArgsTest(self, bot, update, update_queue, args):
self.received_message = update
self.message_count += 1
if args[0] == 'resend':
update_queue.put('/test5 noresend')
elif args[0] == 'noresend':
pass
def contextTest(self, bot, update, context):
self.received_message = update
self.message_count += 1
self.context = context
@run_async
def asyncAdditionalHandlerTest(self, bot, update, update_queue=None,
**kwargs):
sleep(1)
with self.lock:
if update_queue is not None:
self.received_message = update.message.text
self.message_count += 1
def errorRaisingHandlerTest(self, bot, update):
raise TelegramError(update)
def errorHandlerTest(self, bot, update, error):
self.received_message = error.message
self.message_count += 1
def test_addRemoveTelegramMessageHandler(self):
self._setup_updater('Test')
d = self.updater.dispatcher
d.addTelegramMessageHandler(
self.telegramHandlerTest)
self.updater.start_polling(0.01)
sleep(.1)
self.assertEqual(self.received_message, 'Test')
# Remove handler
d.removeTelegramMessageHandler(self.telegramHandlerTest)
self.reset()
self.updater.bot.send_messages = 1
sleep(.1)
self.assertTrue(None is self.received_message)
def test_addTelegramMessageHandlerMultipleMessages(self):
self._setup_updater('Multiple', 100)
self.updater.dispatcher.addTelegramMessageHandler(
self.telegramHandlerTest)
self.updater.start_polling(0.0)
sleep(2)
#.........这里部分代码省略.........
示例14: UpdaterTest
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
class UpdaterTest(BaseTest, unittest.TestCase):
"""
This object represents Tests for Updater, Dispatcher, WebhookServer and
WebhookHandler
"""
def setUp(self):
self.updater = None
self.received_message = None
self.message_count = 0
self.lock = Lock()
def _setup_updater(self, *args, **kwargs):
bot = MockBot(*args, **kwargs)
self.updater = Updater(workers=2, bot=bot)
def tearDown(self):
if self.updater is not None:
self.updater.stop()
def reset(self):
self.message_count = 0
self.received_message = None
def telegramHandlerTest(self, bot, update):
self.received_message = update.message.text
self.message_count += 1
@run_async
def asyncHandlerTest(self, bot, update, **kwargs):
sleep(1)
with self.lock:
self.received_message = update.message.text
self.message_count += 1
def stringHandlerTest(self, bot, update):
self.received_message = update
self.message_count += 1
def regexGroupHandlerTest(self, bot, update, groups=None, groupdict=None):
self.received_message = (groups, groupdict)
self.message_count += 1
def additionalArgsTest(self, bot, update, update_queue, args):
self.received_message = update
self.message_count += 1
if args[0] == "resend":
update_queue.put("/test5 noresend")
elif args[0] == "noresend":
pass
def contextTest(self, bot, update, context):
self.received_message = update
self.message_count += 1
self.context = context
@run_async
def asyncAdditionalHandlerTest(self, bot, update, update_queue=None, **kwargs):
sleep(1)
with self.lock:
if update_queue is not None:
self.received_message = update.message.text
self.message_count += 1
def errorRaisingHandlerTest(self, bot, update):
raise TelegramError(update)
def errorHandlerTest(self, bot, update, error):
self.received_message = error.message
self.message_count += 1
def test_addRemoveTelegramMessageHandler(self):
print("Testing add/removeTelegramMessageHandler")
self._setup_updater("Test")
d = self.updater.dispatcher
d.addTelegramMessageHandler(self.telegramHandlerTest)
self.updater.start_polling(0.01)
sleep(0.1)
self.assertEqual(self.received_message, "Test")
# Remove handler
d.removeTelegramMessageHandler(self.telegramHandlerTest)
self.reset()
self.updater.bot.send_messages = 1
sleep(0.1)
self.assertTrue(None is self.received_message)
def test_addTelegramMessageHandlerMultipleMessages(self):
print("Testing addTelegramMessageHandler and send 100 messages...")
self._setup_updater("Multiple", 100)
self.updater.dispatcher.addTelegramMessageHandler(self.telegramHandlerTest)
self.updater.start_polling(0.0)
sleep(2)
self.assertEqual(self.received_message, "Multiple")
self.assertEqual(self.message_count, 100)
def test_addRemoveTelegramRegexHandler(self):
print("Testing add/removeStringRegexHandler")
self._setup_updater("Test2")
#.........这里部分代码省略.........
示例15: main
# 需要导入模块: from telegram import Updater [as 别名]
# 或者: from telegram.Updater import stop [as 别名]
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.addTelegramCommandHandler("start", start)
dp.addTelegramCommandHandler("help", help)
dp.addUnknownTelegramCommandHandler(unknown_command)
# Message handlers only receive updates that don't contain commands
dp.addTelegramMessageHandler(message)
# Regex handlers will receive all updates on which their regex matches
dp.addTelegramRegexHandler('.*', any_message)
# String handlers work pretty much the same
dp.addStringCommandHandler('reply', cli_reply)
dp.addUnknownStringCommandHandler(unknown_cli_command)
dp.addStringRegexHandler('[^/].*', cli_noncommand)
# All TelegramErrors are caught for you and delivered to the error
# handler(s). Other types of Errors are not caught.
dp.addErrorHandler(error)
# Start the Bot and store the update Queue, so we can insert updates
update_queue = updater.start_polling(poll_interval=0.1, timeout=10)
'''
# Alternatively, run with webhook:
updater.bot.setWebhook(webhook_url='https://example.com/%s' % token,
certificate=open('cert.pem', 'rb'))
update_queue = updater.start_webhook('0.0.0.0',
443,
url_path=token,
cert='cert.pem',
key='key.key')
# 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:
try:
text = raw_input()
except NameError:
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)