From 3820b8bf59fb222257af324163a20fa08b862724 Mon Sep 17 00:00:00 2001 From: Chad Nelson Date: Fri, 4 Oct 2013 14:46:26 -0400 Subject: [PATCH] Wil not select channel users who opt out with not me --- plugins/Cast/plugin.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/Cast/plugin.py b/plugins/Cast/plugin.py index 0861955..c9c4c18 100644 --- a/plugins/Cast/plugin.py +++ b/plugins/Cast/plugin.py @@ -35,6 +35,7 @@ import supybot.ircdb as ircdb import supybot.ircutils as ircutils import supybot.callbacks as callbacks +import supybot.dbi as dbi import random import re @@ -139,9 +140,29 @@ } class Cast(callbacks.Plugin): - + + class DB(plugins.DbiChannelDB): + class DB(dbi.DB): + class Record(dbi.Record): + __fields__ = [ + 'op' + ] + + + def __init__(self, irc): + self.__parent = super(Cast, self) + self.__parent.__init__(irc) + self.db = plugins.DB('NotMe',{'flat':self.DB})() + + def _notme(self, channel): + result = [r.op for r in self.db.select(channel, lambda x: True)] + result.sort() + return result + + def _query_tmdb(self, cmd, args): url = "http://api.themoviedb.org/2.1/%s/en/json/%s/%s" % (cmd,TMDBK,urllib.quote(str(args))) + print url doc = web.getUrl(url, headers=HEADERS) try: json = simplejson.loads(doc) @@ -153,7 +174,7 @@ def tmdb(self, irc, msg, args, channel, opts, play): """[] Cast from the current channel participants using information retrieved from themoviedb.org.""" random.seed() - nicks = list(irc.state.channels[channel].users) + nicks = list(set(irc.state.channels[channel].users) - set(self._notme(channel))) random.shuffle(nicks) maxlen = 20 @@ -245,7 +266,7 @@ def cast(self, irc, msg, args, channel, work_type, thing): return False random.seed() - nicks = list(irc.state.channels[channel].users) + nicks = list(set(irc.state.channels[channel].users) - set(self._notme(channel))) random.shuffle(nicks) record = None