nemubot/modules/bonneannee.py

50 lines
1.7 KiB
Python
Raw Normal View History

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"""
2014-09-30 21:51:14 +00:00
from datetime import datetime, timezone
2012-12-31 19:19:07 +00:00
from hooks import hook
from tools.countdown import countdown_format
2014-08-13 13:53:55 +00:00
nemubotversion = 3.4
2012-12-31 19:19:07 +00:00
from more import Response
2014-09-30 21:51:14 +00:00
yr = datetime.now(timezone.utc).year
yrn = datetime.now(timezone.utc).year + 1
2012-12-31 19:19:07 +00:00
def load(context):
2014-10-04 05:34:30 +00:00
d = datetime(yrn, 1, 1, 0, 0, 0, 0, timezone.utc) - datetime.now(timezone.utc)
2014-09-23 20:27:53 +00:00
add_event(ModuleEvent(interval=0, offset=d.total_seconds(), call=bonneannee))
2012-12-31 19:19:07 +00:00
def bonneannee():
2014-09-30 21:51:14 +00:00
txt = "Bonne année %d !" % yrn
2012-12-31 19:19:07 +00:00
print (txt)
send_response("localhost:2771", Response(txt, "#epitagueule"))
send_response("localhost:2771", Response(txt, "#yaka"))
send_response("localhost:2771", Response(txt, "#epita2014"))
send_response("localhost:2771", Response(txt, "#ykar"))
send_response("localhost:2771", Response(txt, "#42sh"))
send_response("localhost:2771", Response(txt, "#nemubot"))
2012-12-31 19:19:07 +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):
2014-09-30 21:51:14 +00:00
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1, 0, timezone.utc),
"Il reste %s avant la nouvelle année.",
"Nous faisons déjà la fête depuis %s !"),
2012-12-31 19:19:07 +00:00
channel=msg.channel)
@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
2014-09-30 21:51:14 +00:00
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1, 0, timezone.utc),
"Il reste %s avant %d." % ("%s", yr),
"Le premier janvier %d est passé depuis %s !" % (yr, "%s")),
2012-12-31 19:19:07 +00:00
channel=msg.channel)