2012-12-31 19:19:07 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
2014-08-27 23:39:31 +00:00
|
|
|
"""Wishes Happy New Year when the time comes"""
|
|
|
|
|
2012-12-31 19:19:07 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2014-08-12 18:10:19 +00:00
|
|
|
from hooks import hook
|
|
|
|
|
2014-08-13 13:53:55 +00:00
|
|
|
nemubotversion = 3.4
|
2012-12-31 19:19:07 +00:00
|
|
|
|
2014-08-12 18:10:19 +00:00
|
|
|
yr = datetime.today().year
|
|
|
|
yrn = datetime.today().year + 1
|
2012-12-31 19:19:07 +00:00
|
|
|
|
2014-08-12 18:10:19 +00:00
|
|
|
def load(context):
|
2012-12-31 19:19:07 +00:00
|
|
|
d = datetime(yrn, 1, 1, 0, 0, 0) - datetime.now()
|
|
|
|
add_event(ModuleEvent(intervalle=0, offset=d.total_seconds(), call=bonneannee))
|
|
|
|
|
|
|
|
def bonneannee():
|
|
|
|
txt = "Bonne année %d !" % datetime.today().year
|
|
|
|
print (txt)
|
|
|
|
send_response("localhost:2771", Response(None, txt, "#epitagueule"))
|
|
|
|
send_response("localhost:2771", Response(None, txt, "#yaka"))
|
|
|
|
send_response("localhost:2771", Response(None, txt, "#epita2014"))
|
|
|
|
send_response("localhost:2771", Response(None, txt, "#ykar"))
|
|
|
|
send_response("localhost:2771", Response(None, txt, "#42sh"))
|
|
|
|
send_response("localhost:2771", Response(None, txt, "#nemubot"))
|
|
|
|
|
2014-08-12 18:10:19 +00:00
|
|
|
@hook("cmd_hook", "newyear")
|
|
|
|
@hook("cmd_hook", str(yrn), yrn)
|
2012-12-31 19:19:07 +00:00
|
|
|
def cmd_newyear(msg, yr):
|
|
|
|
return Response(msg.sender,
|
|
|
|
msg.countdown_format(datetime(yr, 1, 1, 0, 0, 1),
|
|
|
|
"Il reste %s avant la nouvelle année.",
|
|
|
|
"Nous faisons déjà la fête depuis %s !"),
|
|
|
|
channel=msg.channel)
|
|
|
|
|
2014-08-12 18:10:19 +00:00
|
|
|
@hook("cmd_rgxp", data=yrn, regexp="^[0-9]{4}$")
|
2012-12-31 19:19:07 +00:00
|
|
|
def cmd_timetoyear(msg, cur):
|
|
|
|
yr = int(msg.cmds[0])
|
|
|
|
|
|
|
|
if yr == cur:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return Response(msg.sender,
|
|
|
|
msg.countdown_format(datetime(yr, 1, 1, 0, 0, 1),
|
|
|
|
"Il reste %s avant %d." % ("%s", yr),
|
|
|
|
"Le premier janvier %d est passé depuis %s !" % (yr, "%s")),
|
|
|
|
channel=msg.channel)
|