From 86d058237b336516d2e5009072a4365b5bf7380b Mon Sep 17 00:00:00 2001 From: nico Date: Fri, 9 Nov 2018 19:56:09 +0100 Subject: elif amount reduction * reduced amount of unnecessary elif after return * some formatting --- common/misc.py | 30 ++++++++++++------------------ common/strings.py | 6 ++++-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/common/misc.py b/common/misc.py index abcc05e..86798b8 100755 --- a/common/misc.py +++ b/common/misc.py @@ -24,26 +24,20 @@ def validate(keyword, target): :param target: provided target :return: true if valid """ - # check if keyword is in the argument list - if keyword in StaticAnswers().keys(): - - # if keyword in domain_keywords list - 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 + # if keyword in domain_keywords list + if keyword in StaticAnswers().keys('domain_keywords'): + # if target is a domain / email return True + if validators.domain(target) or 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 + # 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 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 return False diff --git a/common/strings.py b/common/strings.py index 7a10471..6f1b629 100644 --- a/common/strings.py +++ b/common/strings.py @@ -13,11 +13,13 @@ class StaticAnswers: 'version': '!version domain.tld -- receive XMPP server version', 'uptime': '!uptime domain.tld -- receive XMPP server uptime', '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 = { '1': 'I heard 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 = { '1': 'not reachable', '2': 'not a valid target' -- cgit v1.2.3-54-g00ecf