Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import socket, time, re, datetime, threading
  5. from tkinter import *
  6.  
  7. HOST = "irc.chat.twitch.tv"
  8. PORT = 6667
  9. NICK = "bot_angel" #"minecraftm2000"
  10. PASS = "ni de coña"
  11. CHAN = "#pablogoru"
  12.  
  13. hora_inicio = datetime.datetime(2016, 3, 18, 20, 55, 0)
  14. personas_con_poder = ["minecraftm2000", "pablogoru", "pagoru", "mcmacker4", "pizzalated_"]
  15.  
  16. # Make sure you prefix the quotes with an 'r'!
  17. CHAT_MSG=re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
  18.  
  19. RATE = (20/30)
  20. STOP = False
  21.  
  22. # network functions go here
  23.  
  24. s = socket.socket()
  25. s.connect((HOST, PORT))
  26. #s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
  27. s.send("PASS ".encode("utf-8") + PASS.encode("utf-8") +"\r\n".encode("utf-8"))
  28. #s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
  29. s.send("NICK ".encode("utf-8") + NICK.encode("utf-8") +"\r\n".encode("utf-8"))
  30. #s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
  31. s.send("JOIN ".encode("utf-8") + CHAN.encode("utf-8") +"\r\n".encode("utf-8"))
  32.  
  33. def chat(sock, msg):
  34. """
  35. Send a chat message to the server.
  36. Keyword arguments:
  37. sock -- the socket over which to send the message
  38. msg -- the message to be sent
  39. """
  40. #sock.send("PRIVMSG #{} :{}".format(CHAN, msg))
  41. mensaje_final="PRIVMSG " + CHAN + " :" + msg +"\r\n"
  42. sock.send(mensaje_final.encode("utf-8"))
  43.  
  44. def tiempo_online(hora_inicio):
  45. tiempo = datetime.datetime.now() - hora_inicio
  46. dias = tiempo.days
  47. horas = tiempo.seconds // 3600
  48. minutos = tiempo.seconds % 3600 // 60
  49. segundos = tiempo.seconds % 60
  50. milisegundos = tiempo.microseconds % 1000000 // 1000
  51. microsegundos = tiempo.microseconds % 1000
  52. str_tiempo = str(dias) + " días, "+ str(horas) + " horas, "+ str(minutos) + " minutos, " + str(segundos)+ " segundos, " + str(milisegundos) + " milisegundos y " + str(microsegundos) + "microsegundos :)"
  53. return str(str_tiempo)
  54.  
  55. def bucle():
  56. global STOP
  57. while not STOP:
  58.  
  59. response = s.recv(1024).decode("utf-8")
  60. if response == "PING :tmi.twitch.tv\r\n":
  61. s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
  62. else:
  63. username = re.search(r"\w+", response).group(0) # return the entire match
  64. message = CHAT_MSG.sub("", response)
  65. print(username + ": " + message)
  66. if username == "minecraftm2000": pass
  67. if str(message)[0] == "?":
  68. if "exit" in message and username in personas_con_poder:
  69. chat(s, "Adios.")
  70. STOP = True
  71. elif "uptime" in message:
  72. chat(s, tiempo_online(hora_inicio))
  73. elif str(message)[0] == "!":
  74. if "exit" in message and username in personas_con_poder:
  75. chat(s, "Adios.")
  76. STOP = True
  77. elif "uptime" in message:
  78. chat(s, tiempo_online(hora_inicio))
  79. chat(s, "Pablo si te molesta el bot usa ?exit pero no me lo bannees :S")
  80. time.sleep(1 / RATE)
  81.  
  82.  
  83. bucle()
  84. raise SystemExit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement