sourD
sourD

Reputation: 457

Python IRC Client

import socket
from time import strftime

time = strftime("%H:%M:%S")

irc = 'irc.tormented-box.net'
port = 6667
channel = '#test'
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
print sck.recv(4096)
sck.send('NICK supaBOT\r\n')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN ' + channel + '\r\n')
while True:
    data = sck.recv(4096)
    if data.find('PING') != -1:
       sck.send('PONG ' + data.split() [1] + '\r\n')
    elif data.find ( 'PRIVMSG' ) != -1:
       nick = data.split ( '!' ) [ 0 ].replace ( ':', '')
       if data.find('!op') != -1:
       sck.send('MODE #test +o ' + nick + '\r\n')

When I'm trying to !op nick in IRC I end up op'ing myself Instead of giving +o to the other user, I'm not sure what I have to change in the "nick" variable.. I'll appreciate it if someone can help me.. thanks.

Upvotes: 1

Views: 3899

Answers (2)

Anthony Hiscox
Anthony Hiscox

Reputation: 435

You may find the Supybot project to be of interest, it is an IRC bot written in Python, and it is very easy to create your own plugins, a lot of this extra work is already done for you, so you can just worry about those features you want.

G'Luck!

Supybot Sourceforge

Upvotes: 1

Roger Pate
Roger Pate

Reputation:

You really need to rethink how you're trying to parse messages; as-is I can say "haha !opwned PRIVMSG" to get ops. (For everyone else: PRIVMSG is part of the IRC protocol, not normally said by users.)

However, I don't see the error in your current code, but you've changed what you're really running when you posted to SO (see how the indentation is wrong on the last line, this won't run at all). Did you accidentally change something else important too?

Set yourself up some kind of debug console with raw IRC traffic; it will be immensely valuable. Writing to a simple file works (make sure you flush it and then you can use "tail --follow" to view it as your bot runs). You can then inject your own debug messages too, which will help you debug problems like this. (Eg. You'd include repr(nick) and repr(data) to see what's happening.)

Upvotes: 3

Related Questions