def main(): random.seed(None) updater = Updater(token='<YOUR_TOKEN>') dispatcher = updater.dispatcher dispatcher.addTelegramMessageHandler(echo) dispatcher.addTelegramCommandHandler('boobs', echo) updater.start_polling()
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater("123456789:ABCDEFGHIJKLM") job_queue = updater.job_queue job_queue.put(track_items, 60, next_t=0) #job_queue.put(publish_new_offers, 60, next_t=0) # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.addTelegramCommandHandler("start", start) dp.addTelegramCommandHandler("help", help_info) dp.addTelegramCommandHandler("add", add_item) dp.addTelegramCommandHandler("list", list_items) dp.addTelegramCommandHandler("readd", readd_items) dp.addTelegramCommandHandler("addme", add_user) dp.addTelegramCommandHandler("del", del_item) dp.addTelegramCommandHandler("canal", canal) # on noncommand i.e message - echo the message on Telegram dp.addTelegramMessageHandler(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()
def __init__(self, token, rootpath='/opt/code/telegram-projects/'): self.token = token self.rootpath = rootpath print("[+] initializing telegram bot") self.updater = Updater(token=self.token) self.bot = self.updater.bot dispatcher = self.updater.dispatcher print("[+] make sure ssh-agent is running") if not j.sal.process.checkProcessRunning('ssh-agent'): j.do.execute('eval `ssh-agent`') # commands dispatcher.addTelegramCommandHandler('start', self.start) dispatcher.addTelegramCommandHandler('project', self.project) dispatcher.addTelegramCommandHandler('blueprint', self.blueprint) dispatcher.addTelegramCommandHandler('ays', self.ays) dispatcher.addTelegramCommandHandler('help', self.help) # messages dispatcher.addTelegramMessageHandler(self.message) # internal dispatcher.addUnknownTelegramCommandHandler(self.unknown) print("[+] projects will be saved to: %s" % rootpath) j.sal.fs.createDir(rootpath) print("[+] loading existing users") self.users = self.restore()
def main(): # 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.addTelegramCommandHandler("help", help) dp.addTelegramCommandHandler("start", home) dp.addTelegramCommandHandler("home", home) dp.addTelegramCommandHandler("price", price) dp.addTelegramCommandHandler("register", register) dp.addTelegramCommandHandler("balances", balances) dp.addTelegramCommandHandler("transactions", transactions) dp.addTelegramCommandHandler("trades", trades) dp.addTelegramCommandHandler("tickers", tickers) dp.addTelegramCommandHandler("discounts", discounts) dp.addTelegramCommandHandler("delete_keys", deleteKeys) dp.addTelegramCommandHandler("bitcoin_data", bitcoinData) dp.addTelegramCommandHandler("orders", orders) for fund in FUNDS: dp.addTelegramCommandHandler(('tr_' + fund), fundTrades) dp.addTelegramCommandHandler(('tick_' + fund), ticker) dp.addTelegramCommandHandler(('ord_' + fund), fundOrders) for currency in CURRENCIES: dp.addTelegramCommandHandler(('disc_' + currency), currDiscount) dp.addTelegramMessageHandler(signup) dp.addErrorHandler(error) updater.start_polling() updater.idle()
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(BOTKEY) # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram for cmd in ['up', 'down', 'refresh', 'status']: dp.addTelegramCommandHandler(cmd, ssrs) for cmd in ['newbot', 'forcenewbot']: dp.addTelegramCommandHandler(cmd, newbot) for cmd in [1]: dp.addTelegramCommandHandler('updatebot', updatebot) dp.addTelegramCommandHandler('rmbot', rmbot) dp.addTelegramCommandHandler('listbots', listbots) dp.addTelegramCommandHandler("start", help) dp.addTelegramCommandHandler("help", help) # on noncommand i.e message - echo the message on Telegram dp.addTelegramMessageHandler(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()
def main(): """Main program""" # Create the EventHandler and pass it your bot's token. updater = Updater(token='KEY') # Get the dispatcher to register handlers dispatcher = updater.dispatcher # on different commands - answer in Telegram dispatcher.addTelegramCommandHandler('start', start) dispatcher.addTelegramCommandHandler('nuevavotacion', newpoll) dispatcher.addTelegramCommandHandler('respuesta', response) dispatcher.addTelegramCommandHandler('iniciovotacion', initpoll) dispatcher.addTelegramCommandHandler('finvotacion', endpoll) dispatcher.addUnknownTelegramCommandHandler(unknown) # on noncommand i.e message dispatcher.addTelegramMessageHandler(receiver) # 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()
def __init__(self, refresh_users): self.updater = Updater( token="178290745:AAH_Vrkyg5f5C0NkOSUCs7kKaXcv__wUT90") self.dispatcher = self.updater.dispatcher self.dispatcher.addTelegramCommandHandler('start', self.start) self.dispatcher.addTelegramCommandHandler('help', self.help) self.dispatcher.addTelegramCommandHandler('add', self.add) self.dispatcher.addTelegramCommandHandler('done', self.done) self.dispatcher.addTelegramCommandHandler('show', self.show) self.dispatcher.addTelegramMessageHandler(self.echo) self.dispatcher.addUnknownTelegramCommandHandler(self.unknown) self.help_message = "The next commands are available:\n" \ + "- type '/start' to resend a greeting message\n" \ + "- type '/help' to see the help message with the list of a commands\n" \ + "- type '/add title' to add task with given title\n" \ + "- type '/done' to mark tasks as done\n" \ + "- type '/show' to see the full list of tasks\n" if refresh_users: self.users = {} else: try: with open("users.pickle", 'rb') as f: self.users = pickle.load(f) except IOError: self.users = {}
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater("135342801:AAFaninNSzDkYU8UzonHeOhcu5fVaPlCC7Y") # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.addTelegramCommandHandler("start", start) dp.addTelegramCommandHandler("help", help) # on noncommand i.e message - echo the message on Telegram dp.addTelegramMessageHandler(echo) # log all errors dp.addErrorHandler(error) # Start the Bot updater.start_polling() runloop() # 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()
def main(): global logger # load the logging configuration real_path = os.path.dirname(os.path.realpath(__file__)) logging.config.fileConfig(real_path + '/logging.ini') logger = logging.getLogger(__name__) # Get the dispatcher to register handlers updater = Updater(token="TOKEN") dp = updater.dispatcher # on different commands - answer in Telegram dp.addTelegramCommandHandler("start", start) dp.addTelegramCommandHandler("roll", Dice.roll) # log all errors dp.addErrorHandler(error) logger.info('Starting new bot') roll() # Start the Bot updater.start_polling() # Block 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()
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)
def main(): # Create the EventHandler and pass it your bot's token. #updater = Updater(settings.APITOKEN) updater = Updater(APITOKEN) # 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("randomvideo", randomvideo) dp.addTelegramCommandHandler("random", random) dp.addTelegramCommandHandler("caso", caso) # on noncommand i.e message - echo the message on Telegram dp.addTelegramMessageHandler(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()
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)
def __init__(self, token, vk_client_id): self.poller = Poller() self.updater = Updater(token=token) self.vk = Vk(vk_client_id) self.clients = Client.all_from_db() self.reg_actions() self.restore()
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)
def main(): thread.start_new_thread(checkFlood, (2, )) updater = Updater(botID) dp = updater.dispatcher dp.addTelegramCommandHandler("start", start) dp.addTelegramCommandHandler("google", google) dp.addErrorHandler(error) updater.start_polling() updater.idle()
def main(): mybot = Updater("699053794:AAH8KEIug-7IZXTSlUOMQGfFEq_oyrVPQtk", request_kwargs=PROXY) dp = mybot.dispatcher dp.add_handler(CommandHandler("start", greet_user)) dp.add_handler(CommandHandler("planet", planet_take)) dp.add_handler(MessageHandler(Filters.text, talk_to_me)) print('*'*10) mybot.start_polling() mybot.idle() print('*' * 10)
def __init__(self): self.config = configparser.ConfigParser() self.config.read(CONFIGFILE_PATH) self.updater = Updater(token=self.get_bot_conf("TOKEN")) self.dispatcher = self.updater.dispatcher self.add_handlers() try: self.tzinfo = timezone(self.get_bot_conf("TIMEZONE")) except: self.tzinfo = pytz.utc
def main(): config = configparser.ConfigParser() config.read('config.ini') token = config['authorization']['token'] updater = Updater(token=token) dispatcher = updater.dispatcher dispatcher.addTelegramCommandHandler('start', start) dispatcher.addTelegramMessageHandler(print_pdf) updater.start_polling()
def main(): updater = Updater(config['bot_id'], workers=5) dispatcher = updater.dispatcher dispatcher.addTelegramCommandHandler('start', start) dispatcher.addTelegramCommandHandler('help', help) dispatcher.addTelegramCommandHandler('ping', ping) dispatcher.addTelegramCommandHandler('ping6', ping6) dispatcher.addTelegramCommandHandler('traceroute', traceroute) dispatcher.addTelegramCommandHandler('traceroute6', traceroute6) dispatcher.addTelegramCommandHandler('down', down) dispatcher.addErrorHandler(error) updater.start_polling()
def run_bot(): updater = Updater(BOT_TOCKEN) updater.dispatcher.addErrorHandler(on_error) updater.dispatcher.addTelegramCommandHandler("start", on_start) updater.dispatcher.addTelegramCommandHandler("ls", on_ls) updater.dispatcher.addTelegramCommandHandler("cd", on_cd) updater.dispatcher.addTelegramCommandHandler("get", on_get) updater.dispatcher.addTelegramCommandHandler("cat", on_cat) updater.dispatcher.addTelegramCommandHandler("pwd", on_pwd) updater.dispatcher.addTelegramCommandHandler("history", on_history) updater.dispatcher.addTelegramMessageHandler(on_message) updater.start_polling() updater.idle()
def main(): """Add command handlers specified earlier and start the bot.""" updater = Updater(TOKEN) dispatcher = updater.dispatcher dispatcher.addTelegramCommandHandler("start", bot_start) dispatcher.addTelegramCommandHandler("online", bot_online) dispatcher.addTelegramCommandHandler("help", bot_help) dispatcher.addErrorHandler(bot_error) updater.start_polling() updater.idle()
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.addTelegramCommandHandler("start", start) dp.addTelegramCommandHandler("help", help) dp.addTelegramMessageHandler(echo) # log all errors dp.addErrorHandler(error) # Start the Bot updater.start_polling() updater.idle()
def main(): updater = Updater(token='TOKEN') dp = updater.dispatcher dp.addTelegramCommandHandler("start", start) dp.addTelegramCommandHandler("help", help) dp.addTelegramMessageHandler(echo) dp.addErrorHandler(error) updater.start_polling() updater.idle()
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
def main(): updater = Updater("KEY") dp = updater.dispatcher dp.addTelegramCommandHandler("start", start) dp.addTelegramCommandHandler("help", help) dp.addTelegramCommandHandler("gerrit", gerrit) dp.addTelegramCommandHandler("turingtest", turingtest) dp.addTelegramCommandHandler("halay", halay) dp.addTelegramCommandHandler("icselhalay", icselhalay) dp.addTelegramCommandHandler("turku", turku) dp.addTelegramMessageHandler(echo) dp.addErrorHandler(error) updater.start_polling(timeout=5) updater.idle()
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
def bot_main(bot_token=""): # Create the EventHandler and pass it your bot's token. updater = Updater(bot_token) common.bot = updater.bot # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.addTelegramCommandHandler("subscribe", subscribe) dp.addTelegramCommandHandler("unsubscribe", unsubscribe) # Start the Bot updater.start_polling(timeout=5) # Run the bot until the user presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT updater.idle()
def __init__(self, db, chats): self.db = db self.chats = chats self.updater = Updater(token=GET_TOKEN()) dispatcher = self.updater.dispatcher dispatcher.addTelegramCommandHandler('start', self.start) dispatcher.addTelegramCommandHandler('restrict', self.add_restrict) dispatcher.addTelegramCommandHandler('stat', self.stats) dispatcher.addTelegramCommandHandler('info', self.info) dispatcher.addTelegramCommandHandler('help', self.help) dispatcher.addTelegramCommandHandler('sites', self.sites) dispatcher.addTelegramMessageHandler(self.answer) self.updater.start_polling() self.bot = telegram.Bot(token=GET_TOKEN()) self.statistician = Statistic(GET_FIRST_TIME(), GET_LAST_TIME(), db)
def main(): global CLIENT # Create the EventHandler and pass it your bot's token. updater = Updater("TOKEN_HERE") # Set URL to Dublin Bus RTPI url = 'http://rtpi.dublinbus.ie/DublinBusRTPIService.asmx?wsdl' # Import the correct XML Schema and namespace imp = Import('http://www.w3.org/2001/XMLSchema', location='http://www.w3.org/2001/XMLSchema.xsd') imp.filter.add('http://dublinbus.ie/') d = ImportDoctor(imp) # Setup the global client with the import doctor and url try: CLIENT = Client(url, doctor=d) print "Suds Client Connected" except: print "Client connection error" # UTF-8: http://stackoverflow.com/a/17628350 reload(sys) # Reload does the trick! sys.setdefaultencoding('UTF8') # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.addTelegramCommandHandler("start", start) dp.addTelegramCommandHandler("help", help) # on noncommand i.e message - echo the message on Telegram dp.addTelegramMessageHandler(message) # on error - print error to stdout dp.addErrorHandler(error) # Start the Bot updater.start_polling(timeout=5) # Run the bot until the user presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT updater.idle()
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater("128116768:AAFsiMmSV7KjiN8xIidv7eX8TNgbnJ4zMLA") jobs = updater.job_queue jobs.put(update, 1, prevent_autostart=False) # Get the dispatcher to register handlers dp = updater.dispatcher dp.addTelegramCommandHandler('status',statusOfPlant) dp.addTelegramCommandHandler('register',register) # 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()