Apply v3.3 changes on various modules

This commit is contained in:
Némunaire 2012-11-04 04:39:54 +01:00
parent dc52593953
commit d58afa9419
5 changed files with 94 additions and 93 deletions

View File

@ -7,37 +7,37 @@ from datetime import date
from xmlparser.node import ModuleState
nemubotversion = 3.2
nemubotversion = 3.3
def load(context):
global DATAS
DATAS.setIndex("name", "birthday")
global DATAS
DATAS.setIndex("name", "birthday")
def help_tiny ():
"""Line inserted in the response to the command !help"""
return "People birthdays and ages"
"""Line inserted in the response to the command !help"""
return "People birthdays and ages"
def help_full ():
return "!anniv /who/: gives the remaining time before the anniversary of /who/\n!age /who/: gives the age of /who/\nIf /who/ is not given, gives the remaining time before your anniversary.\n\n To set yout birthday, say it to nemubot :)"
return "!anniv /who/: gives the remaining time before the anniversary of /who/\n!age /who/: gives the age of /who/\nIf /who/ is not given, gives the remaining time before your anniversary.\n\n To set yout birthday, say it to nemubot :)"
def findName(msg):
if len(msg.cmd) < 2 or msg.cmd[1].lower() == "moi" or msg.cmd[1].lower() == "me":
name = msg.nick.lower()
else:
name = msg.cmd[1].lower()
if len(msg.cmds) < 2 or msg.cmds[1].lower() == "moi" or msg.cmds[1].lower() == "me":
name = msg.nick.lower()
else:
name = msg.cmds[1].lower()
matches = []
matches = []
if name in DATAS.index:
matches.append(name)
else:
for k in DATAS.index.keys ():
if k.find (name) == 0:
matches.append (k)
return (matches, name)
if name in DATAS.index:
matches.append(name)
else:
for k in DATAS.index.keys ():
if k.find (name) == 0:
matches.append (k)
return (matches, name)
def cmd_anniv(msg):
@ -83,29 +83,29 @@ def cmd_age(msg):
return True
def parseask(msg):
msgl = msg.content.lower ()
if re.match("^.*(date de naissance|birthday|geburtstag|née? |nee? le|born on).*$", msgl) is not None:
try:
extDate = msg.extractDate()
if extDate is None or extDate.year > datetime.now().year:
return Response(msg.sender,
"ta date de naissance ne paraît pas valide...",
msg.channel,
msg.nick)
else:
if msg.nick.lower() in DATAS.index:
DATAS.index[msg.nick.lower()]["born"] = extDate
else:
ms = ModuleState("birthday")
ms.setAttribute("name", msg.nick.lower())
ms.setAttribute("born", extDate)
DATAS.addChild(ms)
save()
return Response(msg.sender,
"ok, c'est noté, ta date de naissance est le %s"
% extDate.strftime("%A %d %B %Y à %H:%M"),
msg.channel,
msg.nick)
except:
return Response(msg.sender, "ta date de naissance ne paraît pas valide...",
msg.channel, msg.nick)
msgl = msg.content.lower ()
if re.match("^.*(date de naissance|birthday|geburtstag|née? |nee? le|born on).*$", msgl) is not None:
try:
extDate = msg.extractDate()
if extDate is None or extDate.year > datetime.now().year:
return Response(msg.sender,
"ta date de naissance ne paraît pas valide...",
msg.channel,
msg.nick)
else:
if msg.nick.lower() in DATAS.index:
DATAS.index[msg.nick.lower()]["born"] = extDate
else:
ms = ModuleState("birthday")
ms.setAttribute("name", msg.nick.lower())
ms.setAttribute("born", extDate)
DATAS.addChild(ms)
save()
return Response(msg.sender,
"ok, c'est noté, ta date de naissance est le %s"
% extDate.strftime("%A %d %B %Y à %H:%M"),
msg.channel,
msg.nick)
except:
return Response(msg.sender, "ta date de naissance ne paraît pas valide...",
msg.channel, msg.nick)

View File

@ -18,7 +18,7 @@
from networkbot import NetworkBot
nemubotversion = 3.2
nemubotversion = 3.3
NODATA = True
def getserver(toks, context, prompt):

View File

@ -65,7 +65,7 @@ class WFASearch:
def getPage(terms):
conn = http.client.HTTPConnection("api.wolframalpha.com", timeout=5)
conn = http.client.HTTPConnection("api.wolframalpha.com", timeout=15)
try:
conn.request("GET", "/v2/query?input=%s&appid=%s" % (quote(terms), CONF.getNode("wfaapi")["key"]))
except socket.gaierror:

View File

