diff options
author | nico <nico.wellpott@uni-oldenburg.de> | 2018-10-01 23:17:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-01 23:17:09 +0200 |
commit | 294a728b0f3cf4c335923b7fbe6bd7e137a3fee3 (patch) | |
tree | 958cdb90022791b0782d2ec7c0108e1c1a304b30 /classes/strings.py | |
parent | b9a2e5adcda82bcf14e6a6ec3b504aec7908ec42 (diff) |
refactorization (#1)
* changed all lineendings to lf
* cleaned up main class
* refactor bot
* refactor bot functions
* moved functions.py to classes dir
* code comment changes
* changed code comment style
- removed unnecessary pass statement
+ added missing newline
* simplified function and return statements
Diffstat (limited to 'classes/strings.py')
-rw-r--r-- | classes/strings.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/classes/strings.py b/classes/strings.py new file mode 100644 index 0000000..ade0520 --- /dev/null +++ b/classes/strings.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +from random import randint + + +class StaticAnswers: + """ + collection of callable static/ semi-static strings + """ + def __init__(self, nick=""): + self.nickname = nick + self.helpfile = { + 'help': '!help -- display this text', + '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'} + 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?'} + self.error_messages = { + '1': 'not reachable', + '2': 'not a valid target' + } + self.keywords = { + "keywords": ["!help", "!uptime", "!version", "!contact"], + "no_arg_keywords": ["!help"] + } + + def keys(self, arg="", keyword='keywords'): + if arg == 'list': + try: + return self.keywords[keyword] + except KeyError: + return self.keywords['keywords'] + else: + return self.keywords + + def gen_help(self): + helpdoc = "\n".join(['%s' % value for (_, value) in self.helpfile.items()]) + return helpdoc + + def gen_answer(self): + possible_answers = self.possible_answers + return possible_answers[str(randint(1, possible_answers.__len__()))] % self.nickname + + def error(self,code): + try: + text = self.error_messages[str(code)] + except KeyError: + return 'unknown error' + return text |