Advertisement
Guest User

Untitled

a guest
Aug 19th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import socket, string, sys, os
  3. from copy import copy
  4. from urllib.request import urlopen
  5. from time import time
  6. map = []
  7. mody = ["mlodypatyk", "Krajuuuuu", "shabobot","rewoniasty"]
  8. file = 0
  9. komendy = []
  10. #print(dirs)
  11. def reload():
  12. global komendy
  13. dir = "komendy/"
  14. dirs = os.listdir(dir)
  15. komendy = []
  16. for file in dirs:
  17. #print(file)
  18. file2 = open("komendy/" + file, 'r', encoding='utf-8')
  19. odp = [line.rstrip('\n') for line in file2]
  20. #print(odp[0])
  21. komenda = [file,odp[0]]
  22. #print(komenda)
  23. komendy += [komenda]
  24. print(komendy)
  25. reload()
  26. try:
  27. file = open('workfileorkfile', 'r')
  28. except IOError:
  29. file = open('workfile', 'w')
  30. file.close()
  31. file = open('workfile','r')
  32. f2 = 0
  33. try:
  34. f2 = open('pucek', 'r')
  35. except IOError:
  36. f2 = open('pucek', 'w')
  37. f2.close()
  38. f2 = open('pucek','r')
  39. f3 = 0
  40. try:
  41. f3 = open('punkty', 'r')
  42. except IOError:
  43. f3 = open('punkty', 'w')
  44. f3.close()
  45. f3 = open('punkty','r')
  46. femote = 0
  47. try:
  48. femote = open('emotki' ,'r')
  49. except IOError:
  50. print("Nie masz pliku z emotkami biedaku")
  51. femote = open('emotki', 'w')
  52. femote.write("Kappa\n")
  53. femote.close()
  54. femote =open('emotki','r')
  55. lines = [line.rstrip('\n') for line in file]
  56. pucek = 0
  57. try:
  58. pucek = int([line.rstrip('\n') for line in f2][0])
  59. except IndexError:
  60. pucek = 0
  61. lines2 = [line.rstrip('\n') for line in f3]
  62. emotki = [line.rstrip('\n') for line in femote]
  63. #print emotki[:-1]
  64. dawg = []
  65. pt = []
  66. ptmap = []
  67. for x in lines:
  68. if dawg==[]:
  69. dawg+=[x]
  70. else:
  71. dawg+=[int(x)]
  72. map+=[dawg]
  73. dawg=[]
  74. for x in lines2:
  75. if pt==[]:
  76. pt+=[x]
  77. else:
  78. pt+=[int(x)]
  79. ptmap+=[pt]
  80. pt=[]
  81. print(ptmap)
  82. file.close
  83. def addpt(user, amount):
  84. global ptmap
  85. done = False
  86. for x in ptmap:
  87. if(x[0]==user):
  88. x[1]+=amount
  89. done = True
  90. if(done==False):
  91. ptmap+=[[user,1]]
  92. def ept(user):
  93. global ptmap
  94. isis = False
  95. for x in ptmap:
  96. if(x[0]==user and x[1]>=10):
  97. x[1]-=10
  98. return True
  99. return isis
  100. def emotesAmount(message):
  101. czesci = message.split(" ")
  102. global emotki
  103. amount = 0
  104. for y in czesci:
  105. for x in emotki[:-1]:
  106. if x in y:
  107. amount+=1
  108. return amount
  109. def punkty(user):
  110. global ptmap
  111. for x in ptmap:
  112. if(x[0]==user):
  113. return x[1]
  114. return 0
  115. def timeouttime(user):
  116. global map
  117. for x in map:
  118. if(x[0]==user):
  119. x[1] = x[1] + 30
  120. return x[1]
  121. map+=[[user,60]]
  122. return 60
  123. def rm(user):
  124. global map
  125. for x in map:
  126. if(x[0]==user):
  127. x[1] = 30
  128. def isCommand(m,c):
  129. return m.startswith('!'+c)
  130.  
  131. def getUser(line):
  132. separate = line.split(":", 3)
  133. user = separate[1].split("!", 1)
  134. return user[0]
  135. def getMessage(line):
  136. separate = line.split(":", 2)
  137. message = separate[2]
  138. return message
  139. def mquit():
  140. global pucek
  141. f = open('workfile', 'w')
  142. f2 = open('pucek', 'w')
  143. f3 = open('punkty', 'w')
  144. for x in map:
  145. f.write(x[0] + "\n" + str(x[1]) + "\n")
  146. f.close()
  147. f2.write(str(pucek) + "\n")
  148. f2.close()
  149. for x in ptmap:
  150. f3.write(x[0]+ "\n" + str(x[1]) + "\n")
  151. sys.exit("blablabla")
  152. NICK = "shabobot"
  153. HOST = "irc.twitch.tv"
  154. PORT= 6667
  155. PASS = "oauth:73hqznjeownydhqnov7wwpnbm3dpfw"
  156. CHANNEL = "mlodypatyk"
  157. s = socket.socket()
  158. s.connect((HOST,PORT))
  159. s.send(("PASS " + PASS + "\r\n").encode("utf-8"))
  160. s.send(("NICK " + NICK + "\r\n").encode("utf-8"))
  161. s.send(("JOIN #" + CHANNEL + "\r\n").encode("utf-8"))
  162.  
  163.  
  164. def send_message(message):
  165. s.send(("PRIVMSG #" + CHANNEL + " :" + message + "\r\n").encode("utf-8"))
  166. def timeout(user, time):
  167. s.send(("PRIVMSG #" + CHANNEL + " :.timeout " + user + " " + str(time) + "\r\n").encode("utf-8"))
  168. def ban(user):
  169. s.send(("PRIVMSG #" + CHANNEL + " :.ban " + user + "\r\n").encode("utf-8"))
  170. def unban(user):
  171. s.send(("PRIVMSF #" + CHANNEL + " :.unban " + user + "\r\n").encode("utf-8"))
  172.  
  173. readbuffer = ""
  174. Loading = True
  175. while Loading:
  176. readbuffer = readbuffer + s.recv(1024).decode("utf-8")
  177. temp = readbuffer.split("\n")
  178. readbuffer = temp.pop()
  179. #print("jestem")
  180. for line in temp:
  181. print(line)
  182. if("End of /NAMES list" in line):
  183. Loading = False
  184.  
  185. #send_message("/w krajuuuuu masz")
  186. addpt("mlodypatyk",500000)
  187. addpt("krajuuuuu", 500000)
  188. send_message("/mods")
  189. #timeout("mlodypatyk","1")
  190. def restart():
  191. send_message("Shabbot podłączony PogChamp")
  192. readbuffer = ""
  193. mval = True
  194. iler = 0
  195. ltime = time()
  196. while mval:
  197. readbuffer = readbuffer + s.recv(1024).decode("utf-8")
  198. temp = readbuffer.split("\n")
  199. ntime = time()
  200. delta = ntime - ltime
  201. #if delta > 6000:
  202.  
  203. print(delta)
  204. readbuffer = temp.pop
  205. for line in temp:
  206. czy = True
  207. if line=="":
  208. czy = False
  209. magia = "PING"
  210. test = True
  211. if(czy):
  212. for i in range(4):
  213. if(line[i]!=magia[i]):
  214. test = False
  215. if test:
  216. czy = False
  217. s.send(("PONG %s\r\n" % line[1]).encode("utf-8"))
  218. #print(line)
  219. #print line
  220. if czy:
  221. user = getUser(line)
  222. messagel = getMessage(line)
  223. message = ""
  224. for i in range(len(messagel)):
  225. if(i<len(messagel)-1):
  226. message+= messagel[i]
  227. print([user,message])
  228. if emotesAmount(message)>10 and user not in mody:
  229. czas = timeouttime(user)
  230. timeout(user,czas)
  231. send_message("Nieładnie " + user + "!")
  232. else:
  233. addpt(user.lower(), 1)
  234. #print(user + ": " + message)
  235. for m in komendy:
  236. if message==m[0]:
  237. send_message(m[1])
  238. if(isCommand(message, "pause") and user in mody):
  239. x = raw_input("> ")
  240. send_message(x)
  241. if(isCommand(message,"song") and user in mody):
  242. pios = 0
  243. try:
  244. pios = open('song', 'r')
  245. except IOError:
  246. pios = open('song', 'w')
  247. pios.close()
  248. pios = open('song','r')
  249. plines = [line.rstrip('\n') for line in pios]
  250. for i in plines:
  251. send_message(i)
  252.  
  253. if(isCommand(message, "lucek")):
  254. if(ept(user)):
  255. global pucek
  256. pucek+=1
  257. send_message("Pucek został nakarmiony " + str(pucek) + " razy! Keepo Zostalo ci " + str(punkty(user)) + " punktów!")
  258. else:
  259. send_message("Nie mogłeś nakarmić Pucka, ponieważ masz tylko " + str(punkty(user)) + " punktów!")
  260. if(message=='!reload' and user in mody):
  261. reload()
  262. send_message("noo i gitara 4Head")
  263. if(isCommand(message, "exitbot") and user in mody):
  264. mval = False
  265. send_message("Shabobot odłączony BibleThump")
  266. mquit()
  267. if(isCommand(message, "rmtimeout") and user in mody):
  268. xxx = message.split(" ")
  269. y = xxx[1][:-1]
  270. timeout(y,1)
  271. rm(y)
  272. print("usuwam timeout dla " + xxx[1])
  273. if(isCommand(message, "addpoints") and user in mody):
  274. tab = message.split(" ")
  275. if len(tab)>1:
  276. y = tab[1]
  277. addpt(y.lower(), 1000)
  278. if(isCommand(message, "playlist")):
  279. send_message("@"+user+" https://open.spotify.com/user/1195654127")
  280. if(isCommand(message, "punkty")):
  281. send_message(user + " Masz " + str(punkty(user)) + " punktów!")
  282. if(len(message)>250 ):
  283. czas = timeouttime(user)
  284. timeout(user,czas)
  285. send_message("Nieładnie " + user + "! Timeout na " + str(czas) + " sekund!")
  286. if(isCommand(message, "komendy")):
  287. send_message("Komendy: !kraju, !playlist, !csconfig, !shab, !rewon, !lucek, !gruby, !pucek, !ala, !lena, !kondziu, !paweł, !komendy, !pancake, !naleśnik, !punkty, !kaoserg")
  288. readbuffer = ""
  289. restart()
  290. #coś nowego
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement