The code that I wrote for assembling messages isn't behaving as I thought it would

Back again with a small issue, the code below prints two messages, the first is supposed to add “marker” to the end of the message, the second prints the username of the sender and the message together. But as I said, the first is “supposed to”, it doesn’t.

it prints the following if I send “hello world” in chat:

leviporton: hello world

instead of adding “marker” at the end of the message, it replaces the first six characters of the string. But why? Previous versions of my code (that couldn’t handle : s in the middle of messages, including D:) didn’t have this problem, and it’s causing checks further down to return False when they shouldn’t either. Please help.

while True:
readbuffer = readbuffer + s.recv(1024)
temp = string.split(readbuffer, "\n")
readbuffer = temp.pop()

for line in temp:
    if "PING" in line and "PRIVMSG" not in line:
        if "stopbot" in line:
            parts = string.split(line, ":")
            if "QUIT" in parts[1] and "JOIN" in parts[1] and "PART" in parts[1] and "USERSTATE" in parts[1] and "ROOMSTATE" in parts[1]:
            if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1] and "USERSTATE" not in parts[1] and "ROOMSTATE" not in parts[1]:
                if "PRIVMSG" in line:
                    count = -1
                    for part in parts:
                        count += 1
                        if "PRIVMSG" in parts[count]:
                            msgThreshhold = count + 1 #msgThreshhold is the part in which the start of the message is found
                        msgPartcount = 2
                    while msgPartcount < msgThreshhold:
                        msgPartcount += 1
                    message = ""
                    while msgPartcount >= msgThreshhold and not msgPartcount > (len(parts) - 1):
                        if msgPartcount == msgThreshhold:
                            message = parts[msgThreshhold]
                            msgPartcount += 1
                            message = message + ":" + parts[msgPartcount]
                            msgPartcount += 1
                    print(message + "marker")
                    usernamesplit = string.split(parts[msgThreshhold - 1], "!")
                    username = usernamesplit[0]
                    if MOTD == False:
                        print(username + ": " + message)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.