Apply v3.3 changes on various modules
This commit is contained in:
parent
dc52593953
commit
d58afa9419
@ -7,37 +7,37 @@ from datetime import date
|
|||||||
|
|
||||||
from xmlparser.node import ModuleState
|
from xmlparser.node import ModuleState
|
||||||
|
|
||||||
nemubotversion = 3.2
|
nemubotversion = 3.3
|
||||||
|
|
||||||
def load(context):
|
def load(context):
|
||||||
global DATAS
|
global DATAS
|
||||||
DATAS.setIndex("name", "birthday")
|
DATAS.setIndex("name", "birthday")
|
||||||
|
|
||||||
|
|
||||||
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 "People birthdays and ages"
|
return "People birthdays and ages"
|
||||||
|
|
||||||
|
|
||||||
def help_full ():
|
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):
|
def findName(msg):
|
||||||
if len(msg.cmd) < 2 or msg.cmd[1].lower() == "moi" or msg.cmd[1].lower() == "me":
|
if len(msg.cmds) < 2 or msg.cmds[1].lower() == "moi" or msg.cmds[1].lower() == "me":
|
||||||
name = msg.nick.lower()
|
name = msg.nick.lower()
|
||||||
else:
|
else:
|
||||||
name = msg.cmd[1].lower()
|
name = msg.cmds[1].lower()
|
||||||
|
|
||||||
matches = []
|
matches = []
|
||||||
|
|
||||||
if name in DATAS.index:
|
if name in DATAS.index:
|
||||||
matches.append(name)
|
matches.append(name)
|
||||||
else:
|
else:
|
||||||
for k in DATAS.index.keys ():
|
for k in DATAS.index.keys ():
|
||||||
if k.find (name) == 0:
|
if k.find (name) == 0:
|
||||||
matches.append (k)
|
matches.append (k)
|
||||||
return (matches, name)
|
return (matches, name)
|
||||||
|
|
||||||
|
|
||||||
def cmd_anniv(msg):
|
def cmd_anniv(msg):
|
||||||
@ -83,29 +83,29 @@ def cmd_age(msg):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def parseask(msg):
|
def parseask(msg):
|
||||||
msgl = msg.content.lower ()
|
msgl = msg.content.lower ()
|
||||||
if re.match("^.*(date de naissance|birthday|geburtstag|née? |nee? le|born on).*$", msgl) is not None:
|
if re.match("^.*(date de naissance|birthday|geburtstag|née? |nee? le|born on).*$", msgl) is not None:
|
||||||
try:
|
try:
|
||||||
extDate = msg.extractDate()
|
extDate = msg.extractDate()
|
||||||
if extDate is None or extDate.year > datetime.now().year:
|
if extDate is None or extDate.year > datetime.now().year:
|
||||||
return Response(msg.sender,
|
return Response(msg.sender,
|
||||||
"ta date de naissance ne paraît pas valide...",
|
"ta date de naissance ne paraît pas valide...",
|
||||||
msg.channel,
|
msg.channel,
|
||||||
msg.nick)
|
msg.nick)
|
||||||
else:
|
else:
|
||||||
if msg.nick.lower() in DATAS.index:
|
if msg.nick.lower() in DATAS.index:
|
||||||
DATAS.index[msg.nick.lower()]["born"] = extDate
|
DATAS.index[msg.nick.lower()]["born"] = extDate
|
||||||
else:
|
else:
|
||||||
ms = ModuleState("birthday")
|
ms = ModuleState("birthday")
|
||||||
ms.setAttribute("name", msg.nick.lower())
|
ms.setAttribute("name", msg.nick.lower())
|
||||||
ms.setAttribute("born", extDate)
|
ms.setAttribute("born", extDate)
|
||||||
DATAS.addChild(ms)
|
DATAS.addChild(ms)
|
||||||
save()
|
save()
|
||||||
return Response(msg.sender,
|
return Response(msg.sender,
|
||||||
"ok, c'est noté, ta date de naissance est le %s"
|
"ok, c'est noté, ta date de naissance est le %s"
|
||||||
% extDate.strftime("%A %d %B %Y à %H:%M"),
|
% extDate.strftime("%A %d %B %Y à %H:%M"),
|
||||||
msg.channel,
|
msg.channel,
|
||||||
msg.nick)
|
msg.nick)
|
||||||
except:
|
except:
|
||||||
return Response(msg.sender, "ta date de naissance ne paraît pas valide...",
|
return Response(msg.sender, "ta date de naissance ne paraît pas valide...",
|
||||||
msg.channel, msg.nick)
|
msg.channel, msg.nick)
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
from networkbot import NetworkBot
|
from networkbot import NetworkBot
|
||||||
|
|
||||||
nemubotversion = 3.2
|
nemubotversion = 3.3
|
||||||
NODATA = True
|
NODATA = True
|
||||||
|
|
||||||
def getserver(toks, context, prompt):
|
def getserver(toks, context, prompt):
|
||||||
|
@ -65,7 +65,7 @@ class WFASearch:
|
|||||||
|
|
||||||
|
|
||||||
def getPage(terms):
|
def getPage(terms):
|
||||||
conn = http.client.HTTPConnection("api.wolframalpha.com", timeout=5)
|
conn = http.client.HTTPConnection("api.wolframalpha.com", timeout=15)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", "/v2/query?input=%s&appid=%s" % (quote(terms), CONF.getNode("wfaapi")["key"]))
|
conn.request("GET", "/v2/query?input=%s&appid=%s" % (quote(terms), CONF.getNode("wfaapi")["key"]))
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import imp
|
import imp
|
||||||
|
|
||||||
nemubotversion = 3.2
|
nemubotversion = 3.3
|
||||||
|
|
||||||
from . import DDGSearch
|
from . import DDGSearch
|
||||||
from . import WFASearch
|
from . import WFASearch
|
||||||
@ -38,12 +38,12 @@ def reload():
|
|||||||
|
|
||||||
|
|
||||||
def define(msg):
|
def define(msg):
|
||||||
if len(msg.cmd) <= 1:
|
if len(msg.cmds) <= 1:
|
||||||
return Response(msg.sender,
|
return Response(msg.sender,
|
||||||
"Indicate a term to define",
|
"Indicate a term to define",
|
||||||
msg.channel, nick=msg.nick)
|
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)
|
res = Response(msg.sender, channel=msg.channel)
|
||||||
|
|
||||||
@ -53,12 +53,12 @@ def define(msg):
|
|||||||
|
|
||||||
|
|
||||||
def search(msg):
|
def search(msg):
|
||||||
if len(msg.cmd) <= 1:
|
if len(msg.cmds) <= 1:
|
||||||
return Response(msg.sender,
|
return Response(msg.sender,
|
||||||
"Indicate a term to search",
|
"Indicate a term to search",
|
||||||
msg.channel, nick=msg.nick)
|
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",
|
res = Response(msg.sender, channel=msg.channel, nomore="No more results",
|
||||||
count=" (%d more results)")
|
count=" (%d more results)")
|
||||||
@ -75,34 +75,35 @@ def search(msg):
|
|||||||
|
|
||||||
|
|
||||||
def calculate(msg):
|
def calculate(msg):
|
||||||
if len(msg.cmd) <= 1:
|
if len(msg.cmds) <= 1:
|
||||||
return Response(msg.sender,
|
return Response(msg.sender,
|
||||||
"Indicate a calcul to compute",
|
"Indicate a calcul to compute",
|
||||||
msg.channel, nick=msg.nick)
|
msg.channel, nick=msg.nick)
|
||||||
|
|
||||||
s = WFASearch.WFASearch(' '.join(msg.cmd[1:]))
|
s = WFASearch.WFASearch(' '.join(msg.cmds[1:]))
|
||||||
|
|
||||||
if s.success:
|
if s.success:
|
||||||
res = Response(msg.sender, channel=msg.channel, nomore="No more results")
|
res = Response(msg.sender, channel=msg.channel, nomore="No more results")
|
||||||
for result in s.nextRes:
|
for result in s.nextRes:
|
||||||
res.append_message(result)
|
res.append_message(result)
|
||||||
res.messages.pop(0)
|
if (len(res.messages) > 0):
|
||||||
|
res.messages.pop(0)
|
||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
return Response(msg.sender, s.error, msg.channel)
|
return Response(msg.sender, s.error, msg.channel)
|
||||||
|
|
||||||
|
|
||||||
def wiki(msg):
|
def wiki(msg):
|
||||||
if len(msg.cmd) <= 1:
|
if len(msg.cmds) <= 1:
|
||||||
return Response(msg.sender,
|
return Response(msg.sender,
|
||||||
"Indicate a term to search",
|
"Indicate a term to search",
|
||||||
msg.channel, nick=msg.nick)
|
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"
|
lang = "fr"
|
||||||
else:
|
else:
|
||||||
lang = "en"
|
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")
|
res = Response(msg.sender, channel=msg.channel, nomore="No more results")
|
||||||
for result in s.nextRes:
|
for result in s.nextRes:
|
||||||
@ -112,5 +113,5 @@ def wiki(msg):
|
|||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
return Response(msg.sender,
|
return Response(msg.sender,
|
||||||
"No information about " + msg.cmd[1],
|
"No information about " + msg.cmds[1],
|
||||||
msg.channel)
|
msg.channel)
|
||||||
|
@ -7,11 +7,11 @@ from xml.dom.minidom import parseString
|
|||||||
from event import ModuleEvent
|
from event import ModuleEvent
|
||||||
from xmlparser.node import ModuleState
|
from xmlparser.node import ModuleState
|
||||||
|
|
||||||
nemubotversion = 3.2
|
nemubotversion = 3.3
|
||||||
|
|
||||||
def load(context):
|
def load(context):
|
||||||
global DATAS
|
global DATAS
|
||||||
DATAS.setIndex("name", "station")
|
DATAS.setIndex("name", "station")
|
||||||
|
|
||||||
# evt = ModuleEvent(station_available, "42706",
|
# evt = ModuleEvent(station_available, "42706",
|
||||||
# (lambda a, b: a != b), None, 60,
|
# (lambda a, b: a != b), None, 60,
|
||||||
@ -19,45 +19,45 @@ def load(context):
|
|||||||
# context.add_event(evt)
|
# context.add_event(evt)
|
||||||
|
|
||||||
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 "Gets information about velib stations"
|
return "Gets information about velib stations"
|
||||||
|
|
||||||
def help_full ():
|
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):
|
def getPage (s, p):
|
||||||
conn = http.client.HTTPConnection(s, timeout=10)
|
conn = http.client.HTTPConnection(s, timeout=10)
|
||||||
try:
|
try:
|
||||||
conn.request("GET", p)
|
conn.request("GET", p)
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
print ("[%s] impossible de récupérer la page %s."%(s, p))
|
print ("[%s] impossible de récupérer la page %s."%(s, p))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
res = conn.getresponse()
|
res = conn.getresponse()
|
||||||
data = res.read()
|
data = res.read()
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
return (res.status, data)
|
return (res.status, data)
|
||||||
|
|
||||||
def station_status(station):
|
def station_status(station):
|
||||||
"""Gets available and free status of a given station"""
|
"""Gets available and free status of a given station"""
|
||||||
(st, page) = getPage(CONF.getNode("server")["ip"], CONF.getNode("server")["url"] + station)
|
(st, page) = getPage(CONF.getNode("server")["ip"], CONF.getNode("server")["url"] + station)
|
||||||
if st == http.client.OK:
|
if st == http.client.OK:
|
||||||
response = parseString(page)
|
response = parseString(page)
|
||||||
available = response.documentElement.getElementsByTagName("available")
|
available = response.documentElement.getElementsByTagName("available")
|
||||||
if len(available) > 0:
|
if len(available) > 0:
|
||||||
available = int(available[0].childNodes[0].nodeValue)
|
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:
|
else:
|
||||||
available = 0
|
return (None, None)
|
||||||
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)
|
|
||||||
|
|
||||||
def station_available(station):
|
def station_available(station):
|
||||||
"""Gets available velib at a given velib station"""
|
"""Gets available velib at a given velib station"""
|
||||||
@ -86,12 +86,12 @@ def print_station_status(msg, station):
|
|||||||
def ask_stations(msg):
|
def ask_stations(msg):
|
||||||
"""Hook entry from !velib"""
|
"""Hook entry from !velib"""
|
||||||
global DATAS
|
global DATAS
|
||||||
if len(msg.cmd) > 5:
|
if len(msg.cmds) > 5:
|
||||||
return Response(msg.sender,
|
return Response(msg.sender,
|
||||||
"Demande-moi moins de stations à la fois.",
|
"Demande-moi moins de stations à la fois.",
|
||||||
msg.channel, nick=msg.nick)
|
msg.channel, nick=msg.nick)
|
||||||
elif len(msg.cmd) > 1:
|
elif len(msg.cmds) > 1:
|
||||||
for station in msg.cmd[1:]:
|
for station in msg.cmds[1:]:
|
||||||
if re.match("^[0-9]{4,5}$", station):
|
if re.match("^[0-9]{4,5}$", station):
|
||||||
return print_station_status(msg, station)
|
return print_station_status(msg, station)
|
||||||
elif station in DATAS.index:
|
elif station in DATAS.index:
|
||||||
|
Loading…
Reference in New Issue
Block a user