[bonneannee] Unharcode channel to send message on 1 January
This commit is contained in:
parent
b6c5bf4f10
commit
4f27232fd4
@ -14,28 +14,42 @@ from more import Response
|
|||||||
yr = datetime.now(timezone.utc).year
|
yr = datetime.now(timezone.utc).year
|
||||||
yrn = datetime.now(timezone.utc).year + 1
|
yrn = datetime.now(timezone.utc).year + 1
|
||||||
|
|
||||||
def load(context):
|
|
||||||
d = datetime(yrn, 1, 1, 0, 0, 0, 0, timezone.utc) - datetime.now(timezone.utc)
|
|
||||||
add_event(ModuleEvent(interval=0, offset=d.total_seconds(), call=bonneannee))
|
|
||||||
|
|
||||||
def bonneannee():
|
def load(context):
|
||||||
txt = "Bonne année %d !" % yrn
|
if not CONF or not CONF.hasNode("sayon"):
|
||||||
print (txt)
|
print("You can append in your configuration some balise to "
|
||||||
send_response("localhost:2771", Response(txt, "#epitagueule"))
|
"automaticaly wish an happy new year on some channels like:\n"
|
||||||
send_response("localhost:2771", Response(txt, "#yaka"))
|
"<sayon hostid=\"nemubot@irc.freenode.net:6667\" "
|
||||||
send_response("localhost:2771", Response(txt, "#epita2014"))
|
"channel=\"#nemutest\" />")
|
||||||
send_response("localhost:2771", Response(txt, "#ykar"))
|
|
||||||
send_response("localhost:2771", Response(txt, "#42sh"))
|
def bonneannee():
|
||||||
send_response("localhost:2771", Response(txt, "#nemubot"))
|
txt = "Bonne année %d !" % yrn
|
||||||
|
print(txt)
|
||||||
|
if CONF and CONF.hasNode("sayon"):
|
||||||
|
for sayon in CONF.getNodes("sayon"):
|
||||||
|
if "hostid" not in sayon or "channel" not in sayon:
|
||||||
|
print("Error: missing hostif or channel")
|
||||||
|
continue
|
||||||
|
srv = sayon["hostid"]
|
||||||
|
chan = sayon["channel"]
|
||||||
|
send_response(srv, Response(txt, chan))
|
||||||
|
|
||||||
|
d = datetime(yrn, 1, 1, 0, 0, 0, 0,
|
||||||
|
timezone.utc) - datetime.now(timezone.utc)
|
||||||
|
add_event(ModuleEvent(interval=0, offset=d.total_seconds(),
|
||||||
|
call=bonneannee))
|
||||||
|
|
||||||
|
|
||||||
@hook("cmd_hook", "newyear")
|
@hook("cmd_hook", "newyear")
|
||||||
@hook("cmd_hook", str(yrn), yrn)
|
@hook("cmd_hook", str(yrn), yrn)
|
||||||
def cmd_newyear(msg, yr):
|
def cmd_newyear(msg, yr):
|
||||||
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1, 0, timezone.utc),
|
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1, 0,
|
||||||
"Il reste %s avant la nouvelle année.",
|
timezone.utc),
|
||||||
"Nous faisons déjà la fête depuis %s !"),
|
"Il reste %s avant la nouvelle année.",
|
||||||
|
"Nous faisons déjà la fête depuis %s !"),
|
||||||
channel=msg.channel)
|
channel=msg.channel)
|
||||||
|
|
||||||
|
|
||||||
@hook("cmd_rgxp", data=yrn, regexp="^[0-9]{4}$")
|
@hook("cmd_rgxp", data=yrn, regexp="^[0-9]{4}$")
|
||||||
def cmd_timetoyear(msg, cur):
|
def cmd_timetoyear(msg, cur):
|
||||||
yr = int(msg.cmds[0])
|
yr = int(msg.cmds[0])
|
||||||
@ -43,7 +57,9 @@ def cmd_timetoyear(msg, cur):
|
|||||||
if yr == cur:
|
if yr == cur:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1, 0, timezone.utc),
|
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1, 0,
|
||||||
"Il reste %s avant %d." % ("%s", yr),
|
timezone.utc),
|
||||||
"Le premier janvier %d est passé depuis %s !" % (yr, "%s")),
|
"Il reste %s avant %d." % ("%s", yr),
|
||||||
|
"Le premier janvier %d est passé "
|
||||||
|
"depuis %s !" % (yr, "%s")),
|
||||||
channel=msg.channel)
|
channel=msg.channel)
|
||||||
|
Loading…
Reference in New Issue
Block a user