Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import socket
- import string
- def parsemsg(msg):
- complete=msg[1:].split(':',1) #Parse the message into useful data
- info=complete[0].split(' ')
- msgpart=complete[1]
- sender=info[0].split('!')
- if msgpart[0]=='`' and sender[0]==OWNER: #Treat all messages starting with '`' as command
- cmd=msgpart[1:].split(' ')
- if cmd[0]=='op':
- s.send('MODE '+info[2]+' +o '+cmd[1]+'n')
- if cmd[0]=='deop':
- s.send('MODE '+info[2]+' -o '+cmd[1]+'n')
- if cmd[0]=='voice':
- s.send('MODE '+info[2]+' +v '+cmd[1]+'n')
- if cmd[0]=='devoice':
- s.send('MODE '+info[2]+' -v '+cmd[1]+'n')
- if cmd[0]=='sys':
- syscmd(msgpart[1:],info[2])
- if msgpart[0]=='-' and sender[0]==OWNER : #Treat msgs with - as explicit command to send to server
- cmd=msgpart[1:]
- s.send(cmd+'n')
- print 'cmd='+cmd
- def syscmd(commandline,channel):
- cmd=commandline.replace('sys ','')
- cmd=cmd.rstrip()
- os.system(cmd+' >temp.txt')
- a=open('temp.txt')
- ot=a.read()
- ot.replace('n','|')
- a.close()
- s.send('PRIVMSG '+channel+' :'+ot+'n')
- return 0
- HOST='irc.freenode.net'
- PORT=6667
- NICK='ChaosCoreBot'
- IDENT='CCbot'
- REALNAME='DarsBots'
- OWNER='ichaleynbin'
- CHANNELINIT='#chaoscore-ircbot'
- readbuffer=''
- opusers = set()
- opusers.add('ichaleynbin')
- opusers.add('smatt454')
- opusers.add('Gio77')
- opusers.add('ChaosCoreBot')
- opusers.add('ChaosCoreBot2')
- s= socket.socket( )
- print socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
- s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
- print "Socketed", dir(s)
- s.connect((HOST,PORT))
- print s.getpeername()
- #for item in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
- # if item[4]!= s.getpeername():
- # s.bind(s.getpeername())
- print "connected", s
- s.send('USER '+IDENT+' '+HOST+' '+IDENT+'3'+ ' :'+REALNAME+' Script\n')
- s.send('NICK ' +NICK+'\n')
- init = 0
- while 1:
- line=s.recv(500) #recieve server messages
- if line != '':
- print "newline",line #server message is output
- #if line.find('End of /MOTD command.'): #This is Crap(I wasn't sure about it but it works)
- # s.send('/JOIN '+CHANNELINIT+'\n') #Join a channel
- if not init:
- s.sendall('ns identify botpass3\n')
- s.sendall('JOIN #chaoscore-ircbot\n')
- s.sendall('JOIN #chaoscorebots\n')
- init = 1
- if line.find('PRIVMSG')!=-1: #Call a parsing function
- parsemsg(line)
- line=line.rstrip() #remove trailing 'rn'
- print line
- line2=line.split()
- print line2
- posti = line.find(':!')
- posti2 = line.find('!~')
- if posti!=-1 and line2[0][1:posti2] in opusers:
- varu = line[posti+2:]
- if varu == 'Win':
- stringer ='PRIVMSG #chaoscore-ircbot :!Win'+ '\n'
- elif varu == 'Kick':
- stringer ='PRIVMSG #chaoscore-ircbot :Youre a LOSER!\n'
- else:
- stringer = 'PRIVMSG #chaoscore-ircbot :I wonder if these silly humans will ever learn...\n'
- s.sendall(stringer)
- stringer = "PRIVMSG #chaoscore-ircbot :Until you program it in, IT WON'T FUCKING WORK.\n"
- s.sendall(stringer)
- if 'PING' in line: #If server pings then pong
- s.send('PONG '+line2[1]+'\n')
- print "PONG"
- #sto = raw_input('enter: ')
- #if sto != '':
- # print sto
- # s.sendall(sto+'\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement