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
|
|
@ -5,7 +5,7 @@
|
|||
import logging
|
||||
import re
|
||||
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.exception import IMException
|
||||
from nemubot.hooks import hook
|
||||
|
||||
from more import Response
|
||||
|
|
@ -43,13 +43,13 @@ def load(context):
|
|||
help_usage={"URL": "Display the title of the given URL"})
|
||||
def cmd_title(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate the URL to visit.")
|
||||
raise IMException("Indicate the URL to visit.")
|
||||
|
||||
url = " ".join(msg.args)
|
||||
res = re.search("<title>(.*?)</title>", page.fetch(" ".join(msg.args)), re.DOTALL)
|
||||
|
||||
if res is None:
|
||||
raise IRCException("The page %s has no title" % url)
|
||||
raise IMException("The page %s has no title" % url)
|
||||
else:
|
||||
return Response("%s: %s" % (url, res.group(1).replace("\n", " ")), channel=msg.channel)
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ def cmd_title(msg):
|
|||
help_usage={"URL": "Display HTTP headers of the given URL"})
|
||||
def cmd_curly(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate the URL to visit.")
|
||||
raise IMException("Indicate the URL to visit.")
|
||||
|
||||
url = " ".join(msg.args)
|
||||
version, status, reason, headers = page.headers(url)
|
||||
|
|
@ -72,7 +72,7 @@ def cmd_curly(msg):
|
|||
help_usage={"URL": "Display raw HTTP body of the given URL"})
|
||||
def cmd_curl(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate the URL to visit.")
|
||||
raise IMException("Indicate the URL to visit.")
|
||||
|
||||
res = Response(channel=msg.channel)
|
||||
for m in page.fetch(" ".join(msg.args)).split("\n"):
|
||||
|
|
@ -85,7 +85,7 @@ def cmd_curl(msg):
|
|||
help_usage={"URL": "Display and format HTTP content of the given URL"})
|
||||
def cmd_w3m(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate the URL to visit.")
|
||||
raise IMException("Indicate the URL to visit.")
|
||||
res = Response(channel=msg.channel)
|
||||
for line in page.render(" ".join(msg.args)).split("\n"):
|
||||
res.append_message(line)
|
||||
|
|
@ -97,7 +97,7 @@ def cmd_w3m(msg):
|
|||
help_usage={"URL": "Display redirections steps for the given URL"})
|
||||
def cmd_traceurl(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate an URL to trace!")
|
||||
raise IMException("Indicate an URL to trace!")
|
||||
|
||||
res = list()
|
||||
for url in msg.args[:4]:
|
||||
|
|
@ -114,7 +114,7 @@ def cmd_traceurl(msg):
|
|||
help_usage={"DOMAIN": "Check if a DOMAIN is up"})
|
||||
def cmd_isup(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate an domain name to check!")
|
||||
raise IMException("Indicate an domain name to check!")
|
||||
|
||||
res = list()
|
||||
for url in msg.args[:4]:
|
||||
|
|
@ -131,7 +131,7 @@ def cmd_isup(msg):
|
|||
help_usage={"URL": "Do W3C HTML validation on the given URL"})
|
||||
def cmd_w3c(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate an URL to validate!")
|
||||
raise IMException("Indicate an URL to validate!")
|
||||
|
||||
headers, validator = w3c.validator(msg.args[0])
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ def cmd_w3c(msg):
|
|||
help_usage={"URL": "Watch the given domain and alert when it availability status changes"})
|
||||
def cmd_watch(msg, diffType="diff"):
|
||||
if not len(msg.args):
|
||||
raise IRCException("indicate an URL to watch!")
|
||||
raise IMException("indicate an URL to watch!")
|
||||
|
||||
return watchWebsite.add_site(msg.args[0], msg.frm, msg.channel, msg.server, diffType)
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ def cmd_listwatch(msg):
|
|||
help_usage={"URL": "Unwatch the given URL"})
|
||||
def cmd_unwatch(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("which URL should I stop watching?")
|
||||
raise IMException("which URL should I stop watching?")
|
||||
|
||||
for arg in msg.args:
|
||||
return watchWebsite.del_site(arg, msg.frm, msg.channel, msg.frm_owner)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import tempfile
|
|||
import urllib
|
||||
|
||||
from nemubot import __version__
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.exception import IMException
|
||||
from nemubot.tools import web
|
||||
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ def headers(url):
|
|||
|
||||
o = urllib.parse.urlparse(web.getNormalizedURL(url), "http")
|
||||
if o.netloc == "":
|
||||
raise IRCException("invalid URL")
|
||||
raise IMException("invalid URL")
|
||||
if o.scheme == "http":
|
||||
conn = http.client.HTTPConnection(o.hostname, port=o.port, timeout=5)
|
||||
else:
|
||||
|
|
@ -32,18 +32,18 @@ def headers(url):
|
|||
conn.request("HEAD", o.path, None, {"User-agent":
|
||||
"Nemubot v%s" % __version__})
|
||||
except ConnectionError as e:
|
||||
raise IRCException(e.strerror)
|
||||
raise IMException(e.strerror)
|
||||
except socket.timeout:
|
||||
raise IRCException("request timeout")
|
||||
raise IMException("request timeout")
|
||||
except socket.gaierror:
|
||||
print ("<tools.web> Unable to receive page %s from %s on %d."
|
||||
% (o.path, o.hostname, o.port if o.port is not None else 0))
|
||||
raise IRCException("an unexpected error occurs")
|
||||
raise IMException("an unexpected error occurs")
|
||||
|
||||
try:
|
||||
res = conn.getresponse()
|
||||
except http.client.BadStatusLine:
|
||||
raise IRCException("An error occurs")
|
||||
raise IMException("An error occurs")
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ def headers(url):
|
|||
|
||||
|
||||
def _onNoneDefault():
|
||||
raise IRCException("An error occurs when trying to access the page")
|
||||
raise IMException("An error occurs when trying to access the page")
|
||||
|
||||
|
||||
def fetch(url, onNone=_onNoneDefault):
|
||||
|
|
@ -71,11 +71,11 @@ def fetch(url, onNone=_onNoneDefault):
|
|||
else:
|
||||
return None
|
||||
except ConnectionError as e:
|
||||
raise IRCException(e.strerror)
|
||||
raise IMException(e.strerror)
|
||||
except socket.timeout:
|
||||
raise IRCException("The request timeout when trying to access the page")
|
||||
raise IMException("The request timeout when trying to access the page")
|
||||
except socket.error as e:
|
||||
raise IRCException(e.strerror)
|
||||
raise IMException(e.strerror)
|
||||
|
||||
|
||||
def _render(cnt):
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import json
|
|||
import urllib
|
||||
|
||||
from nemubot import __version__
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.exception import IMException
|
||||
from nemubot.tools.web import getNormalizedURL
|
||||
|
||||
def validator(url):
|
||||
|
|
@ -14,19 +14,19 @@ def validator(url):
|
|||
|
||||
o = urllib.parse.urlparse(getNormalizedURL(url), "http")
|
||||
if o.netloc == "":
|
||||
raise IRCException("Indicate a valid URL!")
|
||||
raise IMException("Indicate a valid URL!")
|
||||
|
||||
try:
|
||||
req = urllib.request.Request("http://validator.w3.org/check?uri=%s&output=json" % (urllib.parse.quote(o.geturl())), headers={ 'User-Agent' : "Nemubot v%s" % __version__})
|
||||
raw = urllib.request.urlopen(req, timeout=10)
|
||||
except urllib.error.HTTPError as e:
|
||||
raise IRCException("HTTP error occurs: %s %s" % (e.code, e.reason))
|
||||
raise IMException("HTTP error occurs: %s %s" % (e.code, e.reason))
|
||||
|
||||
headers = dict()
|
||||
for Hname, Hval in raw.getheaders():
|
||||
headers[Hname] = Hval
|
||||
|
||||
if "X-W3C-Validator-Status" not in headers or (headers["X-W3C-Validator-Status"] != "Valid" and headers["X-W3C-Validator-Status"] != "Invalid"):
|
||||
raise IRCException("Unexpected error on W3C servers" + (" (" + headers["X-W3C-Validator-Status"] + ")" if "X-W3C-Validator-Status" in headers else ""))
|
||||
raise IMException("Unexpected error on W3C servers" + (" (" + headers["X-W3C-Validator-Status"] + ")" if "X-W3C-Validator-Status" in headers else ""))
|
||||
|
||||
return headers, json.loads(raw.read().decode())
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import urllib.parse
|
|||
from urllib.parse import urlparse
|
||||
|
||||
from nemubot.event import ModuleEvent
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.exception import IMException
|
||||
from nemubot.tools.web import getNormalizedURL
|
||||
from nemubot.tools.xmlparser.node import ModuleState
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ def del_site(url, nick, channel, frm_owner):
|
|||
for a in site.getNodes("alert"):
|
||||
if a["channel"] == channel:
|
||||
# if not (nick == a["nick"] or frm_owner):
|
||||
# raise IRCException("you cannot unwatch this URL.")
|
||||
# raise IMException("you cannot unwatch this URL.")
|
||||
site.delChild(a)
|
||||
if not site.hasNode("alert"):
|
||||
del_event(site["_evt_id"])
|
||||
|
|
@ -69,7 +69,7 @@ def del_site(url, nick, channel, frm_owner):
|
|||
save()
|
||||
return Response("I don't watch this URL anymore.",
|
||||
channel=channel, nick=nick)
|
||||
raise IRCException("I didn't watch this URL!")
|
||||
raise IMException("I didn't watch this URL!")
|
||||
|
||||
|
||||
def add_site(url, nick, channel, server, diffType="diff"):
|
||||
|
|
@ -81,7 +81,7 @@ def add_site(url, nick, channel, server, diffType="diff"):
|
|||
|
||||
o = urlparse(getNormalizedURL(url), "http")
|
||||
if o.netloc == "":
|
||||
raise IRCException("sorry, I can't watch this URL :(")
|
||||
raise IMException("sorry, I can't watch this URL :(")
|
||||
|
||||
alert = ModuleState("alert")
|
||||
alert["nick"] = nick
|
||||
|
|
@ -219,5 +219,5 @@ def start_watching(site, offset=0):
|
|||
interval=site.getInt("time"),
|
||||
call=alert_change, call_data=site)
|
||||
site["_evt_id"] = add_event(evt)
|
||||
except IRCException:
|
||||
except IMException:
|
||||
logger.exception("Unable to watch %s", site["url"])
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import datetime
|
||||
import urllib
|
||||
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.exception import IMException
|
||||
from nemubot.tools.web import getJSON
|
||||
|
||||
from more import Response
|
||||
|
|
@ -80,14 +80,14 @@ def whois_entityformat(entity):
|
|||
|
||||
def cmd_whois(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indiquer un domaine ou une IP à whois !")
|
||||
raise IMException("Indiquer un domaine ou une IP à whois !")
|
||||
|
||||
dom = msg.args[0]
|
||||
|
||||
js = getJSON(URL_WHOIS % urllib.parse.quote(dom))
|
||||
|
||||
if "ErrorMessage" in js:
|
||||
raise IRCException(js["ErrorMessage"]["msg"])
|
||||
raise IMException(js["ErrorMessage"]["msg"])
|
||||
|
||||
whois = js["WhoisRecord"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue