Created
October 28, 2015 13:46
-
-
Save localdevm/0a6f76c7f8346747b8ad to your computer and use it in GitHub Desktop.
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 some necessary libraries. | |
import socket | |
# Some basic variables used to configure the bot | |
server = "irc.freenode.net" # Server | |
channel = "##apelektronica" # Channel | |
botnick = "FailBot" # Your bots nick | |
ping = "PONG :pingis\n" | |
def ping(): # This is our first function! It will respond to server Pings. | |
ircsock.send(ping.encode("utf-8") | |
stuur = "PRIVMSG "+ chan +" :"+ msg +"\n" | |
def sendmsg(chan , msg): # This is the send message function, it simply sends messages to the channel. | |
ircsock.send(stuur.encode("utf-8") | |
chanjoin = "JOIN "+ chan +"\n" | |
def joinchan(chan): # This function is used to join channels. | |
ircsock.send(chanjoin) | |
hellosend = "PRIVMSG "+ channel +" :Leave me alone!\n" | |
def hello(): # This function responds to a user that inputs "Hello Mybot" | |
ircsock.send(hellosend) | |
kak = "USER "+ botnick +" "+ botnick +" "+ botnick | |
nicksend = "NICK "+ botnick +"\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(kak.encode("utf-8") # user authentication | |
ircsock.send(nicksend.encode("utf-8") # here we actually assign the nick to the bot | |
joinchan(channel) # Join the channel using the functions we previously defined | |
while 1: # Be careful with these! it might send you to an infinite loop | |
ircmsg = ircsock.recv(2048) # receive data from the server | |
ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks. | |
print(ircmsg) # Here we print what's coming from the server | |
if ircmsg.find(":Hello ") != -1: # If we can find "Hello Mybot" it will call the function hello() | |
hello() | |
if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond! | |
ping() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment