def get_users(full_msg): l = [] data = full_msg.split("\r\n") for namegroup in data: if "End of /NAMES list" in namegroup or \ "tmi.twitch.tv " + end_names_num in namegroup: return l namegroup = namegroup.split(" ") if names_num in namegroup: names = namegroup[5:] for name in names: name = name.strip(":") if name != get_username(): l.append(name) print "here - i don't think this should occur." return l
def chat_count(chatroom, verbose=False): global i i = 0 chan = "#" + chatroom nick = get_username() PASS = get_password() sock = socket.socket() sock.connect(("irc.twitch.tv", default_port)) sock.send("PASS " + PASS + "\r\n") sock.send("USER " + nick + " 0 * :" + nick + "\r\n") sock.send("NICK " + nick + "\r\n") full_msg = "" while 1: sock.send("JOIN "+chan+"\r\n") data = remove_non_ascii(sock.recv(1024)) i+=1 if data[0:4] == "PING": sock.send(data.replace("PING", "PONG")) continue full_msg += data #if you keep requesting to JOIN the channel, it will continue returning #more and more names until "End of /NAMES list" if verbose: print data if ":End of /NAMES list" in data: #do we end the search? if verbose: print "returning (\"End of /NAMES list\") due to:" print data return count_users(full_msg) if ":jtv MODE #" in data: if verbose: print "returning (FOUND MODE) due to:" print data return count_users(full_msg) if "366 " + nick in data: #status code for ending the stream of names if verbose: print "returning (366) due to:" print data return count_users(full_msg) if False and "PRIVMSG" in data: #privmsg's only come in after the names list if verbose: print "returning (PRIVMSG) due to:" print data return count_users(full_msg)
def chat_count(chatroom, verbose=False): global i i = 0 chan = "#" + chatroom nick = get_username() PASS = get_password() sock = socket.socket() sock.connect(("irc.twitch.tv", default_port)) sock.send("PASS " + PASS + "\r\n") sock.send("USER " + nick + " 0 * :" + nick + "\r\n") sock.send("NICK " + nick + "\r\n") full_msg = "" while 1: sock.send("JOIN " + chan + "\r\n") data = removeNonAscii(sock.recv(1024)) i += 1 if data[0:4] == "PING": sock.send(data.replace("PING", "PONG")) continue full_msg += data #if you keep requesting to JOIN the channel, it will continue returning #more and more names until "End of /NAMES list" if verbose: print data if ":End of /NAMES list" in data: #do we end the search? if verbose: print "returning (\"End of /NAMES list\") due to:" print data return count_users(full_msg) if ":jtv MODE #" in data: if verbose: print "returning (FOUND MODE) due to:" print data return count_users(full_msg) if "366 " + nick in data: #status code for ending the stream of names if verbose: print "returning (366) due to:" print data return count_users(full_msg) if False and "PRIVMSG" in data: #privmsg's only come in after the names list if verbose: print "returning (PRIVMSG) due to:" print data return count_users(full_msg)
author = data.split('.tmi.twitch.tv',1)[0] s = channel + ' :' message = s.join(data.split(s)[1:]) message = filter(lambda x: x in string.printable, message) log(author, message) if verbose: print (author + ' - ' + message).strip() except IndexError: print print 'MALFORMED DATA - ' + data print 'MALFORMED DATA - ' + data print 'MALFORMED DATA - ' + data print return nick = get_username() PASS = get_password() def endFunc(): global done return done print print "===============================STARTING CHAT INPUT==============================" print "Type '!exit', '!quit', or '!q' to stop recording." start_new_thread(logEvent, ('Log an event (optional): ',)) try: stopper = checkTime() listen(channel, nick, PASS, interpret, endFunc) except SystemExit: print "o"
s = channel + ' :' message = s.join(data.split(s)[1:]) message = filter(lambda x: x in string.printable, message) log(author, message) if verbose: print(author + ' - ' + message).strip() except IndexError: print print 'MALFORMED DATA - ' + data print 'MALFORMED DATA - ' + data print 'MALFORMED DATA - ' + data print return nick = get_username() PASS = get_password() def endFunc(): global done return done print print "===============================STARTING CHAT INPUT==============================" print "Type '!exit', '!quit', or '!q' to stop recording." start_new_thread(logEvent, ('Log an event (optional): ', )) try: stopper = checkTime() listen(channel, nick, PASS, interpret, endFunc)