def processCommands(line, sock): user = getUser(line) message = getMessage(line) channel = getChannelname(line) cat1 = Cat() #always check for how much time has passed to mark certain game points if "playCLC" in message: sock.send(("PRIVMSG #" + channel + " :" + initgame + "\r\n").encode('utf-8')) if "$getcat" in message: name = message.replace("$getcat", "") cat1.init(name) catList.append(cat1) # cat1.startTime = time.time() sock.send(("PRIVMSG #" + channel + " :" + getcat(cat1.name) + "\r\n").encode('utf-8')) if "$help" in message: sock.send(("PRIVMSG #" + channel + " :" + helpMessage + "\r\n").encode('utf-8')) #these commands only work while cat1 exists as an instance while isinstance(cat1, Cat): #feeding cat if "$feed" in message: cat1.hunger+=1 feedMsg = "You feed"+cat1.name+", his hunger is now" + cat1.hunger +" out of 10" if cat1.hunger==10: feedMsg += "Your cat is really really full. Please don't feed it anymore or he'll die from overbloating" sock.send(("PRIVMSG #" + channel + " :" + feedMsg + "\r\n").encode('utf-8')) if (time.time() - cat1.startTime) % 2 ==0: #cat loses hunger pts every 5 seconds cat1.hunger -=1 sock.send(("PRIVMSG #" + channel + " :" + cat1.name + "'s hunger is now at " + str(cat1.hunger) + "\r\n").encode('utf-8')) if 0 < cat1.hunger <=2: sock.send(("PRIVMSG #" + channel + " :" + cat1.name + " is starving. :( Please feed it or death from starvation will follow" + "\r\n").encode('utf-8')) if cat1.hunger ==0: sock.send(("PRIVMSG #" + channel + " :" + cat1.name + " has starved to death. You're an awful person" + "\r\n").encode('utf-8')) cat1="" break
readbuffer = readbuffer + s.recv(1024) temp = string.split(readbuffer, "\n") readbuffer = temp.pop() # Iterates through the chunk for line in temp: id = id + 1 print line # Parses lines and writes them to the file if "PRIVMSG" in line: try: # Gets user, message, channel, etc from a line user = getUser(line) message = getMessage(line) channelname = getChannelname(line) owner = getOwner(line) mod = getMod(line) sub = getSub(line) turbo = getTurbo(line) # Though not specified in the data this way, we treat all channel owners as mods if owner == 1: mod = 1 # Writes Message ID, channel, user, date/time, and cleaned message to file. Notes 1 if user is owner/mod/sub/turbo or 0 if not. # Notes 1 if r9k mode or sub mode is enabled, 0 if not. Notes number of seconds of slow mode (0 if off) with open('all' + str(i) + '.csv', 'ab') as fp: ab = csv.writer(fp, delimiter=',') data = [
def processCommands(line, sock): global name, money, hunger, happiness user = getUser(line) message = getMessage(line) channel = getChannelname(line) cat = False if "playCLC" in message: money = 100 sock.send( ("PRIVMSG #" + channel + " :" + initgame + "\r\n").encode('utf-8')) if money == 30: moneymsg = "You only have $30 yet. might want to think about getting a job... or going to work" sock.send( ("PRIVMSG #" + channel + " :" + moneymsg + "\r\n").encode('utf-8')) if not cat: if "$getcat" in message: hunger = 8 happiness = 5 name = message.replace("$getcat", "") cat = True getcat = "Congrats! You're raising a(nother) cat!" + name + " is so excited to move in with you!" sock.send(("PRIVMSG #" + channel + " :" + getcat + "\r\n").encode('utf-8')) if "$help" in message: sock.send(("PRIVMSG #" + channel + " :" + helpMessage + "\r\n").encode('utf-8')) #always check for how much time has passed to mark certain game points if "$work" in message: money += 5 workmsg = "good for you, you decided to get off your butt and go earn some money at work. you now have " + str( money) + " dollars." sock.send( ("PRIVMSG #" + channel + " :" + workmsg + "\r\n").encode('utf-8')) #these commands only work while cat exists as an instance if "$feed" in message: print("feeding") hunger += 1 print(hunger) money -= 5 feedMsg = "You feed" + name + ", his hunger is now " + str( hunger) + " out of 10" if hunger == 10: feedMsg += "Your cat is really really full. Please don't feed it anymore or he'll die from overbloating" sock.send( ("PRIVMSG #" + channel + " :" + feedMsg + "\r\n").encode('utf-8')) if "$play" in message: print("playing") hunger -= 1 print(hunger) playMsg = "You're playing with " + name + "." + name + random.choice( playList) + "." sock.send( ("PRIVMSG #" + channel + " :" + playMsg + "\r\n").encode('utf-8')) if "$pet" in message: print("petting") happiness += 1 petMsg = "You pet " + name + ". " + name + random.choice(petList) + "." sock.send( ("PRIVMSG #" + channel + " :" + petMsg + "\r\n").encode('utf-8')) if "$ignore" in message: happiness -= 1 sock.send(("PRIVMSG #" + channel + " :" + "You ignore " + name + petMsg + "\r\n").encode('utf-8')) if 0 < hunger <= 2: sock.send(( "PRIVMSG #" + channel + " :" + name + " is starving. :( Please feed it or death from starvation will follow" + "\r\n").encode('utf-8')) if hunger == 0: sock.send(( "PRIVMSG #" + channel + " :" + name + " has starved to death. You're an awful person. Please type 'playCLC' to play again." + "\r\n").encode('utf-8')) cat = False name = "" happiness = 5 hunger = 8 return "" if happiness == 0: sock.send(( "PRIVMSG #" + channel + " :" + name + " was so very sad...." + name + " has died from depression. Please type 'playCLC' to play again." + "\r\n").encode('utf-8')) cat = False name = "" happiness = 5 hunger = 8 return ""