Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- #https://tmi.twitch.tv/group/user/pablogoru/chatters
- #:bot_urogap!bot_urogap@bot_urogap.tmi.twitch.tv PRIVMSG #pablogoru :Eso es un link!
- import socket, time, re, datetime, os, requests
- from tkinter import *
- HOST = "irc.chat.twitch.tv"
- PORT = 6667
- NICK = "bot_angel"
- PASS = "pene"
- CHAN = "#pablogoru"
- def conectar():
- s = socket.socket()
- s.connect((HOST, PORT))
- s.send("PASS ".encode("utf-8") + PASS.encode("utf-8") +"\r\n".encode("utf-8"))
- s.send("NICK ".encode("utf-8") + NICK.encode("utf-8") +"\r\n".encode("utf-8"))
- s.send("JOIN ".encode("utf-8") + CHAN.encode("utf-8") +"\r\n".encode("utf-8"))
- s.send("CAP REQ :twitch.tv/membership\r\n".encode("utf-8"))
- s.send("CAP REQ :twitch.tv/tags\r\n".encode("utf-8"))
- return s
- def online(quiero = "viewers"):
- link = requests.get("https://tmi.twitch.tv/group/user/%s/chatters" % (CHAN[1:]))
- jason = link.json()
- return jason["chatters"][quiero]
- def link(mensaje):
- link_str = re.search("\w\.([a-z]{2,})", mensaje.lower())
- if link_str and not re.search("!link", mensaje.lower()):
- if link_str.group(1).upper() in LISTA: return True
- return False
- def mayus(mensaje):
- if len(mensaje.replace(" ", ""))>=5:
- if len(re.sub("[^A-Z]", "", mensaje))>len(mensaje.replace(" ", ""))/2: return True
- return False
- 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 y " + str(segundos)+ " segundos :)"# + str(milisegundos) + " milisegundos y " + str(microsegundos) + "microsegundos :)"
- return str(str_tiempo)
- def leer(file):
- lista = []
- if not os.path.exists(file): return "error"
- lector = open(file).readlines()
- for i in lector:
- lista.append(i.replace("\n",""))
- return lista
- LISTA = leer("domain.txt")
- hora_inicio = datetime.datetime(2016, 3, 18, 22, 4, 0)
- lista_errores = [" ", "End", "of", "/NAMES", "list"]
- mensajes = []
- MODS = []
- VIEWERS = []
- RATE = (20/30)
- STOP = False
- MUTE = True
- DEBUG = True
- CMD = "?$%&/!"
- MSG = {"bastardo" : "Dime.",
- "amor" : "Nadie te quiere.",
- "online" : VIEWERS,
- "mods": MODS}
- def xprint(*vartuple):
- if DEBUG: print(*vartuple)
- #print("\n")
- def chat(sock, msg, ignorar = False):
- global mensajes
- if len(mensajes) >= 20 and 30-(mensajes[0]-time.time())<30:
- time.sleep(30-(mensajes[0]-time.time()))
- if len(mensajes)>20: mensajes.pop(0)
- if ignorar or not MUTE:
- mensajes.append(time.time())
- mensaje_final="PRIVMSG " + CHAN + " :" + str(msg) +"\r\n"
- sock.send(mensaje_final.encode("utf-8"))
- xprint("BOT:", msg)
- else: xprint("~BOT:", msg)
- def bucle():
- global STOP, DEBUG, MUTE
- s = conectar()
- #!song: Nombre de la cancion. - !help: Command info. - !faq: Preguntas frecuentes. - !mods: Moderadores online. - !link: Poner un link sin ban. - !uptime: Tiempo online.
- #!solve: Resolver operaciones matematicas. - !xdpizza: Contar xd's - !urogap: Mutear/Desmutear a bot_urogap. - !online: Usuarios online.
- while not STOP:
- respuesta = s.recv(4096).decode("utf-8")
- for response in respuesta.split("\n"):
- response = response.replace("\n", "")
- response = response.replace("\r", "")
- if "PING :tmi.twitch.tv" in response: #responde al ping para no desconectarse
- s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
- elif ":{0}.tmi.twitch.tv".format(NICK) in response:
- xprint(response)
- for nombre in response[len(":{0}.tmi.twitch.tv 353 {0} = {1}".format(NICK, CHAN)):].split(" "):
- if nombre not in VIEWERS and nombre not in lista_errores and len(nombre) > 1:
- xprint("+", nombre.replace(":",""))
- VIEWERS.append(nombre.replace(":",""))
- elif re.search("PRIVMSG", response): #@color=#FF0000;display-name=bot_urogap;emotes=;mod=1;room-id=30985069;subscriber=0;turbo=0;user-id=119422161;user-type=mod :bot_urogap!bot_urogap@bot_urogap.tmi.twitch.tv PRIVMSG #pablogoru :magicinventor -> NO PONGAS TANTAS MAYUS!
- username = re.search("display-name=(\w+)", response).group(1)
- message = re.search("{} :(.+)".format(CHAN), response).group(1)#pablogoru :
- username_mod = int(re.search("mod=(\d)", response).group(1))
- if username_mod:
- xprint("MOD", username + ": " + message)
- else:
- xprint(username + ": " + message)
- if str(message)[0] in CMD:
- message = message.lower()
- if message.startswith("uptime", 1): chat(s, tiempo_online(hora_inicio))
- elif message.startswith("exit", 1) and username in MODS + ["minecraftm2000"]:
- chat(s, "Adios.")
- STOP = True
- elif message.startswith("debug", 1) and username in MODS + ["minecraftm2000"]: DEBUG = DEBUG != True
- elif message.startswith("angel", 1) and username in MODS + ["minecraftm2000"]: MUTE = MUTE != True
- elif message.startswith("solve", 1):
- try:
- oper = str(eval(message[7:]))
- xprint("Operacíon resuelta")
- if oper[0] in CMD + "!.":
- chat(s, "Eso no está permitido!")
- elif link(oper):
- pass
- else: chat(s, oper)
- except: xprint("ERROR en el !solve")
- else:
- for palabra in MSG.keys():
- if message.startswith(palabra, 1):
- chat(s, MSG[palabra])
- if username not in MODS and link(message):
- chat(s, "LINK")
- if username not in MODS and mayus(message):
- chat(s, "MAYÚSCULAS")
- elif re.search("JOIN",response):
- username = re.search(":(\w+)", response).group(1)
- xprint("+",username)
- if username not in VIEWERS:
- VIEWERS.append(username)
- elif re.search("PART",response):
- username = re.search(":(\w+)", response).group(1)
- xprint("-",username)
- if username in VIEWERS: VIEWERS.remove(username)
- if username in MODS: MODS.remove(username)
- elif re.search("\+o (\w+)", response):
- username = re.search("\+o (\w+)", response).group(1)
- xprint("+o",username)
- MODS.append(username)
- elif re.search("-o (\w+)", response):
- username = re.search("-o (\w+)", response).group(1)
- xprint("-o",username)
- if username in MODS: MODS.remove(username)
- else:
- xprint(response)
- bucle()
- raise SystemExit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement