Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import socket, time, re, datetime, threading
- from tkinter import *
- HOST = "irc.chat.twitch.tv"
- PORT = 6667
- NICK = "bot_angel" #"minecraftm2000"
- PASS = "ni de coña"
- CHAN = "#pablogoru"
- hora_inicio = datetime.datetime(2016, 3, 18, 20, 55, 0)
- personas_con_poder = ["minecraftm2000", "pablogoru", "pagoru", "mcmacker4", "pizzalated_"]
- # Make sure you prefix the quotes with an 'r'!
- CHAT_MSG=re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
- RATE = (20/30)
- STOP = False
- # network functions go here
- s = socket.socket()
- s.connect((HOST, PORT))
- #s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
- s.send("PASS ".encode("utf-8") + PASS.encode("utf-8") +"\r\n".encode("utf-8"))
- #s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
- s.send("NICK ".encode("utf-8") + NICK.encode("utf-8") +"\r\n".encode("utf-8"))
- #s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
- s.send("JOIN ".encode("utf-8") + CHAN.encode("utf-8") +"\r\n".encode("utf-8"))
- def chat(sock, msg):
- """
- Send a chat message to the server.
- Keyword arguments:
- sock -- the socket over which to send the message
- msg -- the message to be sent
- """
- #sock.send("PRIVMSG #{} :{}".format(CHAN, msg))
- mensaje_final="PRIVMSG " + CHAN + " :" + msg +"\r\n"
- sock.send(mensaje_final.encode("utf-8"))
- def tiempo_online(hora_inicio):
- tiempo = datetime.datetime.now() - hora_inicio
- dias = tiempo.days
- horas = tiempo.seconds // 3600
- minutos = tiempo.seconds % 3600 // 60
- segundos = tiempo.seconds % 60
- milisegundos = tiempo.microseconds % 1000000 // 1000
- microsegundos = tiempo.microseconds % 1000
- str_tiempo = str(dias) + " días, "+ str(horas) + " horas, "+ str(minutos) + " minutos, " + str(segundos)+ " segundos, " + str(milisegundos) + " milisegundos y " + str(microsegundos) + "microsegundos :)"
- return str(str_tiempo)
- def bucle():
- global STOP
- while not STOP:
- response = s.recv(1024).decode("utf-8")
- if response == "PING :tmi.twitch.tv\r\n":
- s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
- else:
- username = re.search(r"\w+", response).group(0) # return the entire match
- message = CHAT_MSG.sub("", response)
- print(username + ": " + message)
- if username == "minecraftm2000": pass
- if str(message)[0] == "?":
- if "exit" in message and username in personas_con_poder:
- chat(s, "Adios.")
- STOP = True
- elif "uptime" in message:
- chat(s, tiempo_online(hora_inicio))
- elif str(message)[0] == "!":
- if "exit" in message and username in personas_con_poder:
- chat(s, "Adios.")
- STOP = True
- elif "uptime" in message:
- chat(s, tiempo_online(hora_inicio))
- chat(s, "Pablo si te molesta el bot usa ?exit pero no me lo bannees :S")
- time.sleep(1 / RATE)
- bucle()
- raise SystemExit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement