help with irc bot

This is the place for queries that don't fit in any of the other categories.

help with irc bot

Postby DTSCode » Thu Jan 30, 2014 2:52 pm

im sorry if im posting in the wrong place, but since its not a networking issue rather than a connection issue i assumed it would be better to put this code here. anyways im trying to make an irc bot that records a channel and can play it back based on a range of time. the word it looks for is !Archive, and for now its just supposed to say "Someones talking" and it does, but it says it for everything. could someone tell me why?

Code: Select all
#!/usr/bin/env python

# Libraries
import socket # for connecting to the server
import sys    # for command line arguments
import string # for string manipulating

# IRC Session Variables
Socket = socket.socket() # Socket for connecting to the server

# Server to connect to (default
    Server = sys.argv[1]
    Server = ""

# Channel to connect to (default #cplusplus)
    Channel = sys.argv[2]
    Channel = "#cplusplus"

# Port for Sever to use (default 6667)
    Port = sys.argv[2]
    Port = 6667

Nick       = "Archiver-Bot" # Nickname for the IRC session
RealName   = "Archiver-Bot" # Actual Name for the IRC session
Ident      = "Archiver-Bot" # Identity of the bot
ReadBuffer = ""             # The buffer containing what the server returned
First = True
Record = []
Counter = 0

Socket.connect((Server, Port))
Socket.send("NICK %s\r\n" % Nick)
Socket.send("USER %s %s bla :%s\r\n" % (Ident, Server, RealName))

while True:
    Socket.send("JOIN %s\r\n" % Channel)
    ReadBuffer = ReadBuffer + Socket.recv(1024)
    Temp = string.split(ReadBuffer, "\n")
    Readbuffer = Temp.pop( )

    for Line in Temp:
        Line = string.rstrip(Line)
        Line = string.split(Line)

        if(Line[0] == "PING"):
            Socket.send("PONG %s\r\n" % Line[1])

        if len(Line) > 2:
            if Line[3] == ":!Archive":
                Socket.send("PRIVMSG %s :Someone talked\r\n" % Channel)

        print Record[Counter]
        Counter = Counter + 1
Posts: 5
Joined: Thu Jan 30, 2014 2:41 pm

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 5 guests