Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import os
- import time as t
- from time import time
- import sys
- #----------------------------------------------------------------------------
- #you need espeak installed in your system
- #I made this bot for fun change the channel and the nick to suit your irc
- #have fun and if it breaks your PC tell someone who cares!
- #----------------------------------------------------------------------------
- path = "/home/dennis/bot/"
- t1=time()
- network = 'irc.freenode.net' #irc address to connect too
- port = 6667 #port for irc channel
- nick = 'espeak_bot' #bot name
- nick1 = 'espeak_bot'
- owner = 'name' #owners name used for quit command ..Make sure you put your irc name here or the quit command wont work
- password = 'Password' #bot reg name password
- channel = '#warzone2100' # set up our socket
- irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) #define how to send to irc with variable irc.send
- irc.connect ( ( network, port ) ) #log into irc
- irc.send ( 'NICK ' + nick + '\r\n' ) #send nickname
- irc.send ( 'USER espeak_bot espeak_bot espeak_bot :Python IRC\r\n' ) #send ident
- t.sleep(6) #wait till irc catches up to bot
- irc.send('PRIVMSG NICKSERV :identify ' + password + ' \r\n') #send identification to irc for reg bot name
- t.sleep(15) #wait till irc catches up
- irc.send ( 'JOIN ' + channel + '\r\n' ) #join channel
- #define functions
- def chatuser( input ): #get the user name of who is speaking
- name = input.split("!")[0].replace(":", "")
- return name
- i=0
- #t2=time()
- while time() - t1 < 30: #wait timer to try and wait till irc motd is done before bot speaks
- data = irc.recv ( 4096 )#text as comes from irc
- data = "" #empty data of motd
- while True:
- data = irc.recv ( 4096 )#text as comes from irc
- data1 = data.upper()#text from irc in uppercase
- #espeak set up and test
- if len(data.split("#warzone2100 :")) > 1:#check that string length is over 1 char
- text = data.split("#warzone2100 :")[1]#split string to have only message
- print text + "bug test"#just a bug catcher
- s = "espeak '" + chatuser(data) + " said, " + text + "'." #create the string to send to espeak use name who spoke ...the message they sent
- os.system(s) #send it to espeak
- if data.find ( nick ) != -1:
- if data.find(channel) != -1 and data1.find('QUIT') != -1 and chatuser(data) == owner: #the quit command
- irc.send('PRIVMSG ' + channel + ' :If I must ' + owner + '.\r\n')
- t.sleep(6)
- irc.send('PRIVMSG ' + channel + ' :Ok fine Im outa here ' + owner + '.\r\n')
- irc.send("QUIT :Stinky Berg\r\n")
- print('PRIVMSG ' + channel + ' :Exit command issued from IRC '+ chatuser(data))
- sys.exit()
- elif data1.find('QUIT') != -1 and chatuser(data) != owner: #the quit command if not the owner reply
- irc.send( 'PRIVMSG ' + channel + ':You are not my owner ' + chatuser(data))
- if data.find('PING') != -1 and data.find('freenode') != -1:
- irc.send('PRIVMSG ' + nick + ' :PONG .\r\n')
- print "pong"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement