本文整理汇总了Python中telegram.ext.Updater方法的典型用法代码示例。如果您正苦于以下问题:Python ext.Updater方法的具体用法?Python ext.Updater怎么用?Python ext.Updater使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.ext
的用法示例。
在下文中一共展示了ext.Updater方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [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()
示例2: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [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()
示例3: start
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
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()
示例4: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
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()
示例5: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [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!')
示例6: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [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()
示例7: send_on_telegram
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
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()
示例8: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [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()
示例9: add_towel_mode
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [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"]
})
示例10: __init__
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
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
示例11: setup
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
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()
示例12: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
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()
示例13: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
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}')
示例14: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
def main():
updater = Updater(token=config.TOKEN,use_context=True)
dispatcher = updater.dispatcher
updater.dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(MessageHandler(Filters.document,file_handler))
updater.start_polling()
示例15: main
# 需要导入模块: from telegram import ext [as 别名]
# 或者: from telegram.ext import Updater [as 别名]
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()