Ejemplo n.º 1
0
    def initialize(self, adaptor):
        self.adaptor = adaptor

        vote = adaptor.trigger_factory.create_trigger("!vote")
        voter = CodeResponse(0, self.RegisterVote)
        voter.addTrigger(vote)

        openpoll = adaptor.trigger_factory.create_trigger("!openpoll")
        openpollr = CodeResponse(0, self.OpenPollResponse)
        openpollr.addTrigger(openpoll)

        rankingst = adaptor.trigger_factory.create_trigger("!movies")
        rankingsr = Response(
            MovieNightPoll.RankingsMessage.format(self.spreadsheetUrl), 30)
        rankingsr.addTrigger(rankingst)

        self.poll = PollWriter(self.spreadsheetName)

        #prepare timers
        self.submissionWindowTimer = None
        self.intervalTimer = Timer(10, self.IntervalTick)
        self.intervalTimer.start()

        self.PollOpen = False

        self.voters = []
        return
Ejemplo n.º 2
0
    def __init__(self, eevee, settings=None):
        super(Hunger, self).__init__(settings)
        self.eevee = eevee

        eatR = CodeResponse(5, self.printEatCommands)
        treatR = CodeResponse(5, self.treat)

        eatT = eevee.adaptor.trigger_factory.create_trigger("!eat")
        treatT = eevee.adaptor.trigger_factory.create_trigger("!treat")

        eatR.addTrigger(eatT)
        treatR.addTrigger(treatT)
Ejemplo n.º 3
0
    def __init__(self, eevee, settings=None):
        super(Happiness, self).__init__(settings)
        self.eevee = eevee

        cuddleResponse = CodeResponse(15, self.cuddle)
        eeveeResponse = CodeResponse(5, self.printPlayCommands)

        cuddleTrigger = eevee.adaptor.trigger_factory.create_trigger("!cuddle")
        eeveeTrigger = eevee.adaptor.trigger_factory.create_trigger("!play")

        cuddleResponse.addTrigger(cuddleTrigger)
        eeveeResponse.addTrigger(eeveeTrigger)
Ejemplo n.º 4
0
    def initialize(self, adaptor):
        self.adaptor = adaptor
        self.counters = {}

        with codecs.open(self.file, encoding="utf-8-sig", mode="r") as f:
            try:
                fileCounters = json.load(f, encoding="utf-8")
                for counterName in fileCounters:
                    counter = Counter.fromSettings(counterName,
                                                   fileCounters[counterName])
                    self.counters[counterName] = counter
            except ValueError:
                print "failed to load {0}".format(f)

        for ctr in self.counters:
            self.createCounterTriggers(self.counters[ctr])

        t = adaptor.trigger_factory.create_trigger("!" + self.groupname)
        r = CodeResponse(10, self.AddCounter)
        r.addTrigger(t)
        return
Ejemplo n.º 5
0
    def initialize(self, adaptor):
        t = adaptor.trigger_factory\
            .create_regex_trigger(r".*KappuNadeshiko.*")
        t2 = adaptor.trigger_factory\
            .create_regex_trigger(r".*KappuRin.*")

        r = CodeResponse(10, self.SendMessage, 'KappuNadeshiko')
        r2 = CodeResponse(10, self.SendMessage, 'KappuRin')

        r.addTrigger(t)
        r2.addTrigger(t2)

        server = threading.Thread(target=self.ConnectionHandler.run_forever)
        server.daemon = True

        ThreadingSimpleServer.Start()
        server.start()
        return
Ejemplo n.º 6
0
    def __init__(self, twitchConnection, folder):
        super(PokeHealthGame, self).__init__(twitchConnection)

        eventsListFile = os.path.join(folder, "Events.json")
        self.settingsFile = os.path.join(folder, "PokeHealthGame.json")

        self.events = EventList(PokeHealthGameEvent, eventsListFile)

        with codecs.open(self.settingsFile, encoding="utf-8-sig", mode="r") as f:
            settings = json.load(f, encoding="utf-8")

            if 'Balance' in settings:
                self.balance = settings['Balance']
            else:
                self.balance = 0

            self.queue = [PokeHealthGameEvent.fromSettings(recentEvent)
                          for recentEvent in settings['Queue']]
            self.rewardPoints = settings['RewardPoints']
            self.purchases = settings['Purchases']
            self.players = settings['Players']

            t = UserSpecificTrigger('!{}'.format('Purchase'), self.players)
            r = CodeResponse(10, self.spend_points)
            r.addTrigger(t)
            self.triggers.append(t)

            t1 = UserSpecificTrigger('!{}'.format('donation'), self.players)
            r1 = CodeResponse(10, self.add_donation_points)
            r1.addTrigger(t1)
            self.triggers.append(t1)

            t2 = UserSpecificTrigger('!{}'.format('follow'), self.players)
            r2 = CodeResponse(10, self.add_follow_points)
            r2.addTrigger(t2)
            self.triggers.append(t2)

            tlife = UserSpecificTrigger('!{}'.format('life'), self.players)
            rlife = CodeResponse(0, self.disposition_event)
            rlife.addTrigger(tlife)
            self.triggers.append(tlife)

            tbalance = Trigger("!{}".format("balance"))
            rbalance = CodeResponse(10, self.print_balance)
            rbalance.addTrigger(tbalance)
            self.triggers.append(tbalance)

        self.connection.EventReceived.add(self.eventReceived)

        self.ConnectionHandler = None
        self.start_server('127.0.0.1', 1112)

        webServer = ThreadingSimpleServer(('127.0.0.1', 8000),
                                          SimpleHTTPServer.SimpleHTTPRequestHandler)

        webServerThread = threading.Thread(target=webServer.serve_forever)
        webServerThread.daemon = True
        webServerThread.start()
        return
Ejemplo n.º 7
0
 def createCounterTriggers(self, ctr):
     t = self.adaptor.trigger_factory.create_trigger("!" + ctr.name)
     r = CodeResponse(10, self.increment, ctr)
     r.addTrigger(t)
     return