Convert birthday module to V3.2 and fix some bugs
This commit is contained in:
parent
59f18b7974
commit
9939981dae
@ -5,11 +5,11 @@ import sys
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from module_state import ModuleState
|
from xmlparser.node import ModuleState
|
||||||
|
|
||||||
nemubotversion = 3.0
|
nemubotversion = 3.2
|
||||||
|
|
||||||
def load():
|
def load(context):
|
||||||
global DATAS
|
global DATAS
|
||||||
DATAS.setIndex("name", "birthday")
|
DATAS.setIndex("name", "birthday")
|
||||||
|
|
||||||
@ -40,47 +40,46 @@ def findName(msg):
|
|||||||
return (matches, name)
|
return (matches, name)
|
||||||
|
|
||||||
|
|
||||||
def parseanswer(msg):
|
def cmd_anniv(msg):
|
||||||
if msg.cmd[0] == "anniv":
|
|
||||||
(matches, name) = findName(msg)
|
(matches, name) = findName(msg)
|
||||||
if len(matches) == 1:
|
if len(matches) == 1:
|
||||||
name = matches[0]
|
name = matches[0]
|
||||||
tyd = DATAS.index[name].getDate("born")
|
tyd = DATAS.index[name].getDate("born")
|
||||||
tyd = datetime(date.today().year, tyd.month, tyd.day)
|
tyd = datetime(date.today().year, tyd.month, tyd.day)
|
||||||
|
|
||||||
if tyd.day == datetime.today().day and tyd.month == datetime.today().month:
|
if tyd.day == datetime.today().day and tyd.month == datetime.today().month:
|
||||||
msg.send_chn (msg.countdown_format (DATAS.index[name].getDate("born"), "", "C'est aujourd'hui l'anniversaire de %s ! Il a%s. Joyeux anniversaire :)" % (name, "%s")))
|
msg.send_chn (msg.countdown_format (DATAS.index[name].getDate("born"), "", "C'est aujourd'hui l'anniversaire de %s ! Il a%s. Joyeux anniversaire :)" % (name, "%s")))
|
||||||
else:
|
else:
|
||||||
if tyd < datetime.today():
|
if tyd < datetime.today():
|
||||||
tyd = datetime(date.today().year + 1, tyd.month, tyd.day)
|
tyd = datetime(date.today().year + 1, tyd.month, tyd.day)
|
||||||
|
|
||||||
msg.send_chn (msg.countdown_format (tyd, "Il reste %s avant l'anniversaire de %s !" % ("%s", name), ""))
|
msg.send_chn (msg.countdown_format (tyd, "Il reste %s avant l'anniversaire de %s !" % ("%s", name), ""))
|
||||||
else:
|
else:
|
||||||
msg.send_chn ("%s: désolé, je ne connais pas la date d'anniversaire de %s. Quand est-il né ?"%(msg.nick, name))
|
msg.send_chn ("%s: désolé, je ne connais pas la date d'anniversaire de %s. Quand est-il né ?"%(msg.nick, name))
|
||||||
return True
|
return True
|
||||||
elif msg.cmd[0] == "age":
|
|
||||||
|
def cmd_age(msg):
|
||||||
(matches, name) = findName(msg)
|
(matches, name) = findName(msg)
|
||||||
if len(matches) == 1:
|
if len(matches) == 1:
|
||||||
name = matches[0]
|
name = matches[0]
|
||||||
d = DATAS.index[name].getDate("born")
|
d = DATAS.index[name].getDate("born")
|
||||||
|
|
||||||
msg.send_chn (msg.countdown_format (d, "", "%s a %s." % (n, "%s")))
|
msg.send_chn (msg.countdown_format (d, "%s va naître dans %s." % (name, "%s"),
|
||||||
|
"%s a %s." % (name, "%s")))
|
||||||
else:
|
else:
|
||||||
msg.send_chn ("%s: désolé, je ne connais pas l'âge de %s. Quand est-il né ?"%(msg.nick, name))
|
msg.send_chn ("%s: désolé, je ne connais pas l'âge de %s. Quand est-il né ?"%(msg.nick, name))
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
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:
|
if extDate is None or extDate.year() > datetime.now().year():
|
||||||
msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.nick))
|
msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.nick))
|
||||||
else:
|
else:
|
||||||
if msg.nick.lower() in DATAS.index:
|
if msg.nick.lower() in DATAS.index:
|
||||||
DATAS.index[msg.nick.lower()] = 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())
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
<?xml version="1.0" ?>
|
<?xml version="1.0" ?>
|
||||||
<nemubotmodule name="birthday" />
|
<nemubotmodule name="birthday">
|
||||||
|
<message type="cmd" name="anniv" call="cmd_anniv" />
|
||||||
|
<message type="cmd" name="age" call="cmd_age" />
|
||||||
|
</nemubotmodule>
|
||||||
|
Loading…
Reference in New Issue
Block a user