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
|
|
|
|
2015-02-11 17:12:39 +00:00
|
|
|
from nemubot import context
|
2015-01-04 22:57:09 +00:00
|
|
|
from nemubot.event import ModuleEvent
|
2015-01-03 19:34:44 +00:00
|
|
|
from nemubot.hooks import hook
|
|
|
|
from nemubot.tools.countdown import countdown_format
|
2014-08-12 18:10:19 +00:00
|
|
|
|
2015-07-07 10:34:00 +00:00
|
|
|
nemubotversion = 4.0
|
2012-12-31 19:19:07 +00:00
|
|
|
|
2014-09-26 16:00:22 +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
|
|
|
|
2014-11-10 20:10:09 +00:00
|
|
|
|
2014-08-12 18:10:19 +00:00
|
|
|
def load(context):
|
2015-02-11 17:12:39 +00:00
|
|
|
if not context.config or not context.config.hasNode("sayon"):
|
2014-11-10 20:10:09 +00:00
|
|
|
print("You can append in your configuration some balise to "
|
|
|
|
"automaticaly wish an happy new year on some channels like:\n"
|
|
|
|
"<sayon hostid=\"nemubot@irc.freenode.net:6667\" "
|
|
|
|
"channel=\"#nemutest\" />")
|
|
|
|
|
|
|
|
def bonneannee():
|
|
|
|
txt = "Bonne année %d !" % yrn
|
|
|
|
print(txt)
|
2015-02-11 17:12:39 +00:00
|
|
|
if context.config and context.config.hasNode("sayon"):
|
|
|
|
for sayon in context.config.getNodes("sayon"):
|
2014-11-10 20:10:09 +00:00
|
|
|
if "hostid" not in sayon or "channel" not in sayon:
|
|
|
|
print("Error: missing hostif or channel")
|
|
|
|
continue
|
|
|
|
srv = sayon["hostid"]
|
|
|
|
chan = sayon["channel"]
|
2015-02-11 17:12:39 +00:00
|
|
|
context.send_response(srv, Response(txt, chan))
|
2014-11-10 20:10:09 +00:00
|
|
|
|
|
|
|
d = datetime(yrn, 1, 1, 0, 0, 0, 0,
|
|
|
|
timezone.utc) - datetime.now(timezone.utc)
|
2015-02-11 17:12:39 +00:00
|
|
|
context.add_event(ModuleEvent(interval=0, offset=d.total_seconds(),
|
|
|
|
call=bonneannee))
|
2014-11-10 20:10:09 +00:00
|
|
|
|
2012-12-31 19:19:07 +00:00
|
|
|
|
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):
|
2014-11-10 20:10:09 +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)
|
|
|
|
|
2014-11-10 20:10:09 +00:00
|
|
|
|
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):
|
2015-07-07 10:34:00 +00:00
|
|
|
yr = int(msg.cmd)
|
2012-12-31 19:19:07 +00:00
|
|
|
|
|
|
|
if yr == cur:
|
|
|
|
return None
|
|
|
|
|
2014-11-10 20:10:09 +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)
|