summaryrefslogtreecommitdiffstats
path: root/common/strings.py
diff options
context:
space:
mode:
Diffstat (limited to 'common/strings.py')
-rw-r--r--common/strings.py69
1 files changed, 25 insertions, 44 deletions
diff --git a/common/strings.py b/common/strings.py
index 6f1b629..6941a6b 100644
--- a/common/strings.py
+++ b/common/strings.py
@@ -1,55 +1,36 @@
# -*- coding: utf-8 -*-
-from random import randint
+from random import choice
+import json
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',
- '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?'
- }
- self.error_messages = {
- '1': 'not reachable',
- '2': 'not a valid target'
- }
- self.keywords = {
- "keywords": ["!help", "!uptime", "!version", "!contact", "!xep"],
- "domain_keywords": ["!uptime", "!version", "!contact"],
- "no_arg_keywords": ["!help"],
- "number_keywords": ["!xep"]
- }
-
- def keys(self, key=""):
+ def __init__(self):
+ with open("./common/strings.json") as basefile:
+ self.strings = json.load(basefile)
+
+ self.helpfile = self.strings["help"]
+ self.keywords = self.strings["functions"]["keywords"]
+ self.replys = self.strings["functions"]["answers"]
+
+ def keys(self, key=None):
# if specific keyword in referenced return that
- if key in self.keywords.keys():
+ if key in self.keywords:
return self.keywords[key]
# in any other case return the whole dict
- return self.keywords["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
+ return self.keywords["all"]
+
+ def help_doc(self, key=None):
+ # if specific key is referenced return only that key
+ if key is not None:
+ return self.helpfile["help_advanced"][key]
+
+ # in any other case return basic dict
+ return self.helpfile["help_basic"]
+
+ def answers(self, nick=None):
+ # return pseudo random answer
+ return choice(self.replys) % nick