add IMDb plugin, courtesy of GhettoWizard
This commit is contained in:
parent
d826e2ad83
commit
2171ebd72f
|
@ -0,0 +1,21 @@
|
||||||
|
# IMDb lookup plugin by Ghetto Wizard (2011).
|
||||||
|
|
||||||
|
from util import hook, http
|
||||||
|
|
||||||
|
|
||||||
|
@hook.command
|
||||||
|
def imdb(inp):
|
||||||
|
'''.imdb <movie> -- gets information about <movie> from IMDb'''
|
||||||
|
|
||||||
|
content = http.get_json("http://www.imdbapi.com/", t=inp)
|
||||||
|
|
||||||
|
if content['Response'] == 'Movie Not Found':
|
||||||
|
return 'movie not found'
|
||||||
|
elif content['Response'] == 'True':
|
||||||
|
content['URL'] = 'http://www.imdb.com/title/%(ID)s' % content
|
||||||
|
|
||||||
|
return "\x02%(Title)s\x02 (%(Year)s) (%(Genre)s): %(Plot)s " \
|
||||||
|
"\x02%(Runtime)s\x02. \x02%(Rating)s/10\x02 with " \
|
||||||
|
"\x02%(Votes)s\x02 votes. %(URL)s" % content
|
||||||
|
else:
|
||||||
|
return 'unknown error'
|
|
@ -12,6 +12,11 @@ def add_quote(db, chan, nick, add_nick, msg):
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def del_quote(db, chan, nick, add_nick, msg):
|
||||||
|
db.execute('''update quote set deleted = 1 where
|
||||||
|
chan=? and lower(nick)=lower(?) and msg=msg''')
|
||||||
|
db.commit()
|
||||||
|
|
||||||
def get_quotes_by_nick(db, chan, nick):
|
def get_quotes_by_nick(db, chan, nick):
|
||||||
return db.execute("select time, nick, msg from quote where deleted!=1 "
|
return db.execute("select time, nick, msg from quote where deleted!=1 "
|
||||||
"and chan=? and lower(nick)=lower(?) order by time",
|
"and chan=? and lower(nick)=lower(?) order by time",
|
||||||
|
@ -90,3 +95,48 @@ def quote(inp, nick='', chan='', db=None):
|
||||||
selected_quote = quotes[num - 1]
|
selected_quote = quotes[num - 1]
|
||||||
|
|
||||||
return format_quote(selected_quote, num, n_quotes)
|
return format_quote(selected_quote, num, n_quotes)
|
||||||
|
|
||||||
|
|
||||||
|
@hook.command('qdel', adminonly=True)
|
||||||
|
@hook.command
|
||||||
|
def quotedelete:
|
||||||
|
".qdel/.quotedelete [#chan] [nick] <#n>/.quote add <nick> <msg> -- deletes " \
|
||||||
|
"<#n>th quote by <nick> or from <#chan> (adminonly)"
|
||||||
|
|
||||||
|
retrieve = re.match(r"(\S+)(?:\s+#?(-?\d+))?$", inp)
|
||||||
|
retrieve_chan = re.match(r"(#\S+)\s+(\S+)(?:\s+#?(-?\d+))?$", inp)
|
||||||
|
|
||||||
|
if retrieve:
|
||||||
|
select, num = retrieve.groups()
|
||||||
|
|
||||||
|
by_chan = False
|
||||||
|
if select.startswith('#'):
|
||||||
|
by_chan = True
|
||||||
|
quotes = get_quotes_by_chan(db, select)
|
||||||
|
else:
|
||||||
|
quotes = get_quotes_by_nick(db, chan, select)
|
||||||
|
elif retrieve_chan:
|
||||||
|
chan, nick, num = retrieve_chan.groups()
|
||||||
|
|
||||||
|
quotes = get_quotes_by_nick(db, chan, nick)
|
||||||
|
else:
|
||||||
|
return quote.__doc__
|
||||||
|
|
||||||
|
n_quotes = len(quotes)
|
||||||
|
|
||||||
|
if not n_quotes:
|
||||||
|
return "no quotes found"
|
||||||
|
|
||||||
|
num = int(num)
|
||||||
|
|
||||||
|
if num > n_quotes or (num < 0 and num < -n_quotes):
|
||||||
|
return "I only have %d quote%s for %s" % (n_quotes,
|
||||||
|
('s', '')[n_quotes == 1], select)
|
||||||
|
elif num < 0:
|
||||||
|
selected_quote = quotes[num]
|
||||||
|
num = n_quotes + num + 1
|
||||||
|
else:
|
||||||
|
selected_quote = quotes[num - 1]
|
||||||
|
|
||||||
|
return format_quote(selected_quote, num, n_quotes)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue