Advertisement
Algabe

Bot Ayuda IRC

Jan 6th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.04 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf8
  3.  
  4. # Un notificador simple que avisa a los IRCop por GLOBOPS y al canal #opers
  5. # cuando un suario entra a un canal y solicita ayuda.
  6. #
  7. # IMPORTANTE !!! El bot debe ser IRCop global o al menos poder enviar GLOBOPS en la red.
  8.  
  9. import socket
  10. import os
  11. import time
  12.  
  13. # Datos a modificar
  14.  
  15. IGNORENICKS =   "nick chan memo bot host neostats connect oper"
  16. SERVER      =   "127.0.0.1"
  17. PORT        =   6667
  18. CHANNEL     =   "#ayuda"
  19. BOTNICK     =   "Ayuda"
  20. NICKSERV    =   "NiCKserv"
  21. NICKPASS    =   "pass_nick"
  22. USERNAME    =   "Help"
  23. REALNAME    =   "Bot de ayuda"
  24. OLINE       =   "user pass"
  25. NOTIFY_CHAN =   "#operadores"
  26.  
  27. ## Fin modificaciones
  28.  
  29. s = socket.socket()
  30. s.connect((SERVER, PORT))
  31.  
  32. s.send("NICK %s\r\n" % BOTNICK)
  33. s.send("USER %s localhost %s :%s\r\n" % (USERNAME, SERVER, REALNAME))
  34.  
  35. while(1):
  36.     buffer = s.recv(2048)
  37.     if not buffer:
  38.         break
  39.     print buffer.rstrip("\r\n")
  40.     for line in buffer.split("\r\n"):
  41.         if not line:
  42.             break
  43.         line = line.split()
  44.         if line[0] == "PING":
  45.             s.send("PONG  %s\r\n" % line[1])
  46.         if len(line) >= 2 and line[1] == "001":
  47.             s.send("OPER %s\r\n" % OLINE)
  48.             if NICKPASS:
  49.                 s.send("PRIVMSG %s :IDENTIFY %s\r\n" % (NICKSERV, NICKPASS))
  50.             s.send("JOIN %s\r\n" % CHANNEL)
  51.             s.send("JOIN %s\r\n" % NOTIFY_CHAN)
  52.         if len(line) >=  2 and line[1] == "JOIN" and line[2] == ':'+CHANNEL and not BOTNICK in line[0]:
  53.             h_nick = line[0].split('!')[0][1:]
  54.             if not h_nick.lower() in IGNORENICKS.split():
  55.                 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))
  56.                 f = open(h_nick, "w")
  57.                 f.close()
  58.         if len(line) >=  2 and line[1] == "PART" and line[2] == CHANNEL:
  59.             p_nick = line[0].split('!')[0][1:]
  60.             if os.path.exists(p_nick) and os.path.getsize(p_nick) == 0:
  61.                 os.remove(p_nick)
  62.             if os.path.exists(p_nick+'_queue') and os.path.getsize(p_nick+'_queue') == 0:
  63.                 os.remove(p_nick+'_queue')
  64.         if len(line[3:]) == 2 and line[1] == "PRIVMSG" and line[2].lower() == NOTIFY_CHAN.lower() and line[3][1:].lower() == "!helper":
  65.             if os.path.exists(line[4].lstrip()):
  66.                 helper = line[0].split("!")[0][1:]
  67.                 s.send("PRIVMSG %s :El OPer %s le atendera en breve.\r\n" % (line[4], helper))
  68.                 s.send("PRIVMSG %s :Peticion en curso para el NiCK %s.\r\n" % (NOTIFY_CHAN, line[4]))
  69.                 os.remove(line[4])
  70.             else:
  71.                 s.send("PRIVMSG %s :Error, no hay peticiones.\r\n" % line[2])
  72.         if len(line) >= 3 and line[1] == "PRIVMSG" and line[2].lower() == BOTNICK.lower():
  73.             msg = ""
  74.             r_nick = line[0].split('!')[0][1:]
  75.             if not os.path.exists(r_nick):
  76.                 if not r_nick.lower() in IGNORENICKS.split():
  77.                     s.send("PRIVMSG %s :Debe entrar al canal %s para recibir ayuda.\r\n" % (r_nick, CHANNEL))
  78.             else:
  79.                 if os.path.exists(r_nick+'_queue'):
  80.                     s.send("PRIVMSG %s :Por favor, sea paciente o pruebe a entrar mas adelante.\r\n" % r_nick)
  81.                 else:
  82.                     f = open(r_nick+'_queue', "w")
  83.                     f.close()              
  84.                     for h_msg in line[3:]: msg += h_msg+' '
  85.                     s.send("GLOBOPS %s solicita ayuda, asunto: \"%s\"\r\n" % (r_nick, msg[1:-1]))
  86.                     s.send("PRIVMSG %s :%s solicita ayuda, asunto: \"%s\"\r\n" % (NOTIFY_CHAN, r_nick, msg[1:-1]))
  87.                     s.send("PRIVMSG %s :Si desea aceptar la ayuda de %s escriba: !helper %s\r\n" % (NOTIFY_CHAN, r_nick, r_nick))
  88.                     s.send("PRIVMSG %s :En breve un IRCop contactara contigo, permanezca en el canal. Gracias ;).\r\n" % r_nick)
  89.     buffer = ""
  90.     time.sleep(0.5)
  91.  
  92. s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement