Advertisement
Pilz

PilzButt: progress thus far

Oct 17th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.74 KB | None | 0 0
  1. # Import some necessary libraries.
  2. import socket  
  3.  
  4. # Some basic variables used to configure the bot        
  5. server = "irc.rizon.net" # Server
  6. channel = "#PilzBotTestan" # Channel
  7. botnick = "Ichi_Nee-San" # Your bots nick
  8. admins = ["Pilz", "Unyin"]
  9. error_message = "Danger! Danger! DANGER!"
  10.  
  11. #some bonus global variables
  12.  
  13. def ping(): # This is our first function! It will respond to server Pings.
  14.   ircsock.send("PONG pingis\n")  #Don't forget to PONG the server's PING! -AltAdvice
  15.  
  16. def sendmsg(chan , msg): # This is the send message function, it simply sends messages to the channel.
  17.   ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
  18.  
  19. def joinchan(chan): # This function is used to join channels.
  20.   ircsock.send("JOIN "+ chan +"\n")
  21.  
  22. def hello(): # This function responds to a user that inputs "Hello <botnick>"
  23.   ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
  24.  
  25. def authorization(nick): #this function will determine whether someone is authorized to use a command or not.
  26.   print nick + "authorization sector check"
  27.   print nick + "as a sting is" + str(nick)
  28.   nick = str(nick)
  29.   administrator = 0 #if 1 or higher, user is admin
  30.   for name in admins: #is the user an admin?
  31.      if name == nick:
  32.        administrator = administrator + 1
  33.        while administrator > 0:
  34.          print "Returnin' admin, Boss!"
  35.          return 'admin'
  36.      else:
  37.        print
  38.        return 'spy'
  39.  
  40. def bot_movement(authorized, direction):  #this function allows admins to make the bot join or leave channels
  41.   print "Movement stage, check!  " + authorized + ", " + direction
  42.   if authorized == 'admin':
  43.     if direction == 'join':
  44.       ircsock.send("PRIVMSG " + channel + " :This is working!!!11!  I'd join a channel if I knew how!" + "\n")
  45.     elif direction == 'part':
  46.       ircsock.send("PRIVMSG " + channel + " :This is wor-oh.  You want me to leave ;_;" + "\n")
  47.     elif direction == 'away':
  48.       ircsock.send("PRIVMSG " + channel + " :RIPperoni!" + "\n")
  49.   else:  #is the user a dirty damn not-admin?!
  50.     print "SPAH SAPPIN' MAH SENTRY!"
  51.     ircsock.send("PRIVMSG " + channel + ":I'll cut ya if'n ya try tha' agin m8, see if I doesn't!" + "\n")
  52.  
  53. ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  54. ircsock.connect((server, 6667)) # Here we connect to the server using port 6667
  55. ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutorial covered on http://shellium.org/wiki.\n") # user authentication
  56. ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot
  57.  
  58. joinchan(channel) # Join the channel using the functions we previously defined
  59.  
  60. while 1: # Be careful with these! It might send you to an infinite loop
  61.   ircmsg = ircsock.recv(2048) # receive data from the server
  62.   ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
  63.   print(ircmsg) # Here we print what's coming from the server
  64.  
  65.   if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond!
  66.     ping()  
  67.  
  68.   if ircmsg.find(":Hello "+ botnick) != -1: # If we can find "Hello Mybot" it will call the function hello()
  69.     hello()
  70.  
  71.   if ircmsg.find(":!join") != -1:  #looks for a !join command
  72.     userName = ircmsg.split ( '!' ) [ 0 ].replace ( ':', '' )
  73.     print userName + " Command stage check!"
  74.     bot_movement(authorization(userName), 'join')
  75.  
  76.   if ircmsg.find(":!part") != -1:  #looks for a !part command
  77.     userName = ircmsg.split ( '!' ) [ 0 ].replace ( ':', '' )
  78.     print userName + " Command stage check!"
  79.     bot_movement(authorization(userName), 'part')
  80.  
  81.   if ircmsg.find(":!away") != -1:  #looks for a !away command
  82.     userName = ircmsg.split ( '!' ) [ 0 ].replace ( ':', '' )
  83.     print userName + " Command stage check!"
  84.     bot_movement(authorization(userName), 'away')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement