telegram.cleanup: fix NoneType issue when telegram is deactivated
This commit is contained in:
parent
c3653dc417
commit
465c91b9a9
@ -32,7 +32,7 @@ def init(config: dict) -> None:
|
||||
global _updater
|
||||
|
||||
_CONF.update(config)
|
||||
if not _CONF['telegram']['enabled']:
|
||||
if not is_enabled():
|
||||
return
|
||||
|
||||
_updater = Updater(token=config['telegram']['token'], workers=0)
|
||||
@ -67,9 +67,18 @@ def cleanup() -> None:
|
||||
Stops all running telegram threads.
|
||||
:return: None
|
||||
"""
|
||||
if not is_enabled():
|
||||
return
|
||||
_updater.stop()
|
||||
|
||||
|
||||
def is_enabled() -> bool:
|
||||
"""
|
||||
Returns True if the telegram module is activated, False otherwise
|
||||
"""
|
||||
return bool(_CONF['telegram'].get('enabled', False))
|
||||
|
||||
|
||||
def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[..., Any]:
|
||||
"""
|
||||
Decorator to check if the message comes from the correct chat_id
|
||||
@ -362,7 +371,8 @@ def send_msg(msg: str, bot: Bot = None, parse_mode: ParseMode = ParseMode.MARKDO
|
||||
:param parse_mode: telegram parse mode
|
||||
:return: None
|
||||
"""
|
||||
if _CONF['telegram'].get('enabled', False):
|
||||
if not is_enabled():
|
||||
return
|
||||
try:
|
||||
bot = bot or _updater.bot
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user