mirror of
https://github.com/mightyBroccoli/xmpp-chatbot.git
synced 2024-12-04 22:33:36 +01:00
* corrected CamelCase
* corrected logging.INFO to .info * small changes to HandleError class
This commit is contained in:
parent
0c313565f2
commit
d7fc664d3b
3 changed files with 9 additions and 9 deletions
|
@ -1,8 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import defusedxml.ElementTree as et
|
import defusedxml.ElementTree as Et
|
||||||
|
|
||||||
|
|
||||||
class XEPRequest:
|
class XEPRequest:
|
||||||
|
@ -36,12 +35,12 @@ class XEPRequest:
|
||||||
# compare etag with local_etag if they match up no request is made
|
# compare etag with local_etag if they match up no request is made
|
||||||
if local_etag == etag:
|
if local_etag == etag:
|
||||||
with open("./common/xeplist.xml", "r") as file:
|
with open("./common/xeplist.xml", "r") as file:
|
||||||
self.xeplist = et.fromstring(file.read())
|
self.xeplist = Et.fromstring(file.read())
|
||||||
|
|
||||||
# if the connection is not possible use cached xml if present
|
# if the connection is not possible use cached xml if present
|
||||||
elif os.path.isfile("./common/xeplist.xml") and head.status_code != 200:
|
elif os.path.isfile("./common/xeplist.xml") and head.status_code != 200:
|
||||||
with open("./common/xeplist.xml", "r") as file:
|
with open("./common/xeplist.xml", "r") as file:
|
||||||
self.xeplist = et.fromstring(file.read())
|
self.xeplist = Et.fromstring(file.read())
|
||||||
|
|
||||||
# in any other case request the latest xml
|
# in any other case request the latest xml
|
||||||
else:
|
else:
|
||||||
|
@ -51,7 +50,7 @@ class XEPRequest:
|
||||||
|
|
||||||
with open("./common/xeplist.xml", "w") as file:
|
with open("./common/xeplist.xml", "w") as file:
|
||||||
file.write(r.content.decode())
|
file.write(r.content.decode())
|
||||||
self.xeplist = et.fromstring(r.content.decode())
|
self.xeplist = Et.fromstring(r.content.decode())
|
||||||
|
|
||||||
with open('./common/.etag', 'w') as string:
|
with open('./common/.etag', 'w') as string:
|
||||||
string.write(local_etag)
|
string.write(local_etag)
|
||||||
|
|
|
@ -57,13 +57,13 @@ class HandleError:
|
||||||
"""
|
"""
|
||||||
def __init__(self, error, key, target):
|
def __init__(self, error, key, target):
|
||||||
# init all necessary variables
|
# init all necessary variables
|
||||||
self.error = error
|
self.text = error.text
|
||||||
|
self.condition = error.condition
|
||||||
self.key = key
|
self.key = key
|
||||||
self.target = target
|
self.target = target
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
# return the formatted result string to the user
|
# return the formatted result string to the user
|
||||||
condition = self.error.condition
|
text = "%s, %s resulted in: %s" % (self.text, self.key, self.condition)
|
||||||
text = "There was an error requesting %s's %s : %s" % (self.target, self.key, condition)
|
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
3
main.py
3
main.py
|
@ -60,6 +60,7 @@ class QueryBot(slixmpp.ClientXMPP):
|
||||||
# If a room password is needed, use: password=the_room_password
|
# If a room password is needed, use: password=the_room_password
|
||||||
if self.room:
|
if self.room:
|
||||||
for rooms in self.room.split(sep=","):
|
for rooms in self.room.split(sep=","):
|
||||||
|
logging.debug("joining: %s" % rooms)
|
||||||
self.plugin['xep_0045'].join_muc(rooms, self.nick, wait=True)
|
self.plugin['xep_0045'].join_muc(rooms, self.nick, wait=True)
|
||||||
|
|
||||||
async def message(self, msg):
|
async def message(self, msg):
|
||||||
|
@ -106,7 +107,7 @@ class QueryBot(slixmpp.ClientXMPP):
|
||||||
query = await self['xep_0030'].get_info(jid=target, cached=False)
|
query = await self['xep_0030'].get_info(jid=target, cached=False)
|
||||||
|
|
||||||
except XMPPError as error:
|
except XMPPError as error:
|
||||||
logging.INFO(misc.HandleError(error, keyword, target).report())
|
logging.info(misc.HandleError(error, keyword, target).report())
|
||||||
data['reply'].append(misc.HandleError(error, keyword, target).report())
|
data['reply'].append(misc.HandleError(error, keyword, target).report())
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue