2018-10-01 23:17:09 +02:00
|
|
|
# -*- 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',
|
2018-10-03 23:24:36 +02:00
|
|
|
'contact': '!contact domain.tld -- receive XMPP server contact address info',
|
2018-11-09 19:56:09 +01:00
|
|
|
'xep': '!xep XEP Number -- recieve information about the specified XEP'
|
|
|
|
}
|
2018-10-01 23:17:09 +02:00
|
|
|
self.possible_answers = {
|
|
|
|
'1': 'I heard that, %s.',
|
|
|
|
'2': 'I am sorry for that %s.',
|
2018-11-09 19:56:09 +01:00
|
|
|
'3': '%s did you try turning it off and on again?'
|
|
|
|
}
|
2018-10-01 23:17:09 +02:00
|
|
|
self.error_messages = {
|
|
|
|
'1': 'not reachable',
|
|
|
|
'2': 'not a valid target'
|
|
|
|
}
|
|
|
|
self.keywords = {
|
2018-10-03 23:24:36 +02:00
|
|
|
"keywords": ["!help", "!uptime", "!version", "!contact", "!xep"],
|
|
|
|
"domain_keywords": ["!uptime", "!version", "!contact"],
|
|
|
|
"no_arg_keywords": ["!help"],
|
|
|
|
"number_keywords": ["!xep"]
|
2018-10-01 23:17:09 +02:00
|
|
|
}
|
|
|
|
|
2018-11-06 23:43:11 +01:00
|
|
|
def keys(self, key=""):
|
|
|
|
# if specific keyword in referenced return that
|
|
|
|
if key in self.keywords.keys():
|
|
|
|
return self.keywords[key]
|
2018-11-09 19:42:21 +01:00
|
|
|
|
2018-11-06 23:43:11 +01:00
|
|
|
# in any other case return the whole dict
|
2018-11-09 19:42:21 +01:00
|
|
|
return self.keywords["keywords"]
|
2018-10-01 23:17:09 +02:00
|
|
|
|
|
|
|
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
|