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
|
global _updater
|
||||||
|
|
||||||
_CONF.update(config)
|
_CONF.update(config)
|
||||||
if not _CONF['telegram']['enabled']:
|
if not is_enabled():
|
||||||
return
|
return
|
||||||
|
|
||||||
_updater = Updater(token=config['telegram']['token'], workers=0)
|
_updater = Updater(token=config['telegram']['token'], workers=0)
|
||||||
@ -67,9 +67,18 @@ def cleanup() -> None:
|
|||||||
Stops all running telegram threads.
|
Stops all running telegram threads.
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
if not is_enabled():
|
||||||
|
return
|
||||||
_updater.stop()
|
_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]:
|
def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[..., Any]:
|
||||||
"""
|
"""
|
||||||
Decorator to check if the message comes from the correct chat_id
|
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
|
:param parse_mode: telegram parse mode
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if _CONF['telegram'].get('enabled', False):
|
if not is_enabled():
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
bot = bot or _updater.bot
|
bot = bot or _updater.bot
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user