transbot: connecting to the IRC Imprimir E-mail
Avaliação do Usuário: / 0
PiorMelhor 
Projects - transbot
Escrito por MDK   
Seg, 15 de Junho de 2009 14:03

  Hey guys, I'm here again, now with some code on how I do to connect to some IRC server using Python, on the Translation Bot (trully I found another bot with the same name, but I'll not change it ;p ):

  First, we need to add these modules:

import sys
import socket

  With it, we can define some constants:

NETWORK = 'some.irc.server' # server to connect
PORT = 6667
NICK = 'transbot' # the nick used for the bot
PASSWORD = 'bot_password' # used if you register the bot nick
IDENT = 'transbot'
REALNAME = ':MDK\'s Translation Bot'
OWNER = 'xMDKx' # yeah, it's me on anonnet and on freenode
CHANNEL = '#some_channel' # the initial channel to join

  Cool! Right now we can connect to IRC simply doing:

irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((NETWORK, PORT))

  And now, just to enter on some channel (and identify):

send('NICK %s' % NICK)
send('USER %s %s %s %s' % (IDENT, NICK, NICK, REALNAME))
send('NICKSERV IDENTIFY %s ' % PASSWORD)
send('JOIN %s' % CHANNEL)

  Now your bot is connected to the NETWOR (server) and joined on the CHANNEL that you specify.

  For just grab the messages on the channel, do it:

while True:
        data = irc.recv(SOME_SIZE) # with size like 512 bytes, for ex.

        print data # just print server messages

  And it's all for today, folks! Soon I'll post some tips on how to parse the messages grabbed from the channel. See ya!

Última atualização em Seg, 15 de Junho de 2009 14:48
 

Add your comment

SmileCoolCrying or Very SadEmbarrassedA Smoker/Foot in mouthSadUser is an angel (at heart, at least)A Kiss/Lips Are SealedLaughingBiting one's tongue/Put Your Money Where Your Mouth IsBeen Smacked In The Mouth/Wears A Brace/My lips are sealeSurprisedSticking Out TongueConfusedWinkYelling
Your name:
Título:
Comment:

Queremos saber...

Da onde surgiu o homem?
 
Nós temos 38 visitantes online

Tags

Login



Valid XHTML and CSS.