@ -2,7 +2,7 @@
import imp
nemubotversion = 3.2
nemubotversion = 3.3
from . import DDGSearch
from . import WFASearch
@ -38,12 +38,12 @@ def reload():
def define(msg):
if len(msg.cmd) <= 1:
if len(msg.cmds) <= 1:
return Response(msg.sender,
"Indicate a term to define",
msg.channel, nick=msg.nick)
s = DDGSearch.DDGSearch(' '.join(msg.cmd[1:]))
s = DDGSearch.DDGSearch(' '.join(msg.cmds[1:]))
res = Response(msg.sender, channel=msg.channel)
@ -53,12 +53,12 @@ def define(msg):
def search(msg):
if len(msg.cmd) <= 1:
if len(msg.cmds) <= 1:
return Response(msg.sender,
"Indicate a term to search",
msg.channel, nick=msg.nick)
s = DDGSearch.DDGSearch(' '.join(msg.cmd[1:]))
s = DDGSearch.DDGSearch(' '.join(msg.cmds[1:]))
res = Response(msg.sender, channel=msg.channel, nomore="No more results",
count=" (%d more results)")
@ -75,34 +75,35 @@ def search(msg):
def calculate(msg):
if len(msg.cmd) <= 1:
if len(msg.cmds) <= 1:
return Response(msg.sender,
"Indicate a calcul to compute",
msg.channel, nick=msg.nick)
s = WFASearch.WFASearch(' '.join(msg.cmd[1:]))
s = WFASearch.WFASearch(' '.join(msg.cmds[1:]))
if s.success:
res = Response(msg.sender, channel=msg.channel, nomore="No more results")
for result in s.nextRes:
res.append_message(result)
res.messages.pop(0)
if (len(res.messages) > 0):
res.messages.pop(0)
return res
else:
return Response(msg.sender, s.error, msg.channel)
def wiki(msg):
if len(msg.cmd) <= 1:
if len(msg.cmds) <= 1:
return Response(msg.sender,
"Indicate a term to search",
msg.channel, nick=msg.nick)
if msg.cmd[0] == "w" or msg.cmd[0] == "wf" or msg.cmd[0] == "wfr":
if msg.cmds[0] == "w" or msg.cmds[0] == "wf" or msg.cmds[0] == "wfr":
lang = "fr"
else:
lang = "en"
s = Wikipedia.Wikipedia(' '.join(msg.cmd[1:]), lang)
s = Wikipedia.Wikipedia(' '.join(msg.cmds[1:]), lang)
res = Response(msg.sender, channel=msg.channel, nomore="No more results")
for result in s.nextRes:
@ -112,5 +113,5 @@ def wiki(msg):
return res
else:
return Response(msg.sender,
"No information about " + msg.cmd[1],
"No information about " + msg.cmds[1],
msg.channel)

View File

@ -7,11 +7,11 @@ from xml.dom.minidom import parseString
from event import ModuleEvent
from xmlparser.node import ModuleState
nemubotversion = 3.2
nemubotversion = 3.3
def load(context):
global DATAS
DATAS.setIndex("name", "station")
global DATAS
DATAS.setIndex("name", "station")
# evt = ModuleEvent(station_available, "42706",
# (lambda a, b: a != b), None, 60,
@ -19,45 +19,45 @@ def load(context):
# context.add_event(evt)
def help_tiny ():
"""Line inserted in the response to the command !help"""
return "Gets information about velib stations"
"""Line inserted in the response to the command !help"""
return "Gets information about velib stations"
def help_full ():
return "!velib /number/ ...: gives available bikes and slots at the station /number/."
return "!velib /number/ ...: gives available bikes and slots at the station /number/."
def getPage (s, p):
conn = http.client.HTTPConnection(s, timeout=10)
try:
conn.request("GET", p)
except socket.gaierror:
print ("[%s] impossible de récupérer la page %s."%(s, p))
return None
conn = http.client.HTTPConnection(s, timeout=10)
try:
conn.request("GET", p)
except socket.gaierror:
print ("[%s] impossible de récupérer la page %s."%(s, p))
return None
res = conn.getresponse()
data = res.read()
res = conn.getresponse()
data = res.read()
conn.close()
return (res.status, data)
conn.close()
return (res.status, data)
def station_status(station):
"""Gets available and free status of a given station"""
(st, page) = getPage(CONF.getNode("server")["ip"], CONF.getNode("server")["url"] + station)
if st == http.client.OK:
response = parseString(page)
available = response.documentElement.getElementsByTagName("available")
if len(available) > 0:
available = int(available[0].childNodes[0].nodeValue)
"""Gets available and free status of a given station"""
(st, page) = getPage(CONF.getNode("server")["ip"], CONF.getNode("server")["url"] + station)
if st == http.client.OK:
response = parseString(page)
available = response.documentElement.getElementsByTagName("available")
if len(available) > 0:
available = int(available[0].childNodes[0].nodeValue)
else:
available = 0
free = response.documentElement.getElementsByTagName("free")
if len(free) > 0:
free = int(free[0].childNodes[0].nodeValue)
else:
free = 0
return (available, free)
else:
available = 0
free = response.documentElement.getElementsByTagName("free")
if len(free) > 0:
free = int(free[0].childNodes[0].nodeValue)
else:
free = 0
return (available, free)
else:
return (None, None)
return (None, None)
def station_available(station):
"""Gets available velib at a given velib station"""
@ -86,12 +86,12 @@ def print_station_status(msg, station):
def ask_stations(msg):
"""Hook entry from !velib"""
global DATAS
if len(msg.cmd) > 5:
if len(msg.cmds) > 5:
return Response(msg.sender,
"Demande-moi moins de stations à la fois.",
msg.channel, nick=msg.nick)
elif len(msg.cmd) > 1:
for station in msg.cmd[1:]:
elif len(msg.cmds) > 1:
for station in msg.cmds[1:]:
if re.match("^[0-9]{4,5}$", station):
return print_station_status(msg, station)
elif station in DATAS.index: