h/plugins/pony.py

50 lines
1.2 KiB
Python
Raw Normal View History

2015-11-03 01:18:44 +00:00
from util import hook
from ddate.base import DDate
2015-11-03 01:18:44 +00:00
import datetime
import ponyapi
def get_time(ep):
2015-11-03 01:18:44 +00:00
now = datetime.datetime(2006, 1, 1)
now = now.now()
2015-11-15 16:36:35 +00:00
then = now.fromtimestamp(int(ep["air_date"]))
2015-11-03 01:18:44 +00:00
td = then-now
return now, then, td
@hook.command
def when(inp, say=None):
#"Shows the countdown to the new episode of My Little Pony: Friendship is Magic!"
ep = ponyapi.newest()
now, then, td = get_time(ep)
2015-11-03 01:18:44 +00:00
seasonep = ""
if inp == "discord":
2015-11-15 16:36:35 +00:00
return "%s will air on %s" % (ep["name"], DDate(then))
2015-11-15 16:36:35 +00:00
if ep["is_movie"]:
2015-11-03 01:18:44 +00:00
seasonep = "(a movie)"
else:
2015-11-15 16:36:35 +00:00
seasonep = "(season %d episode %d)" % (ep["season"], ep["episode"])
2015-11-03 01:18:44 +00:00
reply = "%s %s will air on %s in %d days!" % (
2015-11-15 16:36:35 +00:00
ep["name"], seasonep, then.strftime("%a, %d %b %Y %H:%M:%S"),
2015-11-03 01:18:44 +00:00
td.days)
return reply
@hook.command
def randomep(inp):
#"Shows a random episode of My Little Pony: Friendship is Magic"
ep = ponyapi.random()
seasonep = ""
2015-11-15 16:36:35 +00:00
if ep["is_movie"]:
2015-11-03 01:18:44 +00:00
seasonep = "(a movie)"
else:
2015-11-15 16:36:35 +00:00
seasonep = "(season %d episode %d)" % (ep["season"], ep["episode"])
2015-11-03 01:18:44 +00:00
2015-11-15 16:36:35 +00:00
return "%s %s" % (ep["name"], seasonep)