Last active
August 29, 2015 13:56
-
-
Save zeldani/9250157 to your computer and use it in GitHub Desktop.
Criando um irc bot em python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import socket | |
import string | |
import os | |
servidor="irc.freenode.net" | |
porta=6697 | |
nick="zeldani" | |
ident="zeldani" | |
realname="zeldani" | |
canal="#canal" | |
senha="aqui vc coloca a senha do bot, caso ele for registrado" | |
quitmsg="Afk" | |
print 'Conectando...' | |
s=socket.socket( ) | |
s.connect((servidor, porta)) | |
s.send("NICK %s\r\n" % nick) | |
s.send("USER %s %s bla :%s\r\n" % (ident, servidor, realname)) | |
s.send("JOIN :%s\r\n" % canal) | |
s.send ( 'PRIVMSG NickServ :Identify '+ senha+'\r\n') | |
while True: | |
ircmsg = s.recv(2048) | |
print(ircmsg) | |
data = s.recv(4096) | |
print data | |
if data.find ( 'PING' ) != -1: | |
s.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' ) | |
# Se o "!hello" for encontrado na linha de comando, ira mandar no canal a mensagem "Hello World : canal !!!". | |
if data.find(':!hello') != -1: | |
s.send("PRIVMSG %s :%s\r\n"% (canal, "Hello World : " + canal + " !!!")) | |
if data.find(':!quit') != -1: | |
s.send('quit :%s\r\n' % quitmsg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment