Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################################################
- # IRC bot by Amichay P. K. - am1chay.p.k@gmail.com #
- ####################################################
- ##################################################
- # Some basic variables used to configure the bot #
- ##################################################
- server = "irc.nix.co.il" # Server
- port = 6667 # Port
- channel = "#dc9723" # Channel
- botnick = "dc9723_bot" # Your bots nick
- password = "************" # Bots password
- admin = "Amichay" # Bots admin
- cmdchar = "~" # Commands begin with this
- printservmsg = 0 # Do you want to print the server messages? 0/1 = false/true
- quiet = 0 # Should the bot speak? 0/1 = false/true
- win_pass = "123456" # Secret password to win
- # Import some necessary libraries.
- import socket
- # Set up our commands function
- def commands(nick,channel,message):
- if message.find(botnick+": who")!=-1:
- ircsock.send("PRIVMSG %s :%s: I am amichay\"s bot. I hang around on this IRC server in #dc9723 and outher channels.\r\n" % (channel,nick))
- elif message.find(botnick+": list")!=-1:
- ircsock.send("PRIVMSG %s :%s: My current commands are: help, list, who, hi, wtf?!. My command character is ~.\r\n" % (channel,nick))
- def ping(): # This function will respond to server Pings.
- ircsock.send("PONG :pingis\n")
- def sendmsg(chan , msg): # This is the send message function.
- if quiet == 0:
- ircsock.send("PRIVMSG "+ channel +" :"+ msg +"\n")
- elif quiet == 1:
- ircsock.send("PRIVMSG "+ channel +" :"+ "I was a bad bot. i shouldn't speak.\n")
- # ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
- def msg(msg): # This is anouther send message function.
- if quiet == 0:
- ircsock.send("PRIVMSG "+ channel +" :"+ msg +"\n")
- elif quiet == 1:
- ircsock.send("PRIVMSG "+ channel +" :"+ "I was a bad bot. i shouldn't speak.\n")
- def joinchan(chan): # This function is used to join channels.
- ircsock.send("JOIN "+ chan +"\n")
- def win():
- ircsock.send("PRIVMSG "+ channel +" :You win!\n")
- #Connect to the server
- ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ircsock.connect((server, port)) # Here we connect to the server using the port, mostly port 6667.
- print ("\nConnected to server at " + str(server) + ", using port " + str(port) + "\n")
- ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :dc9723 IRC bot.\n") # user authentication
- ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot
- print ("User: " + str(botnick) + "\nNick: " + str(botnick) + "\n")
- ircmsg = ircsock.recv(2048) # receive data from the server
- ircmsg = ircmsg.strip("\n\r") # removing any unnecessary linebreaks.
- if ircmsg.find("PING :") != -1:
- ircsock.send("PONG %s\n" % ircmsg.split(":")[1])
- joinchan(channel) # Join the channel using the functions we previously defined
- print ("Channel: " + str(channel)+ "\n")
- ircsock.send("NICKSERV IDENTIFY "+ password +"\n") # Identify using password
- print ("\n* * * The bot is working in the channel. * * *\n")
- ircsock.send("PRIVMSG %s :%s: dc9723 bot ready at your service sir!\r\n" % (channel,admin))
- #Recive commands
- 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.
- if printservmsg == 1:
- print(ircmsg) # Here we print what"s coming from the server
- if ircmsg.find(" PRIVMSG ")!=-1:
- nick=ircmsg.split("!")[0][1:]
- channel=ircmsg.split(" PRIVMSG ")[-1].split(" :")[0]
- commands(nick,channel,ircmsg)
- #################
- # Commadnd list #
- #################
- if ircmsg.find(":"+botnick+": "+win_pass) != -1:
- win()
- if ircmsg.find(":hi "+botnick) != -1:
- msg("hi!")
- if ircmsg.find("who am i?") != -1:
- msg("No one. Go away.")
- if ircmsg.find(":"+cmdchar+"bad") != -1:
- if nick == admin:
- msg("sorry.")
- quiet = 1
- else:
- msg("Fuck you! you're not my boss!")
- if ircmsg.find(":"+cmdchar+"good") != -1:
- if nick == admin:
- quiet = 0
- msg("ok.")
- else:
- ircsock.send("PRIVMSG %s :Fuck you! you're not my boss!\r\n" % (channel))
- if ircmsg.find("42") != -1:
- msg("The answer to life the universe and everything.")
- if ircmsg.find("the answer to life the universe and everything?") != -1:
- msg("42")
- if ircmsg.find(":"+cmdchar+"WTF?!") != -1:
- msg("Fuck them all!")
- if ircmsg.find(":"+cmdchar+"help") != -1:
- ircsock.send("PRIVMSG %s :%s: My current commands are: help, list, who, hi, wtf?!. My command character is ~.\r\n" % (channel,nick))
- if ircmsg.find("PING :") != -1: # if the server pings us then we"ve got to respond!
- ping()
- # EOF #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement