def run(self, message,user): pre="" for m in message: if pre == m and m in self.temp.keys(): self.temp[m] += 1 elif pre != m: self.temp[m] = 1 pre = m _max = max(self.temp.values()) for i in self.temp: if self.temp[i]==_max: self.count[i]=self.temp[i] self.clearTemp() #if now - last > delta,then exec if datetime.datetime.now() - self.last_time >= self.time_delta: self.last_time = datetime.datetime.now() _max = max(self.count.values()) maxNum=0 for i in self.count: if self.count[i]==_max: maxNum += 1 #if maxOpion >= 2 , return if maxNum>=2 and _max>0: return m = max(self.count.keys(), key=lambda x: self.count[x]) keyholder.holdForSeconds(m,0.05,"VIOLENCE"); logger.log(self.mode,"VIOLENCE", m) self.t.twitch_sendMsg(self.mode.upper()+":"+m.upper()) self.clearCount()
def run(self, message, user): pre = "" for m in message: if pre == m and m in self.temp.keys(): self.temp[m] += 1 elif pre != m: self.temp[m] = 1 pre = m _max = max(self.temp.values()) for i in self.temp: if self.temp[i] == _max: self.count[i] = self.temp[i] self.clearTemp() #if now - last > delta,then exec if datetime.datetime.now() - self.last_time >= self.time_delta: self.last_time = datetime.datetime.now() _max = max(self.count.values()) maxNum = 0 for i in self.count: if self.count[i] == _max: maxNum += 1 #if maxOpion >= 2 , return if maxNum >= 2 and _max > 0: return m = max(self.count.keys(), key=lambda x: self.count[x]) keyholder.holdForSeconds(m, 0.05, "VIOLENCE") logger.log(self.mode, "VIOLENCE", m) self.t.twitch_sendMsg(self.mode.upper() + ":" + m.upper()) self.clearCount()
def run(self, message, user): for m in message: self.count[m] += 1 if datetime.datetime.now() - self.last_time >= self.time_delta: self.last_time = datetime.datetime.now() _max = max(self.count.values()) #if maxOpion >= 2 maxNum = 0 for i in self.count: if self.count[i] == _max: maxNum += 1 if maxNum >= 2 and _max > 0: for i in self.count: if self.count[i] != _max: self.count[i] = -1000 # reset return m = max(self.count.keys(), key=lambda x: self.count[x]) keyholder.holdForSeconds(m, 0.05, "DEMOCRACY") logger.log(self.mode, "DEMOCRACY", m) self.t.twitch_sendMsg(self.mode.upper() + ":" + m.upper()) self.clearCount()
def run(self, message,user): for m in message: self.count[m] += 1 if datetime.datetime.now() - self.last_time >= self.time_delta: self.last_time = datetime.datetime.now() _max = max(self.count.values()) #if maxOpion >= 2 maxNum=0 for i in self.count: if self.count[i]==_max: maxNum += 1 if maxNum>=2 and _max>0: for i in self.count: if self.count[i] != _max: self.count[i] = -1000 # reset return m = max(self.count.keys(), key=lambda x: self.count[x]) keyholder.holdForSeconds(m,0.05,"DEMOCRACY"); logger.log(self.mode, "DEMOCRACY", m) self.t.twitch_sendMsg(self.mode.upper()+":"+m.upper()) self.clearCount()
#Your oauth-key can be generated at http://twitchapps.com/tmi/ username = "******"; key = "oauth:p5s2xoxm08qq80ncspl0z4iop962fm"; t.twitch_connect(username, key); #The main loop while True: #Check for new mesasages new_messages = t.twitch_recieve_messages(); if not new_messages: #No new messages... continue else: for message in new_messages: #Wuhu we got a message. Let's extract some details from it msg = message['message'].lower() username = message['username'].lower() print(username + ": " + msg.encode('utf-8')); #This is where you change the keys that shall be pressed and listened to. #The code below will simulate the key q if "q" is typed into twitch by someone #.. the same thing with "w" #Change this to make Twitch fit to your game! if msg == "w": keyholder.holdForSeconds(msg, 0.3); if msg == "s": keyholder.holdForSeconds(msg, 0.3); if msg == "a": keyholder.holdForSeconds(msg, 0.1); if msg == "d": keyholder.holdForSeconds(msg, 0.1); if msg == "e": keyholder.holdForSeconds(msg, 0.5); if msg == "q": keyholder.holdForSeconds(msg, 0.1); if msg == "t": keyholder.holdForSeconds(msg, 0.5);
#this code checks the settings file to get username and Twitch chat API key #http://twitchapps.com/tmi/ username = settingscheck[0] key = settingscheck[1] t.twitch_connect(username, key) #The main loop while True: #Check for new mesasages new_messages = t.twitch_recieve_messages() #If there are no new messages, continue running if not new_messages: continue else: try: for message in new_messages: #Get message details, username + message msg = message['message'].lower() username = message['username'].lower() print(username + ": " + msg) #loop through each line of list, check if message matchs "comnd", execute "keybrd" for "time" for x in controlscheck: commands = x.split(':') comnd = commands[0] keybrd = commands[1] time = commands[2] if msg == comnd: keyholder.holdForSeconds(keybrd, time) #skip errors, Ignores phone emojis mostly except: continue
k = keypresser.Keypresser() #Enter your twitch username and oauth-key below, and the app connects to twitch with the details. #Your oauth-key can be generated at http://twitchapps.com/tmi/ username = "******" key = "oauth:XXX" t.twitch_connect(username, key) #The main loop while True: #Check for new messages new_messages = t.twitch_recieve_messages() if not new_messages: #No new messages... continue else: for message in new_messages: #Wuhu we got a message. Let's extract some details from it msg = message['message'].lower() username = message['username'].lower() print(username + ": " + msg) #This is where you change the keys that shall be pressed and listened to. #The code below will simulate the key q if "q" is typed into twitch by someone #.. the same thing with "w" #Change this to make Twitch fit to your game! if msg == ">": keyholder.holdForSeconds('right_arrow', 2) if msg == "<": keyholder.holdForSeconds('left_arrow', 2) if msg == "enter": keyholder.holdForSeconds(msg, 2)
for message in new_messages: #Wuhu we got a message. Let's extract some details from it user = message['username'].lower() msg = message['message'].lower() #Broadcaster Only CMD if user == broadcaster and msg in MODES: text = "CHMOD:[ %s ]" % (str)(msg).upper() t.twitch_sendMsg(text) logger.log(mode, user, text) mode = msg elif msg in MODES: vot.run(msg, user, mode) elif user == broadcaster and msg == "!player": t.twitch_sendMsg((str)(keyholder.PLAYER)) elif user == broadcaster and msg == "!counter": t.twitch_sendMsg((str)(keyholder.MSGCOUNT)) else: #Switch by Mode msgList = p.parser(msg) if mode == "normal": for m in msgList: keyholder.holdForSeconds(m, 0.05, user) if mode == "democracy": d.run(msgList, user) if mode == "violence": v.run(msgList, user) if mode == "reverse": for m in msgList: keyholder.holdForSeconds(REVERSE[m], 0.05, user) logger.log(mode, user, msg)
def presser(message): msg = message try: if msg == "w": keyholder.holdForSeconds(message, 0.3) if msg == "s": keyholder.holdForSeconds(message, 0.3) if msg == "a": keyholder.holdForSeconds(message, 0.1) if msg == "d": keyholder.holdForSeconds(message, 0.1) if msg == "e": keyholder.holdForSeconds(message, 0.5) if msg == "q": keyholder.holdForSeconds(message, 0.1) if msg == "t": keyholder.holdForSeconds(message, 0.5) except: print("Clever Girl")
for message in new_messages: #Wuhu we got a message. Let's extract some details from it user = message['username'].lower() msg = message['message'].lower() #Broadcaster Only CMD if user == broadcaster and msg in MODES: text = "CHMOD:[ %s ]" % (str)(msg).upper() t.twitch_sendMsg(text) logger.log(mode,user,text) mode = msg elif msg in MODES: vot.run(msg, user,mode) elif user == broadcaster and msg =="!player": t.twitch_sendMsg((str)(keyholder.PLAYER)) elif user == broadcaster and msg =="!counter": t.twitch_sendMsg((str)(keyholder.MSGCOUNT)) else: #Switch by Mode msgList = p.parser(msg) if mode == "normal": for m in msgList: keyholder.holdForSeconds(m,0.05,user); if mode == "democracy": d.run(msgList,user) if mode == "violence": v.run(msgList,user) if mode == "reverse": for m in msgList: keyholder.holdForSeconds(REVERSE[m],0.05,user); logger.log(mode,user,msg)
import twitch import keypresser import keyholder import os import time import dotenv dotenv.load_dotenv() t = twitch.Twitch() k = keypresser.Keypresser() username = os.getenv("USER") key = os.getenv("TOKEN") t.twitch_connect(username, key) while True: new_messages = t.twitch_recieve_messages() if not new_messages: continue else: for message in new_messages: msg = message['message'].lower() username = message['username'].lower() print((username + ": " + msg).encode('utf-8')) if msg == "w": keyholder.holdForSeconds(msg, 0.3) if msg == "s": keyholder.holdForSeconds(msg, 0.3) if msg == "a": keyholder.holdForSeconds(msg, 0.3) if msg == "d": keyholder.holdForSeconds(msg, 0.3)