Python telegram.ext.Updater() Examples
The following are 30
code examples of telegram.ext.Updater().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
telegram.ext
, or try the search function
.
Example #1
Source File: Server.py From CineMonster with Apache License 2.0 | 7 votes |
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()
Example #2
Source File: towel_mode.py From vldc-bot with MIT License | 6 votes |
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"] })
Example #3
Source File: telegramRSSbot.py From RSS-to-Telegram-Bot with GNU General Public License v3.0 | 6 votes |
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()
Example #4
Source File: telegramrss.py From RSS-to-Telegram-Bot with GNU General Public License v3.0 | 6 votes |
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()
Example #5
Source File: bot.py From TranscriberBot with GNU General Public License v3.0 | 6 votes |
def start(self, token): self.voice_thread_pool = ThreadPoolExecutor( max_workers=config.get_config_prop("app")["voice_max_threads"] ) self.photos_thread_pool = ThreadPoolExecutor( max_workers=config.get_config_prop("app")["photos_max_threads"] ) self.misc_thread_pool = ThreadPoolExecutor( max_workers=2 ) self.queue = mq.MessageQueue() self.request = Request(con_pool_size=10) self.mqbot = self.MQBot(token, request=self.request, mqueue=self.queue) self.updater = Updater(bot=self.mqbot, use_context=True) self.dispatcher = self.updater.dispatcher self.__register_handlers() self.updater.start_polling(clean=True) self.updater.idle()
Example #6
Source File: telegram_main.py From convai-bot-1337 with GNU General Public License v3.0 | 6 votes |
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
Example #7
Source File: bot.py From welcomebot with GNU General Public License v2.0 | 6 votes |
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()
Example #8
Source File: bot.py From ConvAI-baseline with Apache License 2.0 | 6 votes |
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!')
Example #9
Source File: maintenance.py From NanoWalletBot with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()
Example #10
Source File: telegram_bot.py From ravestate with BSD 3-Clause "New" or "Revised" License | 6 votes |
def send_on_telegram(ctx: rs.ContextWrapper, text: str): """ If all telegram chats should be in the same context, sends the text to every currently active chat. Otherwise it only sends output using the Pipe if it is a child process """ if not text or not isinstance(text, str): return rs.Resign() if ctx.conf(key=ALL_IN_ONE_CONTEXT_CONFIG_KEY): # TODO don't instantiate the updater every time token = ctx.conf(key=TOKEN_CONFIG_KEY) if not token: logger.error('telegram-token is not set. Shutting down telegramio') return rs.Delete() updater: Updater = Updater(token) for chat_id in active_chats.keys(): updater.bot.send_message(chat_id=chat_id, text=text) else: child_conn = ctx.conf(key=CHILD_CONN_CONFIG_KEY) if child_conn: # Child Process -> write to Pipe child_conn.send(text) else: # Master Process -> State not needed return rs.Delete()
Example #11
Source File: bot.py From python-telegram-bot-openshift with GNU General Public License v3.0 | 6 votes |
def setup(webhook_url=None): """If webhook_url is not passed, run with long-polling.""" logging.basicConfig(level=logging.WARNING) if webhook_url: bot = Bot(TOKEN) update_queue = Queue() dp = Dispatcher(bot, update_queue) else: updater = Updater(TOKEN) bot = updater.bot dp = updater.dispatcher dp.add_handler(MessageHandler([], example_handler)) # Remove this line # Add your handlers here if webhook_url: bot.set_webhook(webhook_url=webhook_url) thread = Thread(target=dp.start, name='dispatcher') thread.start() return update_queue, bot else: bot.set_webhook() # Delete webhook updater.start_polling() updater.idle()
Example #12
Source File: start.py From server_monitor_bot with MIT License | 6 votes |
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()
Example #13
Source File: bot.py From gdrivemirror_bot with GNU General Public License v3.0 | 6 votes |
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()
Example #14
Source File: bot.py From bot-telegram-comentarios-xvideos with GNU General Public License v3.0 | 6 votes |
def main(): logging.basicConfig( filename='/var/log/bot-telegram-xvideos.log', level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m-%d-%Y %H:%M:%S') try: updater = Updater(os.environ['BOT_TELEGRAM_XVIDEOS_TOKEN']) dispatcher = updater.dispatcher dispatcher.add_handler(CommandHandler('start', start)) dispatcher.add_handler(CommandHandler('comment', comment)) updater.start_polling() print('Running!') updater.idle() print() except Exception as ex: logging.critical(f'{ex}')
Example #15
Source File: roll.py From vldc-bot with MIT License | 5 votes |
def add_roll(upd: Updater, handlers_group: int): logger.info("registering roll handlers") dp = upd.dispatcher dp.add_handler(CommandHandler("roll", roll), handlers_group) dp.add_handler(CommandHandler("gdpr_me", satisfy_GDPR), handlers_group) dp.add_handler(CommandHandler("hussars", show_hussars, filters=admin_filter), handlers_group) dp.add_handler(CommandHandler("wipe_hussars", wipe_hussars, filters=admin_filter), handlers_group)
Example #16
Source File: core.py From vldc-bot with MIT License | 5 votes |
def add_core(upd: Updater, core_handlers_group: int): logger.info("register smile-mode handlers") dp = upd.dispatcher dp.add_handler(CommandHandler("start", start), core_handlers_group) dp.add_handler(CommandHandler("help", help_), core_handlers_group)
Example #17
Source File: banme.py From vldc-bot with MIT License | 5 votes |
def add_banme(upd: Updater, handlers_group: int): logger.info("registering banme handlers") dp = upd.dispatcher dp.add_handler(CommandHandler("banme", banme), handlers_group)
Example #18
Source File: smile_mode.py From vldc-bot with MIT License | 5 votes |
def add_smile_mode(upd: Updater, handlers_group: int): """ Set up all handler for SmileMode """ logger.info("registering smile-mode handlers") dp = upd.dispatcher dp.add_handler(MessageHandler(~Filters.sticker & ~Filters.animation, smile), handlers_group)
Example #19
Source File: at_least_70k.py From vldc-bot with MIT License | 5 votes |
def add_70k(upd: Updater, handlers_group: int): logger.info("registering 70k handler") dp: Dispatcher = upd.dispatcher dp.add_handler(CommandHandler("70k", _70k), handlers_group)
Example #20
Source File: uwu.py From vldc-bot with MIT License | 5 votes |
def add_uwu(upd: Updater, handlers_group: int): logger.info("register uwu handlers") dp = upd.dispatcher dp.add_handler(MessageHandler(uwu_filter, uwu), handlers_group)
Example #21
Source File: mute.py From vldc-bot with MIT License | 5 votes |
def add_mute(upd: Updater, handlers_group: int): logger.info("registering mute handlers") dp = upd.dispatcher dp.add_handler(CommandHandler("mute", mute, filters=admin_filter), handlers_group) dp.add_handler(CommandHandler("unmute", unmute, filters=admin_filter), handlers_group)
Example #22
Source File: fools.py From vldc-bot with MIT License | 5 votes |
def add_fools_mode(upd: Updater, handlers_group: int): logger.info("registering fools handlers") dp = upd.dispatcher dp.add_handler(MessageHandler(Filters.group & ~ Filters.status_update, mesaĝa_traduko), handlers_group)
Example #23
Source File: still.py From vldc-bot with MIT License | 5 votes |
def add_still(upd: Updater, handlers_group: int): logger.info("registering still handlers") dp = upd.dispatcher dp.add_handler(CommandHandler("still", still), handlers_group)
Example #24
Source File: botcore.py From UnivaqBot with MIT License | 5 votes |
def main(): """Defining the main function""" token = os.environ['TELEGRAMBOT'] or os.environ['UNIVERSITYBOT'] logger = utils.get_logger(os.environ['DEBUG']) updater = Updater(token) utils.db_connection() utils.get_users() utils.get_news() updater.job_queue.run_repeating(news.notify_news, float(os.environ['NOTIFICATION_INTERVAL'])) updater.job_queue.run_once(utils.botupdated_message, 0) dispatcher = updater.dispatcher dispatcher.add_handler(CommandHandler("start", start_command)) dispatcher.add_handler(CommandHandler("help", help_command)) dispatcher.add_handler(news_commands.NEWS_CONV) dispatcher.add_handler(news_commands.NEWS_ON_CONV) dispatcher.add_handler(news_commands.NEWS_OFF_CONV) dispatcher.add_handler(CommandHandler("prof", other_commands.prof_command, pass_args=True)) dispatcher.add_handler(CommandHandler("segreteria", other_commands.student_office_command)) dispatcher.add_handler(CommandHandler("mensa", other_commands.canteen_command)) dispatcher.add_handler(CommandHandler("adsu", other_commands.adsu_command)) dispatcher.add_handler(feedback.FEEDBACK_CONV) logger.info('Bot started') updater.start_polling() updater.idle()
Example #25
Source File: echobot2.py From bale-bot-samples with Apache License 2.0 | 5 votes |
def main(): """Start the bot.""" # Create the Updater and pass it your bot's token. # Make sure to set use_context=True to use the new context based callbacks # Post version 12 this will no longer be necessary updater = Updater(token="TOKEN", base_url="https://tapi.bale.ai/") # 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(poll_interval=2) # 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()
Example #26
Source File: bot.py From music-bot with GNU General Public License v3.0 | 5 votes |
def main(): u = Updater('YOUR-TOKEN') dp = u.dispatcher dp.add_handler(CommandHandler("start", start)) dp.add_handler(MessageHandler(Filters.text, music)) u.start_polling() u.idle()
Example #27
Source File: main.py From simple-forwarder-bot with MIT License | 5 votes |
def main(): global dispatcher, updater, Token, Blacklist, admin load_config() updater = Updater(Token) dispatcher = updater.dispatcher fwd_text_handler = MessageHandler(Filters.all & (~Filters.command), read_text_message) ban_user_handler = CommandHandler('ban', ban_user) unban_user_handler = CommandHandler('unban', unban_user) callback_query_handler = CallbackQueryHandler(answer_session) dispatcher.add_handler(callback_query_handler) dispatcher.add_handler(fwd_text_handler) dispatcher.add_handler(ban_user_handler) dispatcher.add_handler(unban_user_handler) updater.start_polling()
Example #28
Source File: bot.py From Awesome-Python-Scripts with MIT License | 5 votes |
def main(): """Start the bot.""" # Create the EventHandler and pass it your bot's token. TOKEN = os.environ['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)) dp.add_handler(CommandHandler("get", get)) dp.add_handler(CommandHandler("ls", ls)) dp.add_handler(CommandHandler("put", put)) dp.add_handler(CommandHandler("mkdir", mkdir)) #admin functionalities dp.add_handler(CommandHandler("adduser", add_user)) dp.add_handler(CommandHandler("showuser", show_user)) dp.add_handler(CommandHandler("removeUser", remove_user)) dp.add_handler(CommandHandler("remove", remove)) dp.add_handler(CommandHandler("rmdir", rmdir)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.document, 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()
Example #29
Source File: bot.py From Crypto_trading_robot with MIT License | 5 votes |
def __init__(self, token): global bot super(Manager, self).__init__() self.__updater = Updater(token)
Example #30
Source File: telegram_fbchat_facade.py From steely with GNU General Public License v3.0 | 5 votes |
def __init__(self, email, password): '''Creates a client. Args: email (str): Is thrown away. password (str): Is used as the Telegram bot key.''' self.updater = Updater(token=password) self.dispatcher = self.updater.dispatcher self.bot = self.updater.bot self.uid = self.updater.bot.username # Each self.thread[thread_id] is a deque (FIFO linked list). self.thread = defaultdict(lambda: deque(iterable=[], maxlen=Client.NUM_STORED_MESSAGES_IN_THREAD))