def run(self): pp("Starting Monitoring Loop") last_start = time.time() if self.config["polling"]["enabled"]: polling = time.time() tick = self.config["polling"]["time"] poll = {"a":0, "b":0, "up":0, "down":0, "left":0, "right":0, "start":0, "select":0} while not exitFlag: if self.config["polling"]["enabled"] and time.time() > (polling + tick): polling = time.time() turn = max(poll.iteritems(), key=operator.itemgetter(1))[0] if poll[turn] != 0: self.game.push_button(turn) print turn poll = dict.fromkeys(poll, 0) if not self.queue.empty(): job = self.queue.get() button = job["msg"] user = job["user"].capitalize() pbutton(user, button) if self.config['start_throttle']['enabled'] and button == 'start': if time.time() - last_start < self.config['start_throttle']['time']: continue last_start = time.time() if self.config["polling"]["enabled"]: poll[button] += 1 else: self.game.push_button(button)
def run(self): last_start = time.time() while True: new_messages = self.irc.recv_messages(1024) if not new_messages: continue for message in new_messages: button = message['message'].lower() username = message['username'] if not self.game.is_valid_button(button): continue if self.config['start_throttle']['enabled'] and button == 'start': if time.time() - last_start < self.config['start_throttle']['time']: continue if button == 'start': last_start = time.time() pbutton(username, button) self.game.push_button(button)
def push_button(self, button): if sys.platform.startswith('win'): win32api.keybd_event(self.button_to_key(button), 0, 0, 0) win32api.keybd_event(self.button_to_key(button), 0, win32con.KEYEVENTF_KEYUP, 0) if sys.platform.startswith('linux'): btn = self.button_to_key(button) if btn is not None: pbutton(nick, btn) keypress(btn)
def run(self): pp("Starting Monitoring Loop") mode = False #false == anarchy : true == democracy throttle_timers = {button:0 for button in self.config['throttled_buttons'].keys()} if self.config["anarchy-democracy"]["enabled"]: vote_size = self.config["anarchy-democracy"]["size"] vote_state = int(round(vote_size / 2)) if self.config["polling"]["enabled"] or self.config["anarchy-democracy"]["enabled"]: polling = time.time() tick = self.config["polling"]["time"] poll = {poll:0 for poll in set(self.config["commands"]) - set(self.config["filted_commands"])} while not exitFlag: if self.config["polling"]["enabled"] or mode and time.time() > (polling + tick): polling = time.time() turn = max(poll.iteritems(), key=operator.itemgetter(1))[0] if poll[turn] != 0: self.to_web({"endpoll": {"winner": turn}}) self.game.push_button(turn) poll = dict.fromkeys(poll, 0) self.to_web({"polling": {"poll": 0}}) if not self.queue.empty(): job = self.queue.get() button = job["msg"] user = job["user"].capitalize() print (pbutton(user, button)) if button not in self.config["filted_commands"]: self.to_web({"button": {"user":user, "button":button, "formated": pbutton(user, button)}}) if button in self.config['throttled_buttons']: if time.time() - throttle_timers[button] < self.config['throttled_buttons'][button]: continue throttle_timers[button] = time.time() if self.config["anarchy-democracy"]["enabled"]: if button == "anarchy" and vote_state != 0: vote_state -= 1 if mode and vote_state < vote_size * 0.50: mode = False print "Set mode to anarchy." if button == "democracy" and vote_state < vote_size: vote_state += 1 if not mode and vote_state > vote_size * 0.80: mode = True print "Set mode to democracy." self.to_web({"anarchy_democracy": {"mode": mode, "size": vote_size, "state": vote_state}}) if button == "anarchy" or button == "democracy": continue if self.config["polling"]["enabled"] or mode: poll[button] += 1 poll_sorted = dict((k, v) for k, v in poll.items() if v > 0) poll_sorted = sorted(poll_sorted.iteritems(), key=lambda x:x[1], reverse=True)[:6] self.to_web({"polling": {"poll": poll_sorted}}) else: self.game.push_button(button)
def run(self): pp("Starting Monitoring Loop") last_start = time.time() mode = False if self.config["anarchy-democracy"]["enabled"]: vote_size = self.config["anarchy-democracy"]["size"] vote_state = int(round(vote_size / 2)) if self.config["polling"]["enabled"] or self.config["anarchy-democracy"]["enabled"]: polling = time.time() tick = self.config["polling"]["time"] poll = {"a":0, "b":0, "up":0, "down":0, "left":0, "right":0, "start":0, "select":0} while not exitFlag: if self.config["polling"]["enabled"] or mode and time.time() > (polling + tick): polling = time.time() turn = max(poll.iteritems(), key=operator.itemgetter(1))[0] if poll[turn] != 0: self.to_web({"endpoll": {"winner": turn}}) self.game.push_button(turn) poll = dict.fromkeys(poll, 0) self.to_web({"polling": {"poll": 0}}) if not self.queue.empty(): job = self.queue.get() button = job["msg"] user = job["user"].capitalize() print (pbutton(user, button)) if self.config["anarchy-democracy"]["show"]: self.to_web({"button": {"user":user, "button":button, "formated": pbutton(user, button)}}) elif button != "anarchy" and button != "democracy": self.to_web({"button": {"user":user, "button":button, "formated": pbutton(user, button)}}) if self.config['start_throttle']['enabled'] and button == 'start': if time.time() - last_start < self.config['start_throttle']['time']: continue last_start = time.time() if self.config["anarchy-democracy"]["enabled"]: if button == "anarchy" and vote_state != 0: vote_state -= 1 if mode and vote_state < vote_size * 0.50: mode = False print "Set mode to anarchy." if button == "democracy" and vote_state < vote_size: vote_state += 1 if not mode and vote_state > vote_size * 0.80: mode = True print "Set mode to democracy." self.to_web({"anarchy_democracy": {"mode": mode, "size": vote_size, "state": vote_state}}) if button == "anarchy" or button == "democracy": continue if self.config["polling"]["enabled"] or mode: poll[button] += 1 poll_sorted = dict((k, v) for k, v in poll.items() if v > 0) poll_sorted = sorted(poll_sorted.iteritems(), key=lambda x:x[1], reverse=True)[:6] self.to_web({"polling": {"poll": poll_sorted}}) else: self.game.push_button(button)
def run(self): pp("Starting Monitoring Loop") last_start = time.time() mode = False if self.config["anarchy-democracy"]["enabled"]: vote_size = self.config["anarchy-democracy"]["size"] vote_state = int(round(vote_size / 2)) if self.config["polling"]["enabled"] or self.config[ "anarchy-democracy"]["enabled"]: polling = time.time() tick = self.config["polling"]["time"] poll = { "a": 0, "b": 0, "up": 0, "down": 0, "left": 0, "right": 0, "start": 0, "select": 0 } while not exitFlag: if self.config["polling"]["enabled"] or mode and time.time() > ( polling + tick): polling = time.time() turn = max(poll.iteritems(), key=operator.itemgetter(1))[0] if poll[turn] != 0: self.to_web({"endpoll": {"winner": turn}}) self.game.push_button(turn) poll = dict.fromkeys(poll, 0) self.to_web({"polling": {"poll": 0}}) if not self.queue.empty(): job = self.queue.get() button = job["msg"] user = job["user"].capitalize() print(pbutton(user, button)) if self.config["anarchy-democracy"]["show"]: self.to_web({ "button": { "user": user, "button": button, "formated": pbutton(user, button) } }) elif button != "anarchy" and button != "democracy": self.to_web({ "button": { "user": user, "button": button, "formated": pbutton(user, button) } }) if self.config['start_throttle'][ 'enabled'] and button == 'start': if time.time( ) - last_start < self.config['start_throttle']['time']: continue last_start = time.time() if self.config["anarchy-democracy"]["enabled"]: if button == "anarchy" and vote_state != 0: vote_state -= 1 if mode and vote_state < vote_size * 0.50: mode = False print "Set mode to anarchy." if button == "democracy" and vote_state < vote_size: vote_state += 1 if not mode and vote_state > vote_size * 0.80: mode = True print "Set mode to democracy." self.to_web({ "anarchy_democracy": { "mode": mode, "size": vote_size, "state": vote_state } }) if button == "anarchy" or button == "democracy": continue if self.config["polling"]["enabled"] or mode: poll[button] += 1 poll_sorted = dict( (k, v) for k, v in poll.items() if v > 0) poll_sorted = sorted(poll_sorted.iteritems(), key=lambda x: x[1], reverse=True)[:6] self.to_web({"polling": {"poll": poll_sorted}}) else: self.game.push_button(button)