Just splice off the first 2 chars and last char and output it to the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
def CleanInput(Line):
if not Line[1] in ["PRIVMSG", "JOIN", "PART", "QUIT"]: return ""
else:
if Line[1] == "JOIN": return ("[%s] %s has joined\n" % (GetTimeStamp(), GetNick(Line[0])))
elif Line[1] == "PART": return ("[%s] %s has left\n" % (GetTimeStamp(), GetNick(Line[0])))
elif Line[1] == "QUIT": return ("[%s] %s has left: %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[3:])))
else:
#Line[3] = Line[3].replace(":", "")
#if Line[3] == (":" + chr(1) + "ACTION"):
if Line[3].endswith('ACTION'):
#Line[-1] = Line[-1].replace("x01", "")
return ("[%s] %s %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[3:])[2:-1]))
else: return ("[%s] <%s> %s\n" % (GetTimeStamp(), GetNick(Line[0]), ' '.join(Line[3:])[1:]))
|
--output--
1 2
|
[8:20:5] <metulburr> test
[8:20:8] metulburr ACTION test
|
Also regarding your code:
def GetNick(Domain):
Its Pythonic to leave first char capped names to classes only. You are capping local variables, function names, etc. It makes it a lot easier for python programmers to read by following PEP guidlines
http://www.python.org/dev/peps/pep-0008/
Temp = string.split(ServerBuffer, "\n")
This is redundant. The string module is pretty much useless in python excpet for using the constants in it. Everything in python is an object, thus you can just simplify that by doing:
Temp = ServerBuffer.split()
You dont have to define it by newline character either because the newline character is split()'s default delimter.
You can find all the str methods:
>>> help(str)
Also You should implement classes soon. It can get way out of hand real fast without classes.
ill clean it up at the end |
I would highly suggest to fix cleaning code now. The reason is, the program will continue to grow and grow, eventually leaving you with this enormous program to fix a ton of small tedious fixes.
https://github.com/metulburr/ircbot/blob/master/metulbot.py
my first IRC bot started out as yours, and now i wish i changed things at first, instead i keep adding to it, etc. and now its so big and badly coded, that i dont want to touch it at all.
Last but not least....Why did you post on a c++ forum a question regarding python? You would have numerous people answering your question by now if this question was on a python forum, each having a different way to do that given task, instead its been 8 hours with no response. This forum is quite helpful:
http://python-forum.org/index.php