Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding: utf8
- # Un notificador simple que avisa a los IRCop por GLOBOPS y al canal #opers
- # cuando un suario entra a un canal y solicita ayuda.
- #
- # IMPORTANTE !!! El bot debe ser IRCop global o al menos poder enviar GLOBOPS en la red.
- import socket
- import os
- import time
- # Datos a modificar
- IGNORENICKS = "nick chan memo bot host neostats connect oper"
- SERVER = "127.0.0.1"
- PORT = 6667
- CHANNEL = "#ayuda"
- BOTNICK = "Ayuda"
- NICKSERV = "NiCKserv"
- NICKPASS = "pass_nick"
- USERNAME = "Help"
- REALNAME = "Bot de ayuda"
- OLINE = "user pass"
- NOTIFY_CHAN = "#operadores"
- ## Fin modificaciones
- s = socket.socket()
- s.connect((SERVER, PORT))
- s.send("NICK %s\r\n" % BOTNICK)
- s.send("USER %s localhost %s :%s\r\n" % (USERNAME, SERVER, REALNAME))
- while(1):
- buffer = s.recv(2048)
- if not buffer:
- break
- print buffer.rstrip("\r\n")
- for line in buffer.split("\r\n"):
- if not line:
- break
- line = line.split()
- if line[0] == "PING":
- s.send("PONG %s\r\n" % line[1])
- if len(line) >= 2 and line[1] == "001":
- s.send("OPER %s\r\n" % OLINE)
- if NICKPASS:
- s.send("PRIVMSG %s :IDENTIFY %s\r\n" % (NICKSERV, NICKPASS))
- s.send("JOIN %s\r\n" % CHANNEL)
- s.send("JOIN %s\r\n" % NOTIFY_CHAN)
- if len(line) >= 2 and line[1] == "JOIN" and line[2] == ':'+CHANNEL and not BOTNICK in line[0]:
- h_nick = line[0].split('!')[0][1:]
- if not h_nick.lower() in IGNORENICKS.split():
- s.send("PRIVMSG %s :Hola %s, soy el encargado de notificar a un IRCop sobre cualquier duda que tenga. Por favor, escriba lo mas resumidamente la duda que tiene.\r\n" % (h_nick, h_nick))
- f = open(h_nick, "w")
- f.close()
- if len(line) >= 2 and line[1] == "PART" and line[2] == CHANNEL:
- p_nick = line[0].split('!')[0][1:]
- if os.path.exists(p_nick) and os.path.getsize(p_nick) == 0:
- os.remove(p_nick)
- if os.path.exists(p_nick+'_queue') and os.path.getsize(p_nick+'_queue') == 0:
- os.remove(p_nick+'_queue')
- if len(line[3:]) == 2 and line[1] == "PRIVMSG" and line[2].lower() == NOTIFY_CHAN.lower() and line[3][1:].lower() == "!helper":
- if os.path.exists(line[4].lstrip()):
- helper = line[0].split("!")[0][1:]
- s.send("PRIVMSG %s :El OPer %s le atendera en breve.\r\n" % (line[4], helper))
- s.send("PRIVMSG %s :Peticion en curso para el NiCK %s.\r\n" % (NOTIFY_CHAN, line[4]))
- os.remove(line[4])
- else:
- s.send("PRIVMSG %s :Error, no hay peticiones.\r\n" % line[2])
- if len(line) >= 3 and line[1] == "PRIVMSG" and line[2].lower() == BOTNICK.lower():
- msg = ""
- r_nick = line[0].split('!')[0][1:]
- if not os.path.exists(r_nick):
- if not r_nick.lower() in IGNORENICKS.split():
- s.send("PRIVMSG %s :Debe entrar al canal %s para recibir ayuda.\r\n" % (r_nick, CHANNEL))
- else:
- if os.path.exists(r_nick+'_queue'):
- s.send("PRIVMSG %s :Por favor, sea paciente o pruebe a entrar mas adelante.\r\n" % r_nick)
- else:
- f = open(r_nick+'_queue', "w")
- f.close()
- for h_msg in line[3:]: msg += h_msg+' '
- s.send("GLOBOPS %s solicita ayuda, asunto: \"%s\"\r\n" % (r_nick, msg[1:-1]))
- s.send("PRIVMSG %s :%s solicita ayuda, asunto: \"%s\"\r\n" % (NOTIFY_CHAN, r_nick, msg[1:-1]))
- s.send("PRIVMSG %s :Si desea aceptar la ayuda de %s escriba: !helper %s\r\n" % (NOTIFY_CHAN, r_nick, r_nick))
- s.send("PRIVMSG %s :En breve un IRCop contactara contigo, permanezca en el canal. Gracias ;).\r\n" % r_nick)
- buffer = ""
- time.sleep(0.5)
- s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement