Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Version 1.1
- # Import socket libraries and system for clean exiting upon leaving the server
- import socket
- import sys
- import urllib.request
- import urllib.parse
- import urllib.error
- # The variables that can be configured
- server = "irc.malvager.com" # Server
- channel = "bot" # Channel
- botnick = "BiowBot" # Your bots nick
- # Defining the functions we'll be using to perform routine tasks
- def ping(): # Function to respond to PINGs
- ircsock.send(str.encode("PONG :pingis\n"))
- def sendmsg(chan , msg): # Function for sending messages to a channel
- ircsock.send(str.encode("PRIVMSG " + "#" + chan +" :" + msg + "\n"))
- def joinchan(chan): # This function is used to join channels.
- ircsock.send(str.encode("JOIN " + "#" + chan + "\n"))
- def leavechan(chan): # This is used to part a chan
- ircsock.send(str.encode("PART " + "#" + chan + " Kbai, leaving the channel" + "\n"))
- def quitirc(chan): # This makes the bot quit the server
- ircsock.send(str.encode("QUIT" + "\n"))
- ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ircsock.connect((server, 6667)) # The actual connection to the server through the socket
- ircsock.send(str.encode("USER "+ botnick +" "+ botnick +" "+ botnick +" :hax\n")) # user authentication
- ircmsg = ircsock.recv(2048) # receive data from the server
- ircsock.send(str.encode("NICK "+ botnick + "\n")) # here we actually assign the nick to the bot
- if ircmsg.find(str.encode(botnick + " :Nickname is already in use.")) != -1:
- ircsock.send(str.encode("NICK" + botnick + "_" + "\n"))
- end
- else:
- print("Nick not taken")
- joinchan(channel) # Join the channel using the functions we previously defined
- sendmsg(channel,"sup") # Same, but now sending a message using its function
- while 1: # Inb4infinite loop
- ircmsg = ircsock.recv(2048) # receive data from the server
- ircmsg_clean = ircmsg.strip(str.encode('\n\r')) # removing any unnecessary linebreaks.
- print(ircmsg_clean) # Print whats coming from the server
- if ircmsg.find(str.encode("PING :")) != -1: # When receiving a ping, it has to be answered in order to stay online
- ping()
- sendmsg(channel, 'Ping received')
- if ircmsg.find(str.encode(botnick + " :Nickname is already in use.")) != -1:
- ircsock.send(str.encode("NICK "+ botnick + "_" + "\n"))
- if ircmsg.find(str.encode("Malvager is full of hackers")) != -1:
- sendmsg(channel, "Trudat")
- if ircmsg.find(str.encode("!leave")) != -1: # Leave command
- leavechan(channel)
- if ircmsg.find(str.encode("!quit")) != -1: # Quit command
- quitirc(channel)
- sys.exit() # To avoid an infinite loop checking for pings whereas we stopped the connection with the server
- if ircmsg.find(str.encode("sup " + botnick)) != -1:
- sendmsg(channel, "nm you?")
- if ircmsg.find(str.encode("!version")) != -1:
- sendmsg(channel, "This is version 1.11, it changes nick when BotNick is already taken")
- #if ircmsg.find(str.encode("!google " + *))
- # Questions:
- # In order for the bot to work with the "chan
- # This is the most recent, working version.
- # Working on: Google function
- # To be added:
- # 1. Google, Wikipedia, Urban Dictionary and Encyclopedia Dramatica search restults
- # 2. Weather from around the world
- # 3. Authentication system
- # 4. Seen user
- # 5. Stats logging
- # 6. Find HF users, print their postcount and rep(total,+ and -)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement