YCC module: dusting & anchors are correctly passed; fixes #59

This commit is contained in:
nemunaire 2014-07-25 16:38:01 +02:00
parent d16f57f8d5
commit 1a3912cc4f

View File

@ -23,11 +23,11 @@ LAST_URLS = dict()
def gen_response(res, msg, srv): def gen_response(res, msg, srv):
if res is None: if res is None:
return Response(msg.sender, "La situation est embarassante, il semblerait que YCC soit down :(", msg.channel) raise IRCException("la situation est embarassante, il semblerait que YCC soit down :(")
elif isinstance(res, str): elif isinstance(res, str):
return Response(msg.sender, "URL pour %s : %s" % (srv, res), msg.channel) return Response(msg.sender, "URL pour %s : %s" % (srv, res), msg.channel)
else: else:
return Response(msg.sender, "Mauvaise URL : %s" % srv, msg.channel) raise IRCException("mauvaise URL : %s" % srv)
def cmd_ycc(msg): def cmd_ycc(msg):
if len(msg.cmds) == 1: if len(msg.cmds) == 1:
@ -35,14 +35,16 @@ def cmd_ycc(msg):
if msg.channel in LAST_URLS and len(LAST_URLS[msg.channel]) > 0: if msg.channel in LAST_URLS and len(LAST_URLS[msg.channel]) > 0:
msg.cmds.append(LAST_URLS[msg.channel].pop()) msg.cmds.append(LAST_URLS[msg.channel].pop())
else: else:
return Response(msg.sender, "Je n'ai pas d'autre URL à réduire.", msg.channel) raise IRCException("je n'ai pas d'autre URL à réduire.")
if len(msg.cmds) > 5:
raise IRCException("je ne peux pas réduire autant d'URL d'un seul coup.")
if len(msg.cmds) < 6:
res = list() res = list()
for url in msg.cmds[1:]: for url in msg.cmds[1:]:
o = urlparse(url, "http") o = urlparse(url, "http")
if o.scheme != "": if o.scheme != "":
snd_url = "http://ycc.fr/redirection/create/" + quote(url, "/:%#@&=?") snd_url = "http://ycc.fr/redirection/create/" + quote(url, "/:%@&=?")
print_debug(snd_url) print_debug(snd_url)
raw = urlopen(snd_url, timeout=10) raw = urlopen(snd_url, timeout=10)
if o.netloc == "": if o.netloc == "":
@ -52,9 +54,6 @@ def cmd_ycc(msg):
else: else:
res.append(gen_response(False, msg, url)) res.append(gen_response(False, msg, url))
return res return res
else:
return Response(msg.sender, "je ne peux pas réduire autant d'URL "
"d'un seul coup.", msg.channel, nick=msg.nick)
def parselisten(msg): def parselisten(msg):
global LAST_URLS global LAST_URLS
@ -67,7 +66,7 @@ def parselisten(msg):
continue continue
if msg.channel not in LAST_URLS: if msg.channel not in LAST_URLS:
LAST_URLS[msg.channel] = list() LAST_URLS[msg.channel] = list()
LAST_URLS[msg.channel].append(o.geturl()) LAST_URLS[msg.channel].append(url)
except: except:
pass pass
return False return False