Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. import sys
  2. import socket
  3. import string
  4.  
  5.  
  6. def parsemsg(msg):
  7. complete=msg[1:].split(':',1) #Parse the message into useful data
  8. info=complete[0].split(' ')
  9. msgpart=complete[1]
  10. sender=info[0].split('!')
  11. if msgpart[0]=='`' and sender[0]==OWNER: #Treat all messages starting with '`' as command
  12. cmd=msgpart[1:].split(' ')
  13. if cmd[0]=='op':
  14. s.send('MODE '+info[2]+' +o '+cmd[1]+'n')
  15. if cmd[0]=='deop':
  16. s.send('MODE '+info[2]+' -o '+cmd[1]+'n')
  17. if cmd[0]=='voice':
  18. s.send('MODE '+info[2]+' +v '+cmd[1]+'n')
  19. if cmd[0]=='devoice':
  20. s.send('MODE '+info[2]+' -v '+cmd[1]+'n')
  21. if cmd[0]=='sys':
  22. syscmd(msgpart[1:],info[2])
  23.  
  24. if msgpart[0]=='-' and sender[0]==OWNER : #Treat msgs with - as explicit command to send to server
  25. cmd=msgpart[1:]
  26. s.send(cmd+'n')
  27. print 'cmd='+cmd
  28.  
  29. def syscmd(commandline,channel):
  30. cmd=commandline.replace('sys ','')
  31. cmd=cmd.rstrip()
  32. os.system(cmd+' >temp.txt')
  33. a=open('temp.txt')
  34. ot=a.read()
  35. ot.replace('n','|')
  36. a.close()
  37. s.send('PRIVMSG '+channel+' :'+ot+'n')
  38. return 0
  39.  
  40. HOST='irc.freenode.net'
  41. PORT=6667
  42. NICK='ChaosCoreBot'
  43. IDENT='CCbot'
  44. REALNAME='DarsBots'
  45. OWNER='ichaleynbin'
  46. CHANNELINIT='#chaoscore-ircbot'
  47. readbuffer=''
  48. opusers = set()
  49. opusers.add('ichaleynbin')
  50. opusers.add('smatt454')
  51. opusers.add('Gio77')
  52. opusers.add('ChaosCoreBot')
  53. opusers.add('ChaosCoreBot2')
  54.  
  55. s= socket.socket( )
  56. print socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
  57.  
  58. s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
  59. print "Socketed", dir(s)
  60. s.connect((HOST,PORT))
  61. print s.getpeername()
  62. #for item in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
  63. # if item[4]!= s.getpeername():
  64. # s.bind(s.getpeername())
  65. print "connected", s
  66. s.send('USER '+IDENT+' '+HOST+' '+IDENT+'3'+ ' :'+REALNAME+' Script\n')
  67. s.send('NICK ' +NICK+'\n')
  68.  
  69. init = 0
  70.  
  71. while 1:
  72. line=s.recv(500) #recieve server messages
  73. if line != '':
  74. print "newline",line #server message is output
  75. #if line.find('End of /MOTD command.'): #This is Crap(I wasn't sure about it but it works)
  76. # s.send('/JOIN '+CHANNELINIT+'\n') #Join a channel
  77. if not init:
  78. s.sendall('ns identify botpass3\n')
  79. s.sendall('JOIN #chaoscore-ircbot\n')
  80. s.sendall('JOIN #chaoscorebots\n')
  81. init = 1
  82. if line.find('PRIVMSG')!=-1: #Call a parsing function
  83. parsemsg(line)
  84. line=line.rstrip() #remove trailing 'rn'
  85. print line
  86. line2=line.split()
  87. print line2
  88. posti = line.find(':!')
  89. posti2 = line.find('!~')
  90. if posti!=-1 and line2[0][1:posti2] in opusers:
  91. varu = line[posti+2:]
  92. if varu == 'Win':
  93. stringer ='PRIVMSG #chaoscore-ircbot :!Win'+ '\n'
  94. elif varu == 'Kick':
  95. stringer ='PRIVMSG #chaoscore-ircbot :Youre a LOSER!\n'
  96. else:
  97. stringer = 'PRIVMSG #chaoscore-ircbot :I wonder if these silly humans will ever learn...\n'
  98. s.sendall(stringer)
  99. stringer = "PRIVMSG #chaoscore-ircbot :Until you program it in, IT WON'T FUCKING WORK.\n"
  100. s.sendall(stringer)
  101. if 'PING' in line: #If server pings then pong
  102. s.send('PONG '+line2[1]+'\n')
  103. print "PONG"
  104. #sto = raw_input('enter: ')
  105. #if sto != '':
  106. # print sto
  107. # s.sendall(sto+'\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement