Advertisement
Guest User

SupahKBot

a guest
Jul 31st, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import socket
  5. import sys
  6.  
  7. #settings
  8. server = "irc.freenode.net"
  9. global botnick
  10. botnick = "SupahKBot"
  11. global channel
  12. channel = "##Penstubal"
  13.  
  14. #connect
  15. irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)                             #defines the socket
  16. print "connecting to:" +server
  17. irc.connect((server, 6667))                                                         #connects to the server
  18. irc.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :"+ botnick +"\n")         #user authentication
  19. irc.send("NICK "+ botnick +"\n")
  20. irc.send("JOIN "+ channel +"\n")
  21.  
  22. #body
  23. readbuffer = ''
  24. while 1:                                                                            #puts it in a loop
  25.     text=irc.recv(2040)                                                             #receive the text
  26.     print text                                                                      #print text to console
  27.     sender = text.split(" ")
  28.     sender = sender[0]
  29.     sender = sender.split("!")
  30.     sender = sender[0]
  31.     sender = sender.strip(":")
  32.     ##Find where command is sent
  33.     sendto = '' # can be a user's nick(from query) or a channel
  34.  
  35.     if text.find('PRIVMSG ' +botnick+ ' :') != -1: #the command comes from a query
  36.         sendto = sender
  37.     else:
  38.         sendto = channel
  39.  
  40.     if text.find('PING') != -1:                                                     #check if 'PING' is found
  41.         irc.send('PONG ' + text.split() [1] + '\r\n')
  42.         irc.send("PRIVMSG "+channel+" :k\r\n")
  43.     elif text.find('KICK') != -1:                                                   #checks if 'KICK' is found (if bot is kicked from channel)
  44.         irc.send("JOIN "+ channel +"\n")
  45.         irc.send("PRIVMSG "+channel+" :k\r\n")
  46.     elif text.find('PRIVMSG') != -1:
  47.         irc.send("PRIVMSG "+channel+" :k\r\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement