python irc bots

so im writing a python irc bot <source here: http://pastebin.com/ZMSGK0Nm > and i have one issue left before i finish v2 (i know the code is bad. ill clean it up at the end). no matter what i use as the condition in the if statement in CleanInput it wont catch the "\x01" at the beginning and end of ACTION responses, but it also wont catch ACTION and writes it to a file
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


Last edited on
sorry i didnt make myself clear. ACTION was being written to the file and I wanted to stop that, but it wasnt working. i fixed that now

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/

alright ill take a look at that and fix it when i get home

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)
noted. will fix

Also You should implement classes soon. It can get way out of hand real fast without classes.
alright. what should go into what class? im pretty new to python so i dont know whats appropriate to go into classes and not

I would highly suggest to fix cleaning code now.
alright ill do that then

as to the last: in my delerious state, i saw i had the tab here open and forgot i made an account on that site. your right i probably should have made it there
Topic archived. No new replies allowed.