1

Here is my trouble: The Bot loads the IRC information fine, but when its suppose to Identify itself, he doesn't.

The following is the relevant part of the code. I guess the problem is on line 9 but I can't figure out why.

import socket

server = #ServerName
channel = #ChannelName
botnick = #BotName
password = #Password (string)

def connect(channel, password): # This function is used on connect.
  ircsock.send("PRIVMSG" + " :NICKSERV Identify " + password +"\n") #Problem Here
  ircsock.send("JOIN "+ channel +"\n")

ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +":Just testing .\n") # user authentication
ircsock.send("NICK "+ botnick +"\n")

connect(channel, password) #Join the channel and identify the nick using the functions we previously defined

Thanks in advance.

Solution: By setting the connect function as posted, it is the first thing to be called Then the server was trying to connect before having USER / NICK.

    def create_connection():
    global ircsock
    ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667
    ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +":This bot is a result of GStones mastery .\n") # user authentication
    ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot
    time.sleep(5)
    connect(channel, password) # Join the channel and identify the nick using the functions we previously defined

create_connection()

Thanks i\OFF

  • ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) – Afonso Pinto Aug 27 '15 at 12:40
  • The bot enters into the irc server but misses to execute the connect function so the NickServ ask for identify command: "NOTICE Botman :This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify " – Afonso Pinto Aug 27 '15 at 13:05
  • Also try using a different botnick. – ρss Aug 27 '15 at 13:20

1 Answers1

3

You have not created a socket, so the connection will not be established.

ircsock = socket.socket (socket.AF_INET, socket.SOCK_STREAM) creates a socket.

Also, you need to connect to the server, before using ircsock.send().

ircsock.connect ((server, serverPort)) connects to the server. This example should work:

import socket

server = #ServerName
serverPort = #Server Port number
channel = #ChannelName
botnick = #BotName
password = #Password (string)

def connect(channel, password): # This function is used on connect.
  ircsock = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
  ircsock.connect ((server, serverPort))
  ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +":Just testing .\n") # user authentication
  ircsock.send("NICK "+ botnick +"\n")
  ircsock.send("PRIVMSG" + " NICKSERV :identify " + password +"\n") #Problem Here
  ircsock.send("JOIN "+ channel +"\n")

connect(channel, password) #Join the channel and identify the nick using the functions we previously defined
ρss
  • 5,115
  • 8
  • 43
  • 73
  • I had omitted that part of code. I already edited the post with the connection to the socket. But thanks for the help anyway. – Afonso Pinto Aug 27 '15 at 12:50
  • Ok, I was not aware of that because in the original post you didn't mention that part of the code. Please try the answer from sideshowbarker & let us know if it worked? – ρss Aug 27 '15 at 12:53
  • My apologies. Already tried. Unfortunately it failed. The code runs without error, and the bot accesses the irc but does not identify the nick – Afonso Pinto Aug 27 '15 at 12:56
  • Try using the same code for some free IRC chat server & channel instead. It might be that the code is working fine but the IRC server or channel settings are blocking the bot. Just a guess. – ρss Aug 27 '15 at 13:01
  • It doens't seem so because the bot executes other functions like ping and a simple hello interaction. In any case I will try it. – Afonso Pinto Aug 27 '15 at 13:08