Example #1
0
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:
        msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.sender))
      else:
        if msg.sender.lower() in DATAS.index:
          DATAS.index[msg.sender.lower()] = extDate
        else:
          ms = ModuleState("birthday")
          ms.setAttribute("name", msg.sender.lower())
          ms.setAttribute("born", extDate)
          DATAS.addChild(ms)
        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()
    except:
      msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.sender))
    return True
  return False
Example #2
0
 def __setitem__(self, i, j):
   ms = ModuleState(self.stateName)
   ms.setAttribute(self.attName, i)
   j.save(ms)
   self.DATAS.addChild(ms)
   self.DATAS.setIndex(self.attName, self.stateName)
Example #3
0
def parseanswer(msg):
  global DATAS
  if msg.cmd[0] == "we" or msg.cmd[0] == "week-end" or msg.cmd[0] == "weekend":
    ndate = datetime.today() + timedelta(5 - datetime.today().weekday())
    ndate = datetime(ndate.year, ndate.month, ndate.day, 0, 0, 1)
    msg.send_chn (
      msg.countdown_format (ndate,
                            "Il reste %s avant le week-end, courage ;)",
                            "Youhou, on est en week-end depuis %s."))
    return True
  elif msg.cmd[0] == "new-year" or msg.cmd[0] == "newyear" or msg.cmd[0] == "ny":
    msg.send_chn (
      msg.countdown_format (datetime(datetime.today().year + 1, 1, 1, 0, 0, 1),
                            "Il reste %s avant la nouvelle année.",
                            "Nous faisons déjà la fête depuis %s !"))
    return True
  elif msg.cmd[0] == "vacances" or msg.cmd[0] == "vacs" or msg.cmd[0] == "holiday" or msg.cmd[0] == "holidays":
    msg.send_chn (
      msg.countdown_format (datetime(2012, 7, 30, 18, 0, 1),
                            "Il reste %s avant les vacances :)",
                            "Profitons, c'est les vacances depuis %s."))
    return True
  elif msg.cmd[0] == "start" and len(msg.cmd) > 1:
    if msg.cmd[1] not in DATAS:
      strnd = ModuleState("strend")
      strnd["server"] = msg.srv.id
      strnd["channel"] = msg.channel
      strnd["proprio"] = msg.sender
      strnd["start"] = datetime.now()
      strnd["name"] = msg.cmd[1]
      DATAS.addChild(strnd)
      
      if len(msg.cmd) > 2:
        result = re.match("([0-9]+)([smhdjSMHDJ])?", msg.cmd[2])
        if result is not None:
          try:
            if result.group(2) is not None and (result.group(2) == "m" or result.group(2) == "M"):
              strnd["end"] = datetime.now() + timedelta(minutes=int(result.group(1)))
            elif result.group(2) is not None and (result.group(2) == "h" or result.group(2) == "H"):
              strnd["end"] = datetime.now() + timedelta(hours=int(result.group(1)))
            elif result.group(2) is not None and (result.group(2) == "d" or result.group(2) == "D" or result.group(2) == "j" or result.group(2) == "J"):
              strnd["end"] = datetime.now() + timedelta(days=int(result.group(1)))
            else:
              strnd["end"] = datetime.now() + timedelta(seconds=int(result.group(1)))
            Manager.newStrendEvt.set()
            msg.send_snd ("%s commencé le %s et se terminera le %s."% (msg.cmd[1], datetime.now(), strnd.getDate("end")))
          except:
            msg.send_snd ("Impossible de définir la fin de %s."% (msg.cmd[1]))
            msg.send_snd ("%s commencé le %s."% (msg.cmd[1], datetime.now()))
        else:
          msg.send_snd ("%s commencé le %s"% (msg.cmd[1], datetime.now()))
      save()
    else:
      msg.send_snd ("%s existe déjà."% (msg.cmd[1]))
    return True
  elif (msg.cmd[0] == "end" or msg.cmd[0] == "forceend") and len(msg.cmd) > 1:
    if msg.cmd[1] in DATAS.index:
      msg.send_chn ("%s a duré %s." % (msg.cmd[1], msg.just_countdown(datetime.now () - DATAS.index[msg.cmd[1]].getDate("start"))))
      if DATAS.index[msg.cmd[1]]["proprio"] == msg.sender or (msg.cmd[0] == "forceend" and msg.sender == msg.srv.owner):
        DATAS.delChild(DATAS.index[msg.cmd[1]])
        Manager.newStrendEvt.set()
        save()
      else:
        msg.send_snd ("Vous ne pouvez pas terminer le compteur %s, créé par %s."% (msg.cmd[1], DATAS.index[msg.cmd[1]]["proprio"]))
    else:
      msg.send_snd ("%s n'est pas un compteur connu."% (msg.cmd[1]))
    return True
  elif msg.cmd[0] == "eventslist" or msg.cmd[0] == "eventlist" or msg.cmd[0] == "eventsliste" or msg.cmd[0] == "eventliste":
    msg.send_snd ("Compteurs connus : %s." % ", ".join(DATAS.index.keys()))
  elif msg.cmd[0] in DATAS.index:
    if DATAS.index[msg.cmd[0]].name == "strend":
      if DATAS.index[msg.cmd[0]].hasAttribute("end"):
        msg.send_chn ("%s commencé il y a %s et se terminera dans %s." % (msg.cmd[0], msg.just_countdown(datetime.now() - DATAS.index[msg.cmd[0]].getDate("start")), msg.just_countdown(DATAS.index[msg.cmd[0]].getDate("end") - datetime.now())))
      else:
        msg.send_chn ("%s commencé il y a %s." % (msg.cmd[0], msg.just_countdown(datetime.now () - DATAS.index[msg.cmd[0]].getDate("start"))))
    else:
      msg.send_chn (msg.countdown_format (DATAS.index[msg.cmd[0]].getDate("start"), DATAS.index[msg.cmd[0]]["msg_before"], DATAS.index[msg.cmd[0]]["msg_after"]))
    save()
    return True
  else:
    return False