improved twitter/x message mode detection

master
Chris Caron 2025-02-21 18:07:30 -05:00
parent 9bd20a283d
commit 9bf45e415d
1 changed files with 11 additions and 6 deletions

View File

@ -195,7 +195,7 @@ class NotifyTwitter(NotifyBase):
}) })
def __init__(self, ckey, csecret, akey, asecret, targets=None, def __init__(self, ckey, csecret, akey, asecret, targets=None,
mode=TwitterMessageMode.DM, cache=True, batch=True, **kwargs): mode=None, cache=True, batch=True, **kwargs):
""" """
Initialize Twitter Object Initialize Twitter Object
@ -230,11 +230,16 @@ class NotifyTwitter(NotifyBase):
self.mode = self.template_args['mode']['default'] \ self.mode = self.template_args['mode']['default'] \
if not isinstance(mode, str) else mode.lower() if not isinstance(mode, str) else mode.lower()
if self.mode not in TWITTER_MESSAGE_MODES: if mode and isinstance(mode, str):
msg = 'The Twitter message mode specified ({}) is invalid.' \ self.mode = next(
.format(mode) (a for a in TWITTER_MESSAGE_MODES if a.startswith(mode)), None)
self.logger.warning(msg) if self.mode not in TWITTER_MESSAGE_MODES:
raise TypeError(msg) msg = 'The Twitter message mode specified ({}) is invalid.'\
.format(mode)
self.logger.warning(msg)
raise TypeError(msg)
else:
self.mode = self.template_args['mode']['default']
# Set Cache Flag # Set Cache Flag
self.cache = cache self.cache = cache