Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import socket, string
  3.  
  4. def isCommand(m,c):
  5. if(m==""):
  6. return False
  7. if(m[0]!='!'):
  8. return False
  9. x = m[1:]
  10. #print(x)]
  11. for i in range(len(c)):
  12. if(x[i]!=c[i]):
  13. return False
  14. return True
  15.  
  16. def getUser(line):
  17. separate = line.split(":", 2)
  18. user = separate[0].split("!", 1)
  19. return user[0]
  20. def getMessage(line):
  21. separate = line.split(":", 2)
  22. message = separate[1]
  23. return message
  24. NICK = "shabobot"
  25. HOST = "irc.twitch.tv"
  26. PORT= 6667
  27. PASS = "oauth:73hqznjeownydhqnov7wwpnbm3dpfw"
  28. CHANNEL = "krajuuuuu"
  29.  
  30. s = socket.socket()
  31. s.connect((HOST,PORT))
  32. s.send("PASS " + PASS + "\r\n")
  33. s.send("NICK " + NICK + "\r\n")
  34. s.send("JOIN #" + CHANNEL + "\r\n")
  35.  
  36. def send_message(message):
  37. s.send("PRIVMSG #krajuuuuu :" + message + "\r\n")
  38. def timeout(user, time):
  39. s.send("PRIVMSG #krajuuuuu :.timeout " + user + " " + time + "\r\n")
  40. def ban(user):
  41. s.send("PRIVMSG #krajuuuuu :.ban " + user + "\r\n")
  42. def unban(user):
  43. s.send("PRIVMSF #krajuuuuu :.unban " + user + "\r\n")
  44.  
  45. readbuffer = ""
  46. Loading = True
  47. while Loading:
  48. readbuffer = readbuffer + s.recv(1024)
  49. temp = string.split(readbuffer, "\n")
  50. readbuffer = temp.pop()
  51. #print("jestem")
  52. for line in temp:
  53. print(line)
  54. if("End of /NAMES list" in line):
  55. Loading = False
  56.  
  57. send_message("Shabbot podłączony PogChamp")
  58. send_message("/w krajuuuuu masz")
  59. #timeout("mlodypatyk","1")
  60. def restart():
  61. readbuffer = ""
  62. while True:
  63. readbuffer = readbuffer + s.recv(1024)
  64. temp = string.split(readbuffer, "\n")
  65. readbuffer = temp.pop
  66. for line in temp:
  67. czy = True
  68. if line=="":
  69. czy = False
  70. magia = "PING"
  71. test = True
  72. if(czy):
  73. for i in range(4):
  74. if(line[i]!=magia[i]):
  75. test = False
  76. if test:
  77. czy = False
  78. s.send("PONG %s\r\n" % line[1])
  79. print line
  80. #print line
  81. if czy:
  82. x=line.split(":")
  83. user = x[1].split("!")[0]
  84. message = x[2]
  85. print(user + ": " + message)
  86. if(isCommand(message,"gruby")):
  87. send_message("cwel")
  88. if(isCommand(message, "rewon")):
  89. send_message("laps")
  90. if(isCommand(message, "shab")):
  91. send_message("król")
  92. if(isCommand(message, "kraju")):
  93. send_message("PogChamp")
  94. if(isCommand(message, "ala")):
  95. send_message(" PogChamp ALA PogChamp KOALA PogChamp HYPE PogChamp ")
  96. if(len(message)>250 ):
  97. timeout(user,"60")
  98. send_message("Nieładnie " + user + "!")
  99. readbuffer = ""
  100. restart()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement