Advertisement
bssanchez93

Bot de Nataly

Jul 7th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.00 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5.  [RGB] Bot!
  6.  
  7.  Copyright (C) 2013 Crozz Cyborg <CrozzCyborg@hotmail.es>
  8.                2014 Nataly Lopez <natalylopez380@hotmail.com>
  9.  
  10.  This program is free software: you can redistribute it and/or modify
  11.  it under the terms of the GNU General Public License as published by
  12.  the Free Software Foundation, either version 3 of the License, or
  13.  (at your option) any later version.
  14.  
  15.  This program is distributed in the hope that it will be useful,
  16.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18.  
  19.  See the GNU General Public License for more details.
  20.  
  21.  You should have received a copy of the GNU General Public License
  22.  along with this program.  If not, see http://www.gnu.org/licenses/.
  23. """
  24.  
  25. import socket,re
  26.  
  27. #import sys
  28. #sys.path.insert(0, '/usr/lib/python2.7/bridge/')
  29. #from bridgeclient import BridgeClient as bridgeclient
  30. #bridge = bridgeclient()
  31. # bridge.put('D13','1') esto enciende led
  32. # bridge.put('D13','0') esto apaga led
  33.  
  34. servidor = "irc.ircnode.com" # Datos a donde conectarse
  35. port = 6667
  36.  
  37. nick = "RGB_see" # Datos de nick y canal
  38. canal = "#dot!"
  39.  
  40. def Conexion(Servidor): # Se realiza la conexion
  41.     print "[!] Estableciendo conexion a "+Servidor[0]
  42.     irc = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  43.     irc.connect(Servidor)
  44.     print "[+] Conexion establecida"
  45.  
  46.     return irc
  47.  
  48. def Identificar(irc): # Se identifica el bot con un nick y el usuario
  49.     print "[!] Enviando datos de autentificacion";
  50.     irc.send("NICK "+nick+"\n")
  51.     irc.send("USER "+nick+" Apellido Apellido Nombre\n")
  52.     return 0
  53.  
  54. def JoinPart(Canal,accion,irc): # Funcion para salir o entrar de un canal Sintaxis: JoinPart(canal, accion) , accion; 1 = entrar,  0 = salir
  55.     if(accion):
  56.         print "[!] Entrando en "+Canal;
  57.         irc.send("JOIN "+Canal+"\n")
  58.         #irc.send("PRIVMSG "+Canal+" :Welcome :D\n")
  59.  
  60. def EncenderLed(Canal,irc):
  61.      irc.send("PRIVMSG "+Canal+" :Encendida esta miedda\n")
  62.  
  63. def ApagarLed(Canal,irc):
  64.          irc.send("PRIVMSG "+Canal+" :Apagada esta miedda\n")
  65.  
  66. def MDatos(data,irc): # Manipulacion de datos
  67.     if re.match(r'^PING :',data): # Se envia pong
  68.         irc.send("PONG :"+data[6:]+"\n")
  69.     elif re.match(r'^:\S+ NOTICE AUTH :\*\*\* Looking up your hostname',data): # se solicita identificarse
  70.         Identificar(irc)
  71.     elif re.match(r'^:\S+ 001',data): # Si se recibe el mensaje de bienvenida entra al canal
  72.         JoinPart(canal,1,irc)
  73.     else:
  74.         tmp = data.split(':')
  75.         print len(tmp)
  76.         if len(tmp) > 2:
  77.             if re.match(r'on\!', tmp[2]): # Si se recibe el on
  78.                 EncenderLed(canal, irc)
  79.             elif re.match(r'off\!',tmp[2]): # Si se recibe el off
  80.                         ApagarLed(canal, irc)
  81.  
  82.  
  83. def main():
  84.     print "[!] RGBOT :) [!]\n"
  85.     irc = Conexion((servidor,port))
  86.  
  87.     while irc: # Bucle que lee el socket
  88.         data = irc.recv(512)
  89.         MDatos(data,irc)
  90.  
  91.     return 0
  92.  
  93. try:
  94.     main()
  95. except KeyboardInterrupt: # Funcion que se ejecuta en caso de Ctrl + C
  96.     print "[!] Deteniendo el bot"
  97.     exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement