2012-06-16 20:52:04 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
|
|
|
import http.client
|
2012-07-03 02:13:10 +00:00
|
|
|
import imp
|
2012-06-16 20:52:04 +00:00
|
|
|
import re
|
|
|
|
import sys
|
2012-06-29 17:20:29 +00:00
|
|
|
|
2012-07-03 02:13:10 +00:00
|
|
|
from . import Tinyfier
|
2012-06-16 20:52:04 +00:00
|
|
|
|
|
|
|
nemubotversion = 3.0
|
|
|
|
|
|
|
|
def help_tiny ():
|
|
|
|
"""Line inserted in the response to the command !help"""
|
|
|
|
return "Gets YCC urls"
|
|
|
|
|
|
|
|
def help_full ():
|
2012-07-03 02:13:10 +00:00
|
|
|
return "!ycc [<url>]: with an argument, reduce the given <url> thanks to ycc.fr; without argument, reduce the last URL said on the current channel."
|
2012-06-16 20:52:04 +00:00
|
|
|
|
2012-07-03 02:13:10 +00:00
|
|
|
def reload():
|
|
|
|
imp.reload(Tinyfier)
|
2012-06-16 20:52:04 +00:00
|
|
|
|
|
|
|
def parseanswer(msg):
|
|
|
|
global LAST_URLS
|
|
|
|
if msg.cmd[0] == "ycc":
|
|
|
|
if len(msg.cmd) == 1:
|
|
|
|
if msg.channel in LAST_URLS and len(LAST_URLS[msg.channel]) > 0:
|
|
|
|
url = LAST_URLS[msg.channel].pop()
|
2012-07-03 02:13:10 +00:00
|
|
|
t = Tinyfier.Tinyfier(url, msg)
|
2012-06-16 20:52:04 +00:00
|
|
|
t.start()
|
|
|
|
else:
|
2012-07-23 10:07:26 +00:00
|
|
|
msg.send_chn("%s: je n'ai pas d'autre URL reduire" % msg.nick)
|
2012-06-16 20:52:04 +00:00
|
|
|
else:
|
|
|
|
if len(msg.cmd) < 6:
|
|
|
|
for url in msg.cmd[1:]:
|
2012-07-03 02:13:10 +00:00
|
|
|
t = Tinyfier.Tinyfier(url, msg)
|
2012-06-16 20:52:04 +00:00
|
|
|
t.start()
|
|
|
|
else:
|
2012-07-23 10:07:26 +00:00
|
|
|
msg.send_chn("%s: je ne peux pas réduire autant d'URL d'un seul coup." % msg.nick)
|
2012-06-16 20:52:04 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
LAST_URLS = dict()
|
|
|
|
|
|
|
|
def parselisten (msg):
|
|
|
|
global LAST_URLS
|
|
|
|
if re.match(".*(https?://|www\.)[^ ]+.*", msg.content) is not None:
|
|
|
|
res = re.match(".*(((ht|f)tps?://|www\.)[^ ]+).*", msg.content)
|
|
|
|
if msg.channel in LAST_URLS:
|
|
|
|
LAST_URLS[msg.channel].append(res.group(1))
|
|
|
|
else:
|
|
|
|
LAST_URLS[msg.channel] = list(res.group(1))
|
|
|
|
return True
|
|
|
|
return False
|