remove get_updater
This commit is contained in:
parent
4ec2ac6d60
commit
fe36f3a552
@ -7,7 +7,6 @@ from sqlalchemy import and_, func, text
|
|||||||
from telegram.error import NetworkError
|
from telegram.error import NetworkError
|
||||||
from telegram.ext import CommandHandler, Updater
|
from telegram.ext import CommandHandler, Updater
|
||||||
from telegram import ParseMode, Bot, Update
|
from telegram import ParseMode, Bot, Update
|
||||||
from wrapt import synchronized
|
|
||||||
|
|
||||||
from persistence import Trade
|
from persistence import Trade
|
||||||
|
|
||||||
@ -30,6 +29,9 @@ def init(config: dict) -> None:
|
|||||||
:param config: config to use
|
:param config: config to use
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
global _updater
|
||||||
|
_updater = Updater(token=config['telegram']['token'], workers=0)
|
||||||
|
|
||||||
_conf.update(config)
|
_conf.update(config)
|
||||||
|
|
||||||
# Register command handler and start telegram message polling
|
# Register command handler and start telegram message polling
|
||||||
@ -42,8 +44,8 @@ def init(config: dict) -> None:
|
|||||||
CommandHandler('performance', _performance),
|
CommandHandler('performance', _performance),
|
||||||
]
|
]
|
||||||
for handle in handles:
|
for handle in handles:
|
||||||
get_updater(_conf).dispatcher.add_handler(handle)
|
_updater.dispatcher.add_handler(handle)
|
||||||
get_updater(_conf).start_polling(
|
_updater.start_polling(
|
||||||
clean=True,
|
clean=True,
|
||||||
bootstrap_retries=3,
|
bootstrap_retries=3,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
@ -295,19 +297,6 @@ def _performance(bot: Bot, update: Update) -> None:
|
|||||||
send_msg(message, parse_mode=ParseMode.HTML)
|
send_msg(message, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
|
|
||||||
@synchronized
|
|
||||||
def get_updater(config: dict) -> Updater:
|
|
||||||
"""
|
|
||||||
Returns the current telegram updater or instantiates a new one
|
|
||||||
:param config: dict
|
|
||||||
:return: telegram.ext.Updater
|
|
||||||
"""
|
|
||||||
global _updater
|
|
||||||
if not _updater:
|
|
||||||
_updater = Updater(token=config['telegram']['token'], workers=0)
|
|
||||||
return _updater
|
|
||||||
|
|
||||||
|
|
||||||
def send_msg(msg: str, bot: Bot=None, parse_mode: ParseMode=ParseMode.MARKDOWN) -> None:
|
def send_msg(msg: str, bot: Bot=None, parse_mode: ParseMode=ParseMode.MARKDOWN) -> None:
|
||||||
"""
|
"""
|
||||||
Send given markdown message
|
Send given markdown message
|
||||||
@ -318,7 +307,7 @@ def send_msg(msg: str, bot: Bot=None, parse_mode: ParseMode=ParseMode.MARKDOWN)
|
|||||||
"""
|
"""
|
||||||
if _conf['telegram'].get('enabled', False):
|
if _conf['telegram'].get('enabled', False):
|
||||||
try:
|
try:
|
||||||
bot = bot or get_updater(_conf).bot
|
bot = bot or _updater.bot
|
||||||
try:
|
try:
|
||||||
bot.send_message(_conf['telegram']['chat_id'], msg, parse_mode=parse_mode)
|
bot.send_message(_conf['telegram']['chat_id'], msg, parse_mode=parse_mode)
|
||||||
except NetworkError as error:
|
except NetworkError as error:
|
||||||
|
Loading…
Reference in New Issue
Block a user