Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import socket, string, sys
  3. map = []
  4. file = open('workfile', 'r')
  5. lines = [line.rstrip('\n') for line in file]
  6. dawg = []
  7. for x in lines:
  8. if dawg==[]:
  9. dawg+=[x]
  10. else:
  11. dawg+=[int(x)]
  12. map+=[dawg]
  13. dawg=[]
  14. print map
  15. file.close
  16. def timeouttime(user):
  17. global map
  18. for x in map:
  19. if(x[0]==user):
  20. x[1] = x[1] + 30
  21. return x[1]
  22. map+=[[user,60]]
  23. return 60
  24. def rm(user):
  25. global map
  26. for x in map:
  27. if(x[0]==user):
  28. x[1] = 30
  29.  
  30. def isCommand(m,c):
  31. if(m==""):
  32. return False
  33. if(m[0]!='!'):
  34. return False
  35. x = m[1:]
  36. #print(x)]
  37. for i in range(len(c)):
  38. if(x[i]!=c[i]):
  39. return False
  40. return True
  41.  
  42. def getUser(line):
  43. separate = line.split(":", 2)
  44. user = separate[0].split("!", 1)
  45. return user[0]
  46. def getMessage(line):
  47. separate = line.split(":", 2)
  48. message = separate[1]
  49. return message
  50. def mquit():
  51. f = open('workfile', 'w')
  52. for x in map:
  53. f.write(x[0] + "\n" + str(x[1]) + "\n")
  54. f.close()
  55. sys.exit("blablabla")
  56. NICK = "shabobot"
  57. HOST = "irc.twitch.tv"
  58. PORT= 6667
  59. PASS = "oauth:73hqznjeownydhqnov7wwpnbm3dpfw"
  60. CHANNEL = "krajuuuuu"
  61.  
  62. s = socket.socket()
  63. s.connect((HOST,PORT))
  64. s.send("PASS " + PASS + "\r\n")
  65. s.send("NICK " + NICK + "\r\n")
  66. s.send("JOIN #" + CHANNEL + "\r\n")
  67.  
  68. def send_message(message):
  69. s.send("PRIVMSG #" + CHANNEL + " :" + message + "\r\n")
  70. def timeout(user, time):
  71. s.send("PRIVMSG #" + CHANNEL + " :.timeout " + user + " " + str(time) + "\r\n")
  72. def ban(user):
  73. s.send("PRIVMSG #" + CHANNEL + " :.ban " + user + "\r\n")
  74. def unban(user):
  75. s.send("PRIVMSF #" + CHANNEL + " :.unban " + user + "\r\n")
  76.  
  77. readbuffer = ""
  78. Loading = True
  79. while Loading:
  80. readbuffer = readbuffer + s.recv(1024)
  81. temp = string.split(readbuffer, "\n")
  82. readbuffer = temp.pop()
  83. #print("jestem")
  84. for line in temp:
  85. print(line)
  86. if("End of /NAMES list" in line):
  87. Loading = False
  88.  
  89. send_message("/w krajuuuuu masz")
  90. #timeout("mlodypatyk","1")
  91. def restart():
  92. send_message("Shabbot podłączony PogChamp")
  93. readbuffer = ""
  94. mval = True
  95. while mval:
  96. readbuffer = readbuffer + s.recv(1024)
  97. temp = string.split(readbuffer, "\n")
  98. readbuffer = temp.pop
  99. for line in temp:
  100. czy = True
  101. if line=="":
  102. czy = False
  103. magia = "PING"
  104. test = True
  105. if(czy):
  106. for i in range(4):
  107. if(line[i]!=magia[i]):
  108. test = False
  109. if test:
  110. czy = False
  111. s.send("PONG %s\r\n" % line[1])
  112. print line
  113. #print line
  114. if czy:
  115. x=line.split(":")
  116. user = x[1].split("!")[0]
  117. message = x[2]
  118. print(user + ": " + message)
  119. if(isCommand(message,"gruby")):
  120. send_message("cwel")
  121. if(isCommand(message, "rewon")):
  122. send_message("laps")
  123. if(isCommand(message, "shab")):
  124. send_message("król")
  125. if(isCommand(message, "kraju")):
  126. send_message("PogChamp")
  127. if(isCommand(message, "ala")):
  128. send_message(" PogChamp ALA PogChamp KOALA PogChamp HYPE PogChamp ")
  129. if(isCommand(message, "exitbot") and user == "mlodypatyk" or user == "krajuuuuu"):
  130. mval = False
  131. send_message("Shabobot odłączony BibleThump")
  132. mquit()
  133. if(len(message)>250 ):
  134. czas = timeouttime(user)
  135. timeout(user,czas)
  136. send_message("Nieładnie " + user + "! Timeout na " + str(czas) + " sekund!")
  137. readbuffer = ""
  138. restart()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement