Birthday module: fixes #63

This commit is contained in:
nemunaire 2014-08-21 15:16:25 +02:00
parent 5559ae20d9
commit 82156543aa

View File

@ -86,27 +86,31 @@ def cmd_age(msg):
return True return True
def parseask(msg): def parseask(msg):
if re.match("^.*(date de naissance|birthday|geburtstag|née? |nee? le|born on).*$", msg.content, re.I) is not None: res = re.match(r"^(\S+)\s*('s|suis|est|is|was|were)?\s+(birthday|geburtstag|née? |nee? le|born on).*$", msg.content, re.I)
if res 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...", "la 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: nick = res.group(1)
if nick == "my" or nick == "I" or nick == "i" or nick == "je" or nick == "mon" or nick == "ma":
nick = msg.nick
if 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", 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é, %s est né le %s"
% extDate.strftime("%A %d %B %Y à %H:%M"), % (nick, extDate.strftime("%A %d %B %Y à %H:%M")),
msg.channel, msg.channel,
msg.nick) msg.nick)
except: except:
raise IRCException("ta date de naissance ne paraît pas valide.") raise IRCException("la date de naissance ne paraît pas valide.")