Stability improvements
This commit is contained in:
parent
0c18611c7f
commit
2e461f26f4
6 changed files with 136 additions and 61 deletions
58
birthday.py
58
birthday.py
|
|
@ -84,22 +84,26 @@ def help_full ():
|
|||
return "!anniv /who/: gives the remaining time before the anniversary 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.sender.lower()
|
||||
else:
|
||||
name = msg.cmd[1].lower()
|
||||
|
||||
matches = []
|
||||
|
||||
if name in BIRTHDAYS:
|
||||
matches.append(name)
|
||||
else:
|
||||
for k in BIRTHDAYS.keys ():
|
||||
if k.find (name) == 0:
|
||||
matches.append (k)
|
||||
return (matches, name)
|
||||
|
||||
|
||||
def parseanswer(msg):
|
||||
if msg.cmd[0] == "anniv":
|
||||
if len(msg.cmd) < 2 or msg.cmd[1].lower() == "moi" or msg.cmd[1].lower() == "me":
|
||||
name = msg.sender.lower()
|
||||
else:
|
||||
name = msg.cmd[1].lower()
|
||||
|
||||
matches = []
|
||||
|
||||
if name in BIRTHDAYS:
|
||||
matches.append(name)
|
||||
else:
|
||||
for k in BIRTHDAYS.keys ():
|
||||
if k.find (name) == 0:
|
||||
matches.append (k)
|
||||
|
||||
(matches, name) = findName(msg)
|
||||
if len(matches) == 1:
|
||||
(n, d) = (matches[0], BIRTHDAYS[matches[0]])
|
||||
tyd = d
|
||||
|
|
@ -111,10 +115,19 @@ def parseanswer(msg):
|
|||
if tyd < datetime.today():
|
||||
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", n), ""))
|
||||
msg.send_chn (msg.countdown_format (tyd, "Il reste %s avant l'anniversaire de %s !" % ("%s", n), ""))
|
||||
else:
|
||||
msg.send_chn ("%s: désolé, je ne connais pas la date d'anniversaire de %s. Quand est-il né ?"%(msg.sender, name))
|
||||
return True
|
||||
elif msg.cmd[0] == "age":
|
||||
(matches, name) = findName(msg)
|
||||
if len(matches) == 1:
|
||||
(n, d) = (matches[0], BIRTHDAYS[matches[0]])
|
||||
|
||||
msg.send_chn (msg.countdown_format (d, "", "%s a %s." % (n, "%s")))
|
||||
else:
|
||||
msg.send_chn ("%s: désolé, je ne connais pas l'âge de %s. Quand est-il né ?"%(msg.sender, name))
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
|
@ -122,13 +135,16 @@ def parseanswer(msg):
|
|||
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:
|
||||
extDate = msg.extractDate ()
|
||||
if extDate is None:
|
||||
try:
|
||||
extDate = msg.extractDate ()
|
||||
if extDate is None:
|
||||
msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.sender))
|
||||
else:
|
||||
BIRTHDAYS[msg.sender.lower()] = extDate
|
||||
msg.send_chn ("%s: ok, c'est noté, ta date de naissance est le %s" % (msg.sender, extDate.strftime("%A %d %B %Y à %H:%M")))
|
||||
save_module ()
|
||||
except:
|
||||
msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.sender))
|
||||
else:
|
||||
BIRTHDAYS[msg.sender.lower()] = extDate
|
||||
msg.send_chn ("%s: ok, c'est noté, ta date de naissance est le %s" % (msg.sender, extDate.strftime("%A %d %B %Y à %H:%M")))
|
||||
save_module ()
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue