summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authornico <nico@magicbroccoli.de>2018-10-06 13:16:27 +0200
committernico <nico@magicbroccoli.de>2018-10-06 13:16:27 +0200
commitd305f8adf3fa7c4f154f003bdf16ce42b1895ffd (patch)
tree43095e2fa414b9a92e4ca5081713402f7509df7c /classes
parent6bb9f1d5b87537ed6bccf0dd6efb7b80c6a81395 (diff)
small improvements
* leading 0 fix * validation function improvements * moved strings.py and misc files to /common/
Diffstat (limited to 'classes')
-rw-r--r--classes/strings.py54
-rw-r--r--classes/xep.py8
2 files changed, 4 insertions, 58 deletions
diff --git a/classes/strings.py b/classes/strings.py
deleted file mode 100644
index 6866a31..0000000
--- a/classes/strings.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# -*- 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
diff --git a/classes/xep.py b/classes/xep.py
index 9e4f61f..9e8414c 100644
--- a/classes/xep.py
+++ b/classes/xep.py
@@ -13,7 +13,7 @@ class XEPRequest:
self.message_type = msg['type']
self.muc_nick = msg['mucnick']
- self.reqxep = str(xepnumber)
+ self.reqxep = int(xepnumber)
self.xeplist = None
self.acceptedxeps = list()
@@ -33,14 +33,14 @@ class XEPRequest:
etag = head.headers['etag']
if local_etag == etag:
- with open("xeplist.xml", "r") as file:
+ with open("./common/xeplist.xml", "r") as file:
self.xeplist = ET.fromstring(file.read())
else:
r = s.get("https://xmpp.org/extensions/xeplist.xml")
r.encoding = 'utf-8'
local_etag = head.headers['etag']
- with open("xeplist.xml", "w") as file:
+ with open("./common/xeplist.xml", "w") as file:
file.write(r.content.decode())
self.xeplist = ET.fromstring(r.content.decode())
@@ -61,7 +61,7 @@ class XEPRequest:
result = list()
# if requested number is inside acceptedxeps continou
- if self.reqxep in self.acceptedxeps:
+ if str(self.reqxep) in self.acceptedxeps:
searchstring = ".//*[@accepted='true']/[number='%s']" % self.reqxep
for item in self.xeplist.findall(searchstring):