Replace IRCException by IMException, as nemubot is not only built for IRC
This commit is contained in:
parent
ac33ceb579
commit
8b4f08c5bd
40 changed files with 183 additions and 188 deletions
|
|
@ -1,5 +1,3 @@
|
|||
# coding=utf-8
|
||||
|
||||
# Nemubot is a smart and modulable IM bot.
|
||||
# Copyright (C) 2012-2015 Mercier Pierre-Olivier
|
||||
#
|
||||
|
|
@ -16,20 +14,21 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class IRCException(Exception):
|
||||
class IMException(Exception):
|
||||
|
||||
|
||||
def __init__(self, message, personnal=True):
|
||||
super(IRCException, self).__init__(message)
|
||||
self.message = message
|
||||
super(IMException, self).__init__(message)
|
||||
self.personnal = personnal
|
||||
|
||||
|
||||
def fill_response(self, msg):
|
||||
if self.personnal:
|
||||
from nemubot.message import DirectAsk
|
||||
return DirectAsk(msg.frm, self.message,
|
||||
return DirectAsk(msg.frm, *self.args,
|
||||
server=msg.server, to=msg.to_response)
|
||||
|
||||
else:
|
||||
from nemubot.message import Text
|
||||
return Text(self.message,
|
||||
return Text(*self.args,
|
||||
server=msg.server, to=msg.to_response)
|
||||
|
|
@ -57,12 +57,12 @@ class Abstract:
|
|||
def run(self, data1, *args):
|
||||
"""Run the hook"""
|
||||
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.exception import IMException
|
||||
self.times -= 1
|
||||
|
||||
try:
|
||||
ret = call_game(self.call, data1, self.data, *args)
|
||||
except IRCException as e:
|
||||
except IMException as e:
|
||||
ret = e.fill_response(data1)
|
||||
finally:
|
||||
if self.times == 0:
|
||||
|
|
|
|||
|
|
@ -110,8 +110,8 @@ class Feed:
|
|||
elif self.feed.tagName == "feed":
|
||||
self._parse_atom_feed()
|
||||
else:
|
||||
from nemubot.exception import IRCException
|
||||
raise IRCException("This is not a valid Atom or RSS feed")
|
||||
from nemubot.exception import IMException
|
||||
raise IMException("This is not a valid Atom or RSS feed")
|
||||
|
||||
|
||||
def _parse_atom_feed(self):
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
from urllib.parse import urlparse, urlsplit, urlunsplit
|
||||
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.exception import IMException
|
||||
|
||||
|
||||
def isURL(url):
|
||||
|
|
@ -100,7 +100,7 @@ def getURLContent(url, body=None, timeout=7, header=None):
|
|||
elif o.scheme is None or o.scheme == "":
|
||||
conn = http.client.HTTPConnection(**kwargs)
|
||||
else:
|
||||
raise IRCException("Invalid URL")
|
||||
raise IMException("Invalid URL")
|
||||
|
||||
from nemubot import __version__
|
||||
if header is None:
|
||||
|
|
@ -121,7 +121,7 @@ def getURLContent(url, body=None, timeout=7, header=None):
|
|||
body,
|
||||
header)
|
||||
except OSError as e:
|
||||
raise IRCException(e.strerror)
|
||||
raise IMException(e.strerror)
|
||||
|
||||
try:
|
||||
res = conn.getresponse()
|
||||
|
|
@ -129,7 +129,7 @@ def getURLContent(url, body=None, timeout=7, header=None):
|
|||
cntype = res.getheader("Content-Type")
|
||||
|
||||
if size > 524288 or (cntype is not None and cntype[:4] != "text" and cntype[:4] != "appl"):
|
||||
raise IRCException("Content too large to be retrieved")
|
||||
raise IMException("Content too large to be retrieved")
|
||||
|
||||
data = res.read(size)
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ def getURLContent(url, body=None, timeout=7, header=None):
|
|||
else:
|
||||
charset = cha[0]
|
||||
except http.client.BadStatusLine:
|
||||
raise IRCException("Invalid HTTP response")
|
||||
raise IMException("Invalid HTTP response")
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ def getURLContent(url, body=None, timeout=7, header=None):
|
|||
res.getheader("Location") != url):
|
||||
return getURLContent(res.getheader("Location"), timeout=timeout)
|
||||
else:
|
||||
raise IRCException("A HTTP error occurs: %d - %s" %
|
||||
raise IMException("A HTTP error occurs: %d - %s" %
|
||||
(res.status, http.client.responses[res.status]))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue