Dusting some modules

This commit is contained in:
nemunaire 2014-07-25 18:02:30 +02:00
parent 495c1f0efa
commit 5bec50744c
5 changed files with 43 additions and 67 deletions

View File

@ -13,7 +13,7 @@ def load(context):
def help_tiny ():
"""Line inserted in the response to the command !help"""
return "Read man on IRC"
return "Read manual pages on IRC"
def help_full ():
return "!man [0-9] /what/: gives informations about /what/."

View File

@ -37,7 +37,7 @@ def cmd_sleep(msg):
g.append(f[i+1].strftime("%H:%M"))
return Response(msg.sender,
"You should try to fall asleep at one of the following"
" times: %s" % ', '.join(g), msg.channel)
" times: %s" % ', '.join(g), channel=msg.channel)
# Just get awake times
else:
@ -49,4 +49,4 @@ def cmd_sleep(msg):
return Response(msg.sender,
"If you head to bed right now, you should try to wake"
" up at one of the following times: %s" %
', '.join(g), msg.channel)
', '.join(g), channel=msg.channel)

View File

@ -26,7 +26,7 @@ def load(context):
def cmd_spell(msg):
if len(msg.cmds) < 2:
return Response(msg.sender, "indique une orthographe approximative du mot dont tu veux vérifier l'orthographe.", msg.channel, msg.nick)
raise IRCException("indique une orthographe approximative du mot dont tu veux vérifier l'orthographe.")
lang = "fr"
strRes = list()

View File

@ -57,21 +57,17 @@ def print_station_status(msg, station):
(available, free) = station_status(station)
if available is not None and free is not None:
return Response(msg.sender,
"%s: à la station %s : %d vélib et %d points d'attache"
" disponibles." % (msg.nick, station, available, free),
msg.channel)
else:
return Response(msg.sender,
"%s: station %s inconnue." % (msg.nick, station),
msg.channel)
"à la station %s : %d vélib et %d points d'attache"
" disponibles." % (station, available, free),
channel=msg.channel, nick=msg.nick)
raise IRCException("station %s inconnue." % station)
def ask_stations(msg):
"""Hook entry from !velib"""
global DATAS
if len(msg.cmds) > 5:
return Response(msg.sender,
"Demande-moi moins de stations à la fois.",
msg.channel, nick=msg.nick)
raise IRCException("demande-moi moins de stations à la fois.")
elif len(msg.cmds) > 1:
for station in msg.cmds[1:]:
if re.match("^[0-9]{4,5}$", station):
@ -79,10 +75,7 @@ def ask_stations(msg):
elif station in DATAS.index:
return print_station_status(msg, DATAS.index[station]["number"])
else:
return Response(msg.sender,
"numéro de station invalide.",
msg.channel, nick=msg.nick)
raise IRCException("numéro de station invalide.")
else:
return Response(msg.sender,
"Pour quelle station ?",
msg.channel, nick=msg.nick)
raise IRCException("pour quelle station ?")

View File

@ -32,18 +32,11 @@ def load(context):
print("No alert defined for this site: " + site["url"])
#DATAS.delChild(site)
def unload(context):
"""Unregister watched website"""
# Useless in 3.3?
# for site in DATAS.getNodes("watch"):
# context.del_event(site["evt_id"])
pass
def getPageContent(url):
"""Returns the content of the given url"""
print_debug("Get page %s" % url)
try:
raw = urlopen(url, timeout=15)
raw = urlopen(url, timeout=10)
return raw.read().decode()
except:
return None
@ -60,8 +53,7 @@ def start_watching(site):
def del_site(msg):
if len(msg.cmds) <= 1:
return Response(msg.sender, "quel site dois-je arrêter de surveiller ?",
msg.channel, msg.nick)
raise IRCException("quel site dois-je arrêter de surveiller ?")
url = msg.cmds[1]
@ -71,53 +63,44 @@ def del_site(msg):
for a in site.getNodes("alert"):
if a["channel"] == msg.channel:
if (msg.sender == a["sender"] or msg.is_owner):
site.delChild(a)
if not site.hasNode("alert"):
del_event(site["_evt_id"])
DATAS.delChild(site)
save()
return Response(msg.sender,
"je ne surveille désormais plus cette URL.",
channel=msg.channel, nick=msg.nick)
else:
return Response(msg.sender,
"Vous ne pouvez pas supprimer cette URL.",
channel=msg.channel, nick=msg.nick)
return Response(msg.sender,
"je ne surveillais pas cette URL, impossible de la supprimer.",
channel=msg.channel, nick=msg.nick)
return Response(msg.sender, "je ne surveillais pas cette URL pour vous.",
channel=msg.channel, nick=msg.nick)
raise IRCException("vous ne pouvez pas supprimer cette URL.")
site.delChild(a)
if not site.hasNode("alert"):
del_event(site["_evt_id"])
DATAS.delChild(site)
save()
return Response(msg.sender,
"je ne surveille désormais plus cette URL.",
channel=msg.channel, nick=msg.nick)
raise IRCException("je ne surveillais pas cette URL !")
def add_site(msg, diffType="diff"):
print (diffType)
if len(msg.cmds) <= 1:
return Response(msg.sender, "quel site dois-je surveiller ?",
msg.channel, msg.nick)
raise IRCException("quel site dois-je surveiller ?")
url = msg.cmds[1]
o = urlparse(url, "http")
if o.netloc != "":
alert = ModuleState("alert")
alert["sender"] = msg.sender
alert["server"] = msg.server
alert["channel"] = msg.channel
alert["message"] = "%s a changé !" % url
if o.netloc == "":
raise IRCException("je ne peux pas surveiller cette URL")
if url not in DATAS.index:
watch = ModuleState("watch")
watch["type"] = diffType
watch["url"] = url
watch["time"] = 123
DATAS.addChild(watch)
watch.addChild(alert)
start_watching(watch)
else:
DATAS.index[url].addChild(alert)
alert = ModuleState("alert")
alert["sender"] = msg.sender
alert["server"] = msg.server
alert["channel"] = msg.channel
alert["message"] = "%s a changé !" % url
if url not in DATAS.index:
watch = ModuleState("watch")
watch["type"] = diffType
watch["url"] = url
watch["time"] = 123
DATAS.addChild(watch)
watch.addChild(alert)
start_watching(watch)
else:
return Response(msg.sender, "je ne peux pas surveiller cette URL",
channel=msg.channel, nick=msg.nick)
DATAS.index[url].addChild(alert)
save()
return Response(msg.sender, channel=msg.channel, nick=msg.nick,