summaryrefslogtreecommitdiffstats
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
parent6bb9f1d5b87537ed6bccf0dd6efb7b80c6a81395 (diff)
small improvements
* leading 0 fix * validation function improvements * moved strings.py and misc files to /common/
-rw-r--r--classes/xep.py8
-rw-r--r--common/strings.py (renamed from classes/strings.py)0
-rw-r--r--main.py23
3 files changed, 15 insertions, 16 deletions
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):
diff --git a/classes/strings.py b/common/strings.py
index 6866a31..6866a31 100644
--- a/classes/strings.py
+++ b/common/strings.py
diff --git a/main.py b/main.py
index 2625728..cc0d282 100644
--- a/main.py
+++ b/main.py
@@ -17,7 +17,7 @@ import logging
from argparse import ArgumentParser
from slixmpp.exceptions import XMPPError
-from classes.strings import StaticAnswers
+from common.strings import StaticAnswers
from classes.functions import Version, LastActivity, ContactInfo, HandleError
from classes.xep import XEPRequest
@@ -46,7 +46,7 @@ class QueryBot(slixmpp.ClientXMPP):
for rooms in self.room.split(sep=","):
self.plugin['xep_0045'].join_muc(rooms, self.nick, wait=True)
- def validate_domain(self, wordlist, index):
+ def validate(self, wordlist, index):
"""
validation method to reduce malformed querys and unnecessary connection attempts
:param wordlist: words separated by " " from the message
@@ -71,8 +71,8 @@ class QueryBot(slixmpp.ClientXMPP):
# check if number keyword is used if true check if target is assignable
elif argument in StaticAnswers().keys(arg='list', keyword='number_keywords'):
try:
- target = wordlist[index + 1]
- return True
+ if wordlist[index + 1]:
+ return True
except IndexError:
# except an IndexError if target is not assignable
return False
@@ -124,27 +124,26 @@ class QueryBot(slixmpp.ClientXMPP):
# if so queue the keyword and the postion in the string
if x[1] == y:
# only add job to queue if domain is valid
- if self.validate_domain(words, x[0]):
+ if self.validate(words, x[0]):
queue.append({str(y): x[0]})
# queue
for job in queue:
- for key in job:
- keyword = key
- index = job[key]
+ for keyword in job:
+ index = job[keyword]
if keyword == '!help':
reply.append(StaticAnswers().gen_help())
continue
+ target = words[index + 1]
try:
- target = words[index + 1]
if keyword == '!uptime':
- last_activity = yield from self['xep_0012'].get_last_activity(target)
+ last_activity = yield from self['xep_0012'].get_last_activity(jid=target, cached=False)
reply.append(LastActivity(last_activity, msg, target).format_values())
elif keyword == "!version":
- version = yield from self['xep_0092'].get_version(target)
+ version = yield from self['xep_0092'].get_version(jid=target, cached=False)
reply.append(Version(version, msg, target).format_version())
elif keyword == "!contact":
@@ -155,7 +154,7 @@ class QueryBot(slixmpp.ClientXMPP):
reply.append(XEPRequest(msg, target).format())
except XMPPError as error:
- reply.append(HandleError(error, msg, key, target).build_report())
+ reply.append(HandleError(error, msg, keyword, target).build_report())
# remove None type from list and send all elements
if list(filter(None.__ne__, reply)) and reply: