Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. # Version 1.1
  2. # Import socket libraries and system for clean exiting upon leaving the server
  3. import socket
  4. import sys
  5. import urllib.request
  6. import urllib.parse
  7. import urllib.error
  8.  
  9. # The variables that can be configured
  10. server = "irc.malvager.com" # Server
  11. channel = "bot" # Channel
  12. botnick = "BiowBot" # Your bots nick
  13.  
  14. # Defining the functions we'll be using to perform routine tasks
  15. def ping(): # Function to respond to PINGs
  16. ircsock.send(str.encode("PONG :pingis\n"))
  17.  
  18. def sendmsg(chan , msg): # Function for sending messages to a channel
  19. ircsock.send(str.encode("PRIVMSG " + "#" + chan +" :" + msg + "\n"))
  20.  
  21. def joinchan(chan): # This function is used to join channels.
  22. ircsock.send(str.encode("JOIN " + "#" + chan + "\n"))
  23.  
  24. def leavechan(chan): # This is used to part a chan
  25. ircsock.send(str.encode("PART " + "#" + chan + " Kbai, leaving the channel" + "\n"))
  26.  
  27. def quitirc(chan): # This makes the bot quit the server
  28. ircsock.send(str.encode("QUIT" + "\n"))
  29.  
  30. ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  31. ircsock.connect((server, 6667)) # The actual connection to the server through the socket
  32. ircsock.send(str.encode("USER "+ botnick +" "+ botnick +" "+ botnick +" :hax\n")) # user authentication
  33. ircmsg = ircsock.recv(2048) # receive data from the server
  34. ircsock.send(str.encode("NICK "+ botnick + "\n")) # here we actually assign the nick to the bot
  35. if ircmsg.find(str.encode(botnick + " :Nickname is already in use.")) != -1:
  36. ircsock.send(str.encode("NICK" + botnick + "_" + "\n"))
  37. end
  38. else:
  39. print("Nick not taken")
  40.  
  41. joinchan(channel) # Join the channel using the functions we previously defined
  42. sendmsg(channel,"sup") # Same, but now sending a message using its function
  43.  
  44. while 1: # Inb4infinite loop
  45. ircmsg = ircsock.recv(2048) # receive data from the server
  46. ircmsg_clean = ircmsg.strip(str.encode('\n\r')) # removing any unnecessary linebreaks.
  47. print(ircmsg_clean) # Print whats coming from the server
  48. if ircmsg.find(str.encode("PING :")) != -1: # When receiving a ping, it has to be answered in order to stay online
  49. ping()
  50. sendmsg(channel, 'Ping received')
  51. if ircmsg.find(str.encode(botnick + " :Nickname is already in use.")) != -1:
  52. ircsock.send(str.encode("NICK "+ botnick + "_" + "\n"))
  53. if ircmsg.find(str.encode("Malvager is full of hackers")) != -1:
  54. sendmsg(channel, "Trudat")
  55. if ircmsg.find(str.encode("!leave")) != -1: # Leave command
  56. leavechan(channel)
  57. if ircmsg.find(str.encode("!quit")) != -1: # Quit command
  58. quitirc(channel)
  59. sys.exit() # To avoid an infinite loop checking for pings whereas we stopped the connection with the server
  60. if ircmsg.find(str.encode("sup " + botnick)) != -1:
  61. sendmsg(channel, "nm you?")
  62. if ircmsg.find(str.encode("!version")) != -1:
  63. sendmsg(channel, "This is version 1.11, it changes nick when BotNick is already taken")
  64. #if ircmsg.find(str.encode("!google " + *))
  65.  
  66.  
  67. # Questions:
  68. # In order for the bot to work with the "chan
  69.  
  70. # This is the most recent, working version.
  71. # Working on: Google function
  72. # To be added:
  73. # 1. Google, Wikipedia, Urban Dictionary and Encyclopedia Dramatica search restults
  74. # 2. Weather from around the world
  75. # 3. Authentication system
  76. # 4. Seen user
  77. # 5. Stats logging
  78. # 6. Find HF users, print their postcount and rep(total,+ and -)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement