Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import some necessary libraries.
- import socket
- # Some basic variables used to configure the bot
- server = "irc.rizon.net" # Server
- channel = "#PilzBotTestan" # Channel
- botnick = "Ichi_Nee-San" # Your bots nick
- admins = ["Pilz", "Unyin"]
- error_message = "Danger! Danger! DANGER!"
- #some bonus global variables
- def ping(): # This is our first function! It will respond to server Pings.
- ircsock.send("PONG pingis\n") #Don't forget to PONG the server's PING! -AltAdvice
- def sendmsg(chan , msg): # This is the send message function, it simply sends messages to the channel.
- ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
- def joinchan(chan): # This function is used to join channels.
- ircsock.send("JOIN "+ chan +"\n")
- def hello(): # This function responds to a user that inputs "Hello <botnick>"
- ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
- def authorization(nick): #this function will determine whether someone is authorized to use a command or not.
- print nick + "authorization sector check"
- print nick + "as a sting is" + str(nick)
- nick = str(nick)
- administrator = 0 #if 1 or higher, user is admin
- for name in admins: #is the user an admin?
- if name == nick:
- administrator = administrator + 1
- while administrator > 0:
- print "Returnin' admin, Boss!"
- return 'admin'
- else:
- print
- return 'spy'
- def bot_movement(authorized, direction): #this function allows admins to make the bot join or leave channels
- print "Movement stage, check! " + authorized + ", " + direction
- if authorized == 'admin':
- if direction == 'join':
- ircsock.send("PRIVMSG " + channel + " :This is working!!!11! I'd join a channel if I knew how!" + "\n")
- elif direction == 'part':
- ircsock.send("PRIVMSG " + channel + " :This is wor-oh. You want me to leave ;_;" + "\n")
- elif direction == 'away':
- ircsock.send("PRIVMSG " + channel + " :RIPperoni!" + "\n")
- else: #is the user a dirty damn not-admin?!
- print "SPAH SAPPIN' MAH SENTRY!"
- ircsock.send("PRIVMSG " + channel + ":I'll cut ya if'n ya try tha' agin m8, see if I doesn't!" + "\n")
- ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ircsock.connect((server, 6667)) # Here we connect to the server using port 6667
- ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutorial covered on http://shellium.org/wiki.\n") # user authentication
- ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot
- joinchan(channel) # Join the channel using the functions we previously defined
- 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.
- print(ircmsg) # Here we print what's coming from the server
- if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond!
- ping()
- if ircmsg.find(":Hello "+ botnick) != -1: # If we can find "Hello Mybot" it will call the function hello()
- hello()
- if ircmsg.find(":!join") != -1: #looks for a !join command
- userName = ircmsg.split ( '!' ) [ 0 ].replace ( ':', '' )
- print userName + " Command stage check!"
- bot_movement(authorization(userName), 'join')
- if ircmsg.find(":!part") != -1: #looks for a !part command
- userName = ircmsg.split ( '!' ) [ 0 ].replace ( ':', '' )
- print userName + " Command stage check!"
- bot_movement(authorization(userName), 'part')
- if ircmsg.find(":!away") != -1: #looks for a !away command
- userName = ircmsg.split ( '!' ) [ 0 ].replace ( ':', '' )
- print userName + " Command stage check!"
- bot_movement(authorization(userName), 'away')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement