mirror of
https://github.com/mightyBroccoli/xmpp-chatbot.git
synced 2024-11-12 21:36:50 +01:00
825167b8aa
commit 91cf4b74105f69f16a80825581a0d2d34d15d155 Merge: 30ceaea 90b42ed Author: nico <nico.wellpott@uni-oldenburg.de> Date: Wed Oct 3 22:34:42 2018 +0200 Merge remote-tracking branch 'origin/xep' into xep commit 30ceaea56a77ed95deba30c4fe65e238ea5960ac Author: nico <nico.wellpott@uni-oldenburg.de> Date: Wed Oct 3 22:34:33 2018 +0200 Initial Version XEP query + added initial version of xep query class Init Implementation + added xep plugin to bot class * reworked validation function * updated .gitignore file + added xep plugin commit 90b42edb9b8e92eba3bb67030d5f919b1e71d0bc Author: nico <nico.wellpott@uni-oldenburg.de> Date: Wed Oct 3 22:34:21 2018 +0200 * reworked validation function * updated .gitignore file + added xep plugin commit 25c78807731417867840d6fe4abf598e64aded28 Author: nico <nico@magicbroccoli.de> Date: Wed Oct 3 10:54:02 2018 +0200 Init Implementation + added xep plugin to bot class commit fe711f44d40671d927e9b946fb66679b297272c8 Author: nico <nico@magicbroccoli.de> Date: Tue Oct 2 21:20:08 2018 +0200 Initial Version XEP query + added initial version of xep query class
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
# -*- 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',
|
|
'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, 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
|