Dusting modules

This commit is contained in:
nemunaire 2015-07-10 23:09:54 +02:00
parent 4bc8bc3c12
commit 4d51bc1fda
20 changed files with 147 additions and 147 deletions

View File

@ -30,11 +30,11 @@ def help_full():
def findName(msg):
if (len(msg.cmds) < 2 or msg.cmds[1].lower() == "moi" or
msg.cmds[1].lower() == "me"):
if (not len(msg.args) or msg.args[0].lower() == "moi" or
msg.args[0].lower() == "me"):
name = msg.nick.lower()
else:
name = msg.cmds[1].lower()
name = msg.args[0].lower()
matches = []

View File

@ -39,13 +39,13 @@ def help_full():
@hook("cmd_hook", "conjugaison")
def cmd_conjug(msg):
if len(msg.cmds) < 3:
if len(msg.args) < 2:
raise IRCException("donne moi un temps et un verbe, et je te donnerai "
"sa conjugaison!")
tens = ' '.join(msg.cmds[1:-1])
tens = ' '.join(msg.args[:-1])
verb = msg.cmds[-1]
verb = msg.args[-1]
conjug = get_conjug(verb, tens)

View File

@ -64,25 +64,25 @@ def cmd_we(msg):
@hook("cmd_hook", "start")
def start_countdown(msg):
"""!start /something/: launch a timer"""
if len(msg.cmds) < 2:
if len(msg.args) < 1:
raise IRCException("indique le nom d'un événement à chronométrer")
if msg.cmds[1] in context.data.index:
raise IRCException("%s existe déjà." % msg.cmds[1])
if msg.args[0] in context.data.index:
raise IRCException("%s existe déjà." % msg.args[0])
strnd = ModuleState("strend")
strnd["server"] = msg.server
strnd["channel"] = msg.channel
strnd["proprio"] = msg.nick
strnd["start"] = msg.date
strnd["name"] = msg.cmds[1]
strnd["name"] = msg.args[0]
context.data.addChild(strnd)
evt = ModuleEvent(call=fini, call_data=dict(strend=strnd))
if len(msg.cmds) > 2:
result1 = re.findall("([0-9]+)([smhdjwyaSMHDJWYA])?", msg.cmds[2])
result2 = re.match("(.*[^0-9])?([0-3]?[0-9])/([0-1]?[0-9])/((19|20)?[01239][0-9])", msg.cmds[2])
result3 = re.match("(.*[^0-9])?([0-2]?[0-9]):([0-5]?[0-9])(:([0-5]?[0-9]))?", msg.cmds[2])
if len(msg.args) > 1:
result1 = re.findall("([0-9]+)([smhdjwyaSMHDJWYA])?", msg.args[1])
result2 = re.match("(.*[^0-9])?([0-3]?[0-9])/([0-1]?[0-9])/((19|20)?[01239][0-9])", msg.args[1])
result3 = re.match("(.*[^0-9])?([0-2]?[0-9]):([0-5]?[0-9])(:([0-5]?[0-9]))?", msg.args[1])
if result2 is not None or result3 is not None:
try:
now = msg.date
@ -107,7 +107,7 @@ def start_countdown(msg):
strnd["_id"] = context.add_event(evt)
except:
context.data.delChild(strnd)
raise IRCException("Mauvais format de date pour l'événement %s. Il n'a pas été créé." % msg.cmds[1])
raise IRCException("Mauvais format de date pour l'événement %s. Il n'a pas été créé." % msg.args[0])
elif result1 is not None and len(result1) > 0:
strnd["end"] = msg.date
@ -132,39 +132,39 @@ def start_countdown(msg):
context.save()
if "end" in strnd:
return Response("%s commencé le %s et se terminera le %s." %
(msg.cmds[1], msg.date.strftime("%A %d %B %Y à %H:%M:%S"),
(msg.args[0], msg.date.strftime("%A %d %B %Y à %H:%M:%S"),
strnd.getDate("end").strftime("%A %d %B %Y à %H:%M:%S")),
nick=msg.frm)
else:
return Response("%s commencé le %s"% (msg.cmds[1],
return Response("%s commencé le %s"% (msg.args[0],
msg.date.strftime("%A %d %B %Y à %H:%M:%S")),
nick=msg.frm)
@hook("cmd_hook", "end")
@hook("cmd_hook", "forceend")
def end_countdown(msg):
if len(msg.cmds) < 2:
if len(msg.args) < 1:
raise IRCException("quel événement terminer ?")
if msg.cmds[1] in context.data.index:
if context.data.index[msg.cmds[1]]["proprio"] == msg.nick or (msg.cmds[0] == "forceend" and msg.frm_owner):
duration = countdown(msg.date - context.data.index[msg.cmds[1]].getDate("start"))
context.del_event(context.data.index[msg.cmds[1]]["_id"])
context.data.delChild(context.data.index[msg.cmds[1]])
if msg.args[0] in context.data.index:
if context.data.index[msg.args[0]]["proprio"] == msg.nick or (msg.cmd == "forceend" and msg.frm_owner):
duration = countdown(msg.date - context.data.index[msg.args[0]].getDate("start"))
context.del_event(context.data.index[msg.args[0]]["_id"])
context.data.delChild(context.data.index[msg.args[0]])
context.save()
return Response("%s a duré %s." % (msg.cmds[1], duration),
return Response("%s a duré %s." % (msg.args[0], duration),
channel=msg.channel, nick=msg.nick)
else:
raise IRCException("Vous ne pouvez pas terminer le compteur %s, créé par %s." % (msg.cmds[1], context.data.index[msg.cmds[1]]["proprio"]))
raise IRCException("Vous ne pouvez pas terminer le compteur %s, créé par %s." % (msg.args[0], context.data.index[msg.args[0]]["proprio"]))
else:
return Response("%s n'est pas un compteur connu."% (msg.cmds[1]), channel=msg.channel, nick=msg.nick)
return Response("%s n'est pas un compteur connu."% (msg.args[0]), channel=msg.channel, nick=msg.nick)
@hook("cmd_hook", "eventslist")
def liste(msg):
"""!eventslist: gets list of timer"""
if len(msg.cmds) > 1:
if len(msg.args):
res = list()
for user in msg.cmds[1:]:
for user in msg.args:
cmptr = [x["name"] for x in context.data.index.values() if x["proprio"] == user]
if len(cmptr) > 0:
res.append("Compteurs créés par %s : %s" % (user, ", ".join(cmptr)))
@ -176,20 +176,20 @@ def liste(msg):
@hook("cmd_default")
def parseanswer(msg):
if msg.cmds[0] in context.data.index:
if msg.cmd in context.data.index:
res = Response(channel=msg.channel)
# Avoid message starting by ! which can be interpreted as command by other bots
if msg.cmds[0][0] == "!":
if msg.cmd[0] == "!":
res.nick = msg.nick
if context.data.index[msg.cmds[0]].name == "strend":
if context.data.index[msg.cmds[0]].hasAttribute("end"):
res.append_message("%s commencé il y a %s et se terminera dans %s." % (msg.cmds[0], countdown(msg.date - context.data.index[msg.cmds[0]].getDate("start")), countdown(context.data.index[msg.cmds[0]].getDate("end") - msg.date)))
if context.data.index[msg.cmd].name == "strend":
if context.data.index[msg.cmd].hasAttribute("end"):
res.append_message("%s commencé il y a %s et se terminera dans %s." % (msg.cmd, countdown(msg.date - context.data.index[msg.cmd].getDate("start")), countdown(context.data.index[msg.cmd].getDate("end") - msg.date)))
else:
res.append_message("%s commencé il y a %s." % (msg.cmds[0], countdown(msg.date - context.data.index[msg.cmds[0]].getDate("start"))))
res.append_message("%s commencé il y a %s." % (msg.cmd, countdown(msg.date - context.data.index[msg.cmd].getDate("start"))))
else:
res.append_message(countdown_format(context.data.index[msg.cmds[0]].getDate("start"), context.data.index[msg.cmds[0]]["msg_before"], context.data.index[msg.cmds[0]]["msg_after"]))
res.append_message(countdown_format(context.data.index[msg.cmd].getDate("start"), context.data.index[msg.cmd]["msg_before"], context.data.index[msg.cmd]["msg_after"]))
return res
RGXP_ask = re.compile(r"^.*((create|new)\s+(a|an|a\s*new|an\s*other)?\s*(events?|commande?)|(nouvel(le)?|ajoute|cr[ée]{1,3})\s+(un)?\s*([eé]v[ée]nements?|commande?)).*$", re.I)

View File

@ -71,10 +71,10 @@ def find_movies(title):
@hook("cmd_hook", "imdb")
def cmd_imdb(msg):
"""View movie details with !imdb <title>"""
if len(msg.cmds) < 2:
if not len(msg.args):
raise IRCException("precise a movie/serie title!")
title = ' '.join(msg.cmds[1:])
title = ' '.join(msg.args)
if re.match("^tt[0-9]{7}$", title) is not None:
data = get_movie(imdbid=title)
@ -100,8 +100,10 @@ def cmd_imdb(msg):
@hook("cmd_hook", "imdbs")
def cmd_search(msg):
"""!imdbs <approximative title> to search a movie title"""
if not len(msg.args):
raise IRCException("precise a movie/serie title!")
data = find_movies(' '.join(msg.cmds[1:]))
data = find_movies(' '.join(msg.args))
movies = list()
for m in data['Search']:

View File

@ -43,18 +43,18 @@ def getJsonKeys(data):
@hook("cmd_hook", "json")
def get_json_info(msg):
if len(msg.cmds) < 2:
if not len(msg.args):
raise IRCException("Please specify a url and a list of JSON keys.")
request_data = web.getURLContent(msg.cmds[1].replace(' ', "%20"))
request_data = web.getURLContent(msg.args[0].replace(' ', "%20"))
if not request_data:
raise IRCException("Please specify a valid url.")
json_data = json.loads(request_data)
if len(msg.cmds) == 2:
if len(msg.args) == 1:
raise IRCException("Please specify the keys to return (%s)" % ", ".join(getJsonKeys(json_data)))
tags = ','.join(msg.cmds[2:]).split(',')
tags = ','.join(msg.args[1:]).split(',')
response = getRequestedTags(tags, json_data)
return Response(response, channel=msg.channel, nomore="No more content", count=" (%d more lines)")

View File

@ -14,10 +14,10 @@ def help_full():
@hook("cmd_hook", "laposte")
def get_tracking_info(msg):
if len(msg.cmds) < 2:
if not len(msg.args):
raise IRCException("Renseignez un identifiant d'envoi,")
data = urllib.parse.urlencode({'id': msg.cmds[1]})
data = urllib.parse.urlencode({'id': msg.args[0]})
laposte_baseurl = "http://www.part.csuivi.courrier.laposte.fr/suivi/index"
laposte_data = urllib.request.urlopen(laposte_baseurl, data.encode('utf-8'))
@ -42,4 +42,3 @@ def get_tracking_info(msg):
return Response("Le courrier de type \x02%s\x0F : \x02%s\x0F est actuellement \x02%s\x0F dans la zone \x02%s\x0F (Mis à jour le \x02%s\x0F)." % (poste_type.lower(), poste_id.strip(), poste_status.lower(), poste_location, poste_date), msg.channel)
return Response("L'identifiant recherché semble incorrect, merci de vérifier son exactitude.", msg.channel)

View File

@ -23,15 +23,15 @@ RGXP_s = re.compile(b'\x1b\\[[0-9]+m')
def cmd_man(msg):
args = ["man"]
num = None
if len(msg.cmds) == 2:
args.append(msg.cmds[1])
elif len(msg.cmds) >= 3:
if len(msg.args) == 1:
args.append(msg.args[0])
elif len(msg.args) >= 2:
try:
num = int(msg.cmds[1])
num = int(msg.args[0])
args.append("%d" % num)
args.append(msg.cmds[2])
args.append(msg.args[1])
except ValueError:
args.append(msg.cmds[1])
args.append(msg.args[0])
os.unsetenv("LANG")
res = Response(channel=msg.channel)
@ -45,16 +45,16 @@ def cmd_man(msg):
if len(res.messages) <= 0:
if num is not None:
res.append_message("There is no entry %s in section %d." %
(msg.cmds[1], num))
(msg.args[0], num))
else:
res.append_message("There is no man page for %s." % msg.cmds[1])
res.append_message("There is no man page for %s." % msg.args[0])
return res
@hook("cmd_hook", "man")
def cmd_whatis(msg):
args = ["whatis", " ".join(msg.cmds[1:])]
args = ["whatis", " ".join(msg.args)]
res = Response(channel=msg.channel)
with subprocess.Popen(args,
@ -67,8 +67,8 @@ def cmd_whatis(msg):
if len(res.messages) <= 0:
if num is not None:
res.append_message("There is no entry %s in section %d." %
(msg.cmds[1], num))
(msg.args[0], num))
else:
res.append_message("There is no man page for %s." % msg.cmds[1])
res.append_message("There is no man page for %s." % msg.args[0])
return res

View File

@ -139,27 +139,27 @@ def search(site, term, ssl=False):
@hook("cmd_hook", "mediawiki")
def cmd_mediawiki(msg):
"""Read an article on a MediaWiki"""
if len(msg.cmds) < 3:
if len(msg.args) < 2:
raise IRCException("indicate a domain and a term to search")
site = msg.cmds[1]
site = msg.args[0]
ns = get_namespaces(site)
return Response(get_page(site, " ".join(msg.cmds[2:])),
line_treat=lambda line: irc_format(parse_wikitext(msg.cmds[1], line, ns)),
return Response(get_page(site, " ".join(msg.args[1:])),
line_treat=lambda line: irc_format(parse_wikitext(msg.args[0], line, ns)),
channel=msg.receivers)
@hook("cmd_hook", "search_mediawiki")
def cmd_srchmediawiki(msg):
"""Search an article on a MediaWiki"""
if len(msg.cmds) < 3:
if len(msg.args) < 2:
raise IRCException("indicate a domain and a term to search")
res = Response(channel=msg.receivers, nomore="No more results", count=" (%d more results)")
for r in search(msg.cmds[1], " ".join(msg.cmds[2:])):
for r in search(msg.args[0], " ".join(msg.args[1:])):
res.append_message("%s: %s" % r)
return res
@ -167,13 +167,13 @@ def cmd_srchmediawiki(msg):
@hook("cmd_hook", "wikipedia")
def cmd_wikipedia(msg):
if len(msg.cmds) < 3:
if len(msg.args) < 2:
raise IRCException("indicate a lang and a term to search")
site = msg.cmds[1] + ".wikipedia.org"
site = msg.args[0] + ".wikipedia.org"
ns = get_namespaces(site)
return Response(get_page(site, " ".join(msg.cmds[2:])),
return Response(get_page(site, " ".join(msg.args[1:])),
line_treat=lambda line: irc_format(parse_wikitext(site, line, ns)),
channel=msg.receivers)

View File

@ -39,10 +39,10 @@ def help_full():
@hook("cmd_hook", "curly")
def cmd_curly(msg):
if len(msg.cmds) < 2:
if not len(msg.args):
raise IRCException("Indicate the URL to visit.")
url = " ".join(msg.cmds[1:])
url = " ".join(msg.args)
version, status, reason, headers = page.headers(url)
return Response("Entêtes de la page %s : HTTP/%s, statut : %d %s ; headers : %s" % (url, version, status, reason, ", ".join(["\x03\x02" + h + "\x03\x02: " + v for h, v in headers])), channel=msg.channel)
@ -50,20 +50,20 @@ def cmd_curly(msg):
@hook("cmd_hook", "curl")
def cmd_curl(msg):
if len(msg.cmds) < 2:
if not len(msg.args):
raise IRCException("Indicate the URL to visit.")
res = Response(channel=msg.channel)
for m in page.fetch(" ".join(msg.cmds[1:])).split("\n"):
for m in page.fetch(" ".join(msg.args)).split("\n"):
res.append_message(m)
return res
@hook("cmd_hook", "w3m")
def cmd_w3m(msg):
if len(msg.cmds) > 1:
if len(msg.args):
res = Response(channel=msg.channel)
for line in page.render(" ".join(msg.cmds[1:])).split("\n"):
for line in page.render(" ".join(msg.args)).split("\n"):
res.append_message(line)
return res
else:
@ -72,9 +72,9 @@ def cmd_w3m(msg):
@hook("cmd_hook", "traceurl")
def cmd_traceurl(msg):
if 1 < len(msg.cmds) < 6:
if 1 < len(msg.args) < 5:
res = list()
for url in msg.cmds[1:]:
for url in msg.args:
trace = page.traceURL(url)
res.append(Response(trace, channel=msg.channel, title="TraceURL"))
return res
@ -84,9 +84,9 @@ def cmd_traceurl(msg):
@hook("cmd_hook", "isup")
def cmd_isup(msg):
if 1 < len(msg.cmds) < 6:
if 1 < len(msg.args) < 5:
res = list()
for url in msg.cmds[1:]:
for url in msg.args:
rep = isup.isup(url)
if rep:
res.append(Response("%s is up (response time: %ss)" % (url, rep), channel=msg.channel))
@ -99,10 +99,10 @@ def cmd_isup(msg):
@hook("cmd_hook", "w3c")
def cmd_w3c(msg):
if len(msg.cmds) < 2:
if not len(msg.args):
raise IRCException("Indicate an URL to validate!")
headers, validator = w3c.validator(msg.cmds[1])
headers, validator = w3c.validator(msg.args[0])
res = Response(channel=msg.channel, nomore="No more error")
@ -121,15 +121,15 @@ def cmd_w3c(msg):
@hook("cmd_hook", "watch", data="diff")
@hook("cmd_hook", "updown", data="updown")
def cmd_watch(msg, diffType="diff"):
if len(msg.cmds) <= 1:
if not len(msg.args):
raise IRCException("indicate an URL to watch!")
return watchWebsite.add_site(msg.cmds[1], msg.frm, msg.channel, msg.server, diffType)
return watchWebsite.add_site(msg.args[0], msg.frm, msg.channel, msg.server, diffType)
@hook("cmd_hook", "unwatch")
def cmd_unwatch(msg):
if len(msg.cmds) <= 1:
if not len(msg.args):
raise IRCException("which URL should I stop watching?")
return watchWebsite.del_site(msg.cmds[1], msg.frm, msg.channel, msg.frm_owner)
return watchWebsite.del_site(msg.args[0], msg.frm, msg.channel, msg.frm_owner)

View File

@ -77,10 +77,10 @@ def whois_entityformat(entity):
def cmd_whois(msg):
if len(msg.cmds) < 2:
if not len(msg.args):
raise IRCException("Indiquer un domaine ou une IP à whois !")
dom = msg.cmds[1]
dom = msg.args[0]
js = getJSON(URL_WHOIS % urllib.parse.quote(dom))

View File

@ -17,12 +17,12 @@ def help_full ():
@hook("cmd_hook", "ratp")
def ask_ratp(msg):
"""Hook entry from !ratp"""
if len(msg.cmds) >= 4:
transport = msg.cmds[1]
line = msg.cmds[2]
station = msg.cmds[3]
if len(msg.cmds) == 5:
times = ratp.getNextStopsAtStation(transport, line, station, msg.cmds[4])
if len(msg.args) >= 3:
transport = msg.args[0]
line = msg.args[1]
station = msg.args[2]
if len(msg.args) == 4:
times = ratp.getNextStopsAtStation(transport, line, station, msg.args[3])
else:
times = ratp.getNextStopsAtStation(transport, line, station)
@ -34,8 +34,8 @@ def ask_ratp(msg):
title="Prochains passages du %s ligne %s à l'arrêt %s" % (transport, line, stationname),
channel=msg.channel)
elif len(msg.cmds) == 3:
stations = ratp.getAllStations(msg.cmds[1], msg.cmds[2])
elif len(msg.args) == 2:
stations = ratp.getAllStations(msg.args[0], msg.args[1])
if len(stations) == 0:
raise IRCException("aucune station trouvée.")
@ -46,9 +46,9 @@ def ask_ratp(msg):
@hook("cmd_hook", "ratp_alert")
def ratp_alert(msg):
if len(msg.cmds) == 3:
transport = msg.cmds[1]
cause = msg.cmds[2]
if len(msg.args) == 2:
transport = msg.args[0]
cause = msg.args[1]
incidents = ratp.getDisturbance(cause, transport)
return Response(incidents, channel=msg.channel, nomore="No more incidents", count=" (%d more incidents)")
else:

View File

@ -22,14 +22,14 @@ LAST_SUBS = dict()
@hook("cmd_hook", "subreddit")
def cmd_subreddit(msg):
global LAST_SUBS
if len(msg.cmds) <= 1:
if not len(msg.args):
if msg.channel in LAST_SUBS and len(LAST_SUBS[msg.channel]) > 0:
subs = [LAST_SUBS[msg.channel].pop()]
else:
raise IRCException("Which subreddit? Need inspiration? "
"type !horny or !bored")
else:
subs = msg.cmds[1:]
subs = msg.args
all_res = list()
for osub in subs:

View File

@ -14,9 +14,9 @@ from more import Response
@hook("cmd_hook", "choice")
def cmd_choice(msg):
if len(msg.cmds) > 1:
return Response(random.choice(msg.cmds[1:]),
channel=msg.channel,
nick=msg.nick)
else:
if not len(msg.args):
raise IRCException("indicate some terms to pick!")
return Response(random.choice(msg.args),
channel=msg.channel,
nick=msg.nick)

View File

@ -21,10 +21,10 @@ def help_full():
@hook("cmd_hook", "sleepytime")
def cmd_sleep(msg):
if len(msg.cmds) > 1 and re.match("[0-9]{1,2}[h':.,-]([0-9]{1,2})?[m'\":.,-]?",
msg.cmds[1]) is not None:
if len(msg.args) and re.match("[0-9]{1,2}[h':.,-]([0-9]{1,2})?[m'\":.,-]?",
msg.args[0]) is not None:
# First, parse the hour
p = re.match("([0-9]{1,2})[h':.,-]([0-9]{1,2})?[m':.,-]?", msg.cmds[1])
p = re.match("([0-9]{1,2})[h':.,-]([0-9]{1,2})?[m':.,-]?", msg.args[0])
f = [datetime(datetime.now(timezone.utc).year,
datetime.now(timezone.utc).month,
datetime.now(timezone.utc).day,

View File

@ -49,12 +49,12 @@ def send_sms(frm, api_usr, api_key, content):
@hook("cmd_hook", "sms")
def cmd_sms(msg):
if len(msg.cmds) <= 2:
if not len(msg.args):
raise IRCException("À qui veux-tu envoyer ce SMS ?")
# Check dests
cur_epoch = time.mktime(time.localtime());
for u in msg.cmds[1].split(","):
for u in msg.args[0].split(","):
if u not in context.data.index:
raise IRCException("Désolé, je sais pas comment envoyer de SMS à %s." % u)
elif cur_epoch - float(context.data.index[u]["lastuse"]) < 42:
@ -62,13 +62,13 @@ def cmd_sms(msg):
# Go!
fails = list()
for u in msg.cmds[1].split(","):
for u in msg.args[0].split(","):
context.data.index[u]["lastuse"] = cur_epoch
if msg.to_response[0] == msg.frm:
frm = msg.frm
else:
frm = msg.frm + "@" + msg.to[0]
test = send_sms(frm, context.data.index[u]["user"], context.data.index[u]["key"], " ".join(msg.cmds[2:]))
test = send_sms(frm, context.data.index[u]["user"], context.data.index[u]["key"], " ".join(msg.args[1:]))
if test is not None:
fails.append( "%s: %s" % (u, test) )

View File

@ -25,13 +25,13 @@ def load(context):
@hook("cmd_hook", "spell")
def cmd_spell(msg):
if len(msg.cmds) < 2:
if not len(msg.args):
raise IRCException("indique une orthographe approximative du mot dont tu veux vérifier l'orthographe.")
lang = "fr"
strRes = list()
for word in msg.cmds[1:]:
if len(word) <= 2 and len(msg.cmds) > 2:
for word in msg.args:
if len(word) <= 2 and len(msg.args) > 2:
lang = word
else:
try:
@ -65,14 +65,13 @@ def add_score(nick, t):
def cmd_score(msg):
res = list()
unknown = list()
if len(msg.cmds) > 1:
for cmd in msg.cmds[1:]:
if cmd in context.data.index:
res.append(Response("%s: %s" % (cmd, " ; ".join(["%s: %d" % (a, context.data.index[cmd].getInt(a)) for a in context.data.index[cmd].attributes.keys() if a != "name"])), channel=msg.channel))
else:
unknown.append(cmd)
else:
return Response("De qui veux-tu voir les scores ?", channel=msg.channel, nick=msg.nick)
if not len(msg.args):
raise IRCException("De qui veux-tu voir les scores ?")
for cmd in msg.args:
if cmd in context.data.index:
res.append(Response("%s: %s" % (cmd, " ; ".join(["%s: %d" % (a, context.data.index[cmd].getInt(a)) for a in context.data.index[cmd].attributes.keys() if a != "name"])), channel=msg.channel))
else:
unknown.append(cmd)
if len(unknown) > 0:
res.append(Response("%s inconnus" % ", ".join(unknown), channel=msg.channel))

View File

@ -78,11 +78,11 @@ def print_station_status(msg, station):
@hook("cmd_hook", "velib")
def ask_stations(msg):
"""Hook entry from !velib"""
if len(msg.cmds) > 5:
if len(msg.args) > 4:
raise IRCException("demande-moi moins de stations à la fois.")
elif len(msg.cmds) > 1:
for station in msg.cmds[1:]:
elif len(msg.args):
for station in msg.args:
if re.match("^[0-9]{4,5}$", station):
return print_station_status(msg, station)
elif station in context.data.index:

View File

@ -48,12 +48,12 @@ def cmd_watch(msg):
node = n
break
if len(msg.cmds) >= 2:
if msg.cmds[1] == "stop" and node is not None:
if len(msg.args):
if msg.args[0] == "stop" and node is not None:
context.data.delChild(node)
context.save()
raise IRCException("This channel will not anymore receives world cup events.")
elif msg.cmds[1] == "start" and node is None:
elif msg.args[0] == "start" and node is None:
start_watch(msg)
else:
raise IRCException("Use only start or stop as first argument")
@ -180,20 +180,19 @@ def get_matches(url):
@hook("cmd_hook", "worldcup")
def cmd_worldcup(msg):
res = Response(channel=msg.channel, nomore="No more match to display", count=" (%d more matches)")
nb = len(msg.cmds)
url = None
if nb == 2:
if msg.cmds[1] == "today" or msg.cmds[1] == "aujourd'hui":
if len(msg.args) == 1:
if msg.args[0] == "today" or msg.args[0] == "aujourd'hui":
url = "matches/today?by_date=ASC"
elif msg.cmds[1] == "tomorrow" or msg.cmds[1] == "demain":
elif msg.args[0] == "tomorrow" or msg.args[0] == "demain":
url = "matches/tomorrow?by_date=ASC"
elif msg.cmds[1] == "all" or msg.cmds[1] == "tout" or msg.cmds[1] == "tous":
elif msg.args[0] == "all" or msg.args[0] == "tout" or msg.args[0] == "tous":
url = "matches/"
elif len(msg.cmds[1]) == 3:
url = "matches/country?fifa_code=%s&by_date=DESC" % msg.cmds[1]
elif is_int(msg.cmds[1]):
url = int(msg.cmds[1])
elif len(msg.args[0]) == 3:
url = "matches/country?fifa_code=%s&by_date=DESC" % msg.args[0]
elif is_int(msg.args[0]):
url = int(msg.arg[0])
else:
raise IRCException("unrecognized request; choose between 'today', 'tomorrow', a FIFA country code or a match identifier")

View File

@ -45,17 +45,17 @@ def gen_response(res, msg, srv):
def cmd_ycc(msg):
minify = list()
if len(msg.cmds) == 1:
if not len(msg.args):
global LAST_URLS
if msg.channel in LAST_URLS and len(LAST_URLS[msg.channel]) > 0:
minify.append(LAST_URLS[msg.channel].pop())
else:
raise IRCException("je n'ai pas d'autre URL à réduire.")
if len(msg.cmds) > 5:
if len(msg.args) > 4:
raise IRCException("je ne peux pas réduire autant d'URL d'un seul coup.")
else:
minify += msg.cmds[1:]
minify += msg.args
res = list()
for url in minify:

View File

@ -11,7 +11,7 @@ from more import Response
nemubotversion = 3.4
def help_full():
return "!yt [<url>]: with an argument, get information about the given link; without arguments, use the latest youtube link seen on the current channel."
return "!yt [<url>]: with an argument, get information about the given link; without arguments, use the latest link seen on the current channel."
def _get_ytdl(links):
cmd = 'youtube-dl -j --'.split()
@ -82,13 +82,14 @@ def parselisten(msg):
@hook("all_post")
def parseresponse(msg):
global LAST_URLS
urls = re.findall("([a-zA-Z0-9+.-]+:(?://)?[^ ]+)", msg.text)
for url in urls:
o = urlparse(url)
if o.scheme != "":
if o.netloc == "" and len(o.path) < 10:
continue
if msg.channel not in LAST_URLS:
LAST_URLS[msg.channel] = list()
LAST_URLS[msg.channel].append(url)
if hasattr(msg, "text"):
urls = re.findall("([a-zA-Z0-9+.-]+:(?://)?[^ ]+)", msg.text)
for url in urls:
o = urlparse(url)
if o.scheme != "":
if o.netloc == "" and len(o.path) < 10:
continue
if msg.channel not in LAST_URLS:
LAST_URLS[msg.channel] = list()
LAST_URLS[msg.channel].append(url)
return msg