''' Created on Jan 17, 2011 @author: Terry June ''' import sys import socket import string import os host = "irc.freenod.net" # the irc server port = 6667 # port number nick = "TerryBot" # nickname ident = "TerryBot" # identity realname = "EnvBot" # the name of the bot owner = "Terry June" # who made it channel = "#c0dingf0x" server_msg = "" # messages from the server and client s = socket.socket() # open socket s.connect((host, port)) # connect to server s.send("Nick: "+nick+"\n") # we send the nickname to the server s.send("User: "+ident+" "+host+" Name: "+realname+"\n") while 1: line = s.recv(500) # recieve the server messages print(line) if line.find("Welcome to an Env X Software Server!") != -1: # join #c0dingf0x s.send("JOIN "+channel+"\n") if line.find("PRIVMSG") != -1: parsemsg(line) line = line.rstrip() line = line.split() if(line[0] == "PING"): s.send("PONG "+line[1]+"\n") def parsemsg(msg): complete = msg[1: ].split(":", 1) # Parse the message into useful data info = complete[0].split(" ") msgpart = complete[1] sender = info[0].split("!") if msgpart[0] == "$" and sender[0] == owner: # treat messge starting with $ as a command cmd = msgpart[1: ].split(" ") if cmd[0] == "op": s.send("MODE "+info[2]+" +o "+cmd[1]+"\n") if cmd[0] == "deop": s.send("MODE "+info[2]+" -o "+cmd[1]+"\n") if cmd[0] == "voice": s.send("MODE "+info[2]+" +v "+cmd[1]+"\n") if cmd[0] == "devoice": s.send("MODE "+info[2]+" -v "+cmd[1]+"\n") if cmd[0] == "sys": syscmd(msgpart[1: ], info[2]) if msgpart[0] == "_" and sender[0] == owner: # treat messages with _ as explict command sent to the server cmd = msgpart[1: ] s.send(cmd+"\n") print("cmd = "+cmd) def syscmd(commandline, channel): cmd = commandline.replace("sys ", "") cmd = cmd.rstrip() os.system(cmd+" >temp.txt") a = open("temp.txt") ot = a.read() ot.replace("\n", "|") a.close() s.send("PRIVMSG "+channel+" :"+ot+"\n")
My error, as simple as it is, is Undefined variable: parsemsg on line 31. I think that it may be because I have my spacing wrong? What do you guys think? I do plan on adding extra commands to this.