Convert YCC module to V3.2
This commit is contained in:
parent
7e20368c10
commit
db7bb4ad3a
2 changed files with 31 additions and 28 deletions
4
modules/ycc.xml
Normal file
4
modules/ycc.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" ?>
|
||||||
|
<nemubotmodule name="ycc">
|
||||||
|
<message type="cmd" name="ycc" call="cmd_ycc" />
|
||||||
|
</nemubotmodule>
|
|
@ -7,7 +7,7 @@ import sys
|
||||||
|
|
||||||
from . import Tinyfier
|
from . import Tinyfier
|
||||||
|
|
||||||
nemubotversion = 3.0
|
nemubotversion = 3.2
|
||||||
|
|
||||||
def help_tiny ():
|
def help_tiny ():
|
||||||
"""Line inserted in the response to the command !help"""
|
"""Line inserted in the response to the command !help"""
|
||||||
|
@ -19,36 +19,35 @@ def help_full ():
|
||||||
def reload():
|
def reload():
|
||||||
imp.reload(Tinyfier)
|
imp.reload(Tinyfier)
|
||||||
|
|
||||||
def parseanswer(msg):
|
def cmd_ycc(data, msg):
|
||||||
global LAST_URLS
|
global LAST_URLS
|
||||||
if msg.cmd[0] == "ycc":
|
|
||||||
if len(msg.cmd) == 1:
|
if len(msg.cmd) == 1:
|
||||||
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:
|
||||||
url = LAST_URLS[msg.channel].pop()
|
url = LAST_URLS[msg.channel].pop()
|
||||||
t = Tinyfier.Tinyfier(url, msg)
|
t = Tinyfier.Tinyfier(url, msg)
|
||||||
t.start()
|
t.start()
|
||||||
else:
|
else:
|
||||||
msg.send_chn("%s: je n'ai pas d'autre URL reduire" % msg.nick)
|
msg.send_chn("%s: je n'ai pas d'autre URL reduire" % msg.nick)
|
||||||
else:
|
else:
|
||||||
if len(msg.cmd) < 6:
|
if len(msg.cmd) < 6:
|
||||||
for url in msg.cmd[1:]:
|
for url in msg.cmd[1:]:
|
||||||
t = Tinyfier.Tinyfier(url, msg)
|
t = Tinyfier.Tinyfier(url, msg)
|
||||||
t.start()
|
t.start()
|
||||||
else:
|
else:
|
||||||
msg.send_chn("%s: je ne peux pas réduire autant d'URL d'un seul coup." % msg.nick)
|
msg.send_chn("%s: je ne peux pas réduire autant d'URL d'un seul"
|
||||||
|
" coup." % msg.nick)
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
LAST_URLS = dict()
|
LAST_URLS = dict()
|
||||||
|
|
||||||
def parselisten (msg):
|
def parselisten(data, msg):
|
||||||
global LAST_URLS
|
global LAST_URLS
|
||||||
if re.match(".*(https?://|www\.)[^ ]+.*", msg.content) is not None:
|
if re.match(".*(https?://|www\.)[^ ]+.*", msg.content) is not None:
|
||||||
res = re.match(".*(((ht|f)tps?://|www\.)[^ ]+).*", msg.content)
|
res = re.match(".*(((ht|f)tps?://|www\.)[^ ]+).*", msg.content)
|
||||||
if msg.channel in LAST_URLS:
|
if msg.channel in LAST_URLS:
|
||||||
LAST_URLS[msg.channel].append(res.group(1))
|
LAST_URLS[msg.channel].append(res.group(1))
|
||||||
else:
|
else:
|
||||||
LAST_URLS[msg.channel] = list(res.group(1))
|
LAST_URLS[msg.channel] = list(res.group(1))
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue