elif amount reduction

* reduced amount of unnecessary elif after return
* some formatting
This commit is contained in:
nico 2018-11-09 19:56:09 +01:00
parent cd1442e216
commit 86d058237b
2 changed files with 17 additions and 21 deletions

View file

@ -24,27 +24,21 @@ def validate(keyword, target):
:param target: provided target :param target: provided target
:return: true if valid :return: true if valid
""" """
# check if keyword is in the argument list # if keyword in domain_keywords list
if keyword in StaticAnswers().keys(): if keyword in StaticAnswers().keys('domain_keywords'):
# if target is a domain / email return True
# if keyword in domain_keywords list if validators.domain(target) or validators.email(target):
if keyword in StaticAnswers().keys('domain_keywords'):
# if target is a domain / email return True
if validators.domain(target):
return True
elif validators.email(target):
return True
# check if keyword is in number_keyword list
elif keyword in StaticAnswers().keys('number_keywords'):
# if target only consists of digits return True
if target.isdigit():
return True
# if keyword is in no_arg_keywords list return True
elif keyword in StaticAnswers().keys("no_arg_keywords"):
return True return True
# check if keyword is in number_keyword list
elif keyword in StaticAnswers().keys('number_keywords'):
# if target only consists of digits return True
return target.isdigit()
# if keyword is in no_arg_keywords list return True
elif keyword in StaticAnswers().keys("no_arg_keywords"):
return True
# if the target could not be validated until this return False # if the target could not be validated until this return False
return False return False

View file

@ -13,11 +13,13 @@ class StaticAnswers:
'version': '!version domain.tld -- receive XMPP server version', 'version': '!version domain.tld -- receive XMPP server version',
'uptime': '!uptime domain.tld -- receive XMPP server uptime', 'uptime': '!uptime domain.tld -- receive XMPP server uptime',
'contact': '!contact domain.tld -- receive XMPP server contact address info', 'contact': '!contact domain.tld -- receive XMPP server contact address info',
'xep': '!xep XEP Number -- recieve information about the specified XEP'} 'xep': '!xep XEP Number -- recieve information about the specified XEP'
}
self.possible_answers = { self.possible_answers = {
'1': 'I heard that, %s.', '1': 'I heard that, %s.',
'2': 'I am sorry for that %s.', '2': 'I am sorry for that %s.',
'3': '%s did you try turning it off and on again?'} '3': '%s did you try turning it off and on again?'
}
self.error_messages = { self.error_messages = {
'1': 'not reachable', '1': 'not reachable',
'2': 'not a valid target' '2': 'not a valid target'