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 (): def help_tiny ():
"""Line inserted in the response to the command !help""" """Line inserted in the response to the command !help"""
return "Read man on IRC" return "Read manual pages on IRC"
def help_full (): def help_full ():
return "!man [0-9] /what/: gives informations about /what/." 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")) g.append(f[i+1].strftime("%H:%M"))
return Response(msg.sender, return Response(msg.sender,
"You should try to fall asleep at one of the following" "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 # Just get awake times
else: else:
@ -49,4 +49,4 @@ def cmd_sleep(msg):
return Response(msg.sender, return Response(msg.sender,
"If you head to bed right now, you should try to wake" "If you head to bed right now, you should try to wake"
" up at one of the following times: %s" % " 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): def cmd_spell(msg):
if len(msg.cmds) < 2: 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" lang = "fr"
strRes = list() strRes = list()

View File

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

View File

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