minerbot-phoenix/plugins/stevenuniverse.py

50 lines
2.0 KiB
Python

import markovuniverse,plugin,sys
import tvdb_api,tvdb_keys
from pluralslib import plural
tvdb = tvdb_api.Tvdb(apikey=tvdb_keys.api_key,cache=False)
@plugin.group("stevenuniverse","<subcmd> [args]")
def stevenuniverse(bot,channel,nick,subcmd=None,*args):
return False
plugin.alias("su","stevenuniverse")
@stevenuniverse.command("help")
def help(bot,channel,nick,*a):
bot.say(channel,"{}: Current !{} subcommands are {}".format(nick,bot.cmd,", ".join(stevenuniverse.subcmds.keys())))
@stevenuniverse.command("fake-leak")
def fakeleak(bot,channel,nick,*a):
bot.say(channel,nick+": {} - {}".format(*markovuniverse.new_episode()))
SU_EPISODE_FORMAT = "{nick}: Season {ep[airedSeason]}, Episode {ep[airedEpisodeNumber]}: {ep[episodeName]} - \"{ep[overview]}\"; aired {ep[firstAired]}"
@stevenuniverse.command("episode")
def episode(bot,channel,nick,sub,*args):
args = list(args)
sub = args.pop(0) # we already know the subcommand used to call this function so it's not that important to preserve this variable.
if sub=="name":
eps = tvdb["Steven Universe"].search(" ".join(args),key="episodeName")
if len(eps)>1:
if len(eps)<=3:
bot.say(channel,"{}: Please be a bit more specific. (Search returned \"{}\")".format(nick,", ".join(ep["episodeName"] for ep in eps)))
else:
bot.say(channel,"{}: Please be a bit more specific. (Search returned {})".format(nick,plural(len(eps),"episode")))
elif len(eps)==0:
bot.say(channel,"{}: No episode was found by the name {!r}.".format(nick," ".join(args)))
else:
bot.say(channel,SU_EPISODE_FORMAT.format(nick=nick,ep=eps[0]))
elif sub=="number":
if len(args)==1:
assert "x" in args[0],"Usage: !{0} episode number <0x0> OR !{0} episode number 0 0".format(bot.cmd)
season, epnum = (int(x) for x in args[0].split("x"))
else:
season, epnum = (int(x) for x in args[:2])
try:
ep = tvdb["Steven Universe"][season][epnum]
except:
bot.say(channel,"{}: I couldn't find an episode for Season {} Episode {}.".format(nick,season,epnum))
return
bot.say(channel,SU_EPISODE_FORMAT.format(nick=nick,ep=ep))