Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @autor: kid_goth
- * @copyright (None) 2014, Brandon Sanchez
- * @todo Consultar los RSS de los foros en un archivo txt para
- * enviar por privado al usuario que lo pida con !news
- *
- * @filesource $archivoURL es la ruta del archivo que tiene los foros
- * y sus respectivas urls, el formato debe ser así en cada
- * linea:
- * NombreForo::http://urldelforo.dom/?uri=rss
- */
- error_reporting(E_ALL);
- class bot_foro {
- private static $servidor = 'irc.servidor.dom';
- private static $ip_servidor;
- private static $puerto = 6667;
- private static $canal = '#canal';
- private static $nick = "forum_feeds";
- private static $usuario = "ff";
- private static $nombre = "ForumFeeds";
- private static $archivoURL = './foros.txt';
- private $socket;
- private $conexion;
- public function __construct() {
- self::$ip_servidor = gethostbyname(self::$servidor);
- $this->crearSocket();
- $this->conectarSocket();
- $this->iniciarTransaccion();
- }
- private function crearSocket() {
- $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- if ($this->socket === false) {
- die("socket_create() falló: razón: " . socket_strerror(socket_last_error()) . "\n");
- } else {
- print "Conexion socket_create(): OK.\n";
- }
- }
- private function conectarSocket() {
- $this->conexion = socket_connect($this->socket, self::$ip_servidor, self::$puerto);
- if ($this->conexion === false) {
- die("socket_connect() falló.\nRazón: ($result) " . socket_strerror(socket_last_error($socket)) . "\n");
- } else {
- print "OK.\n";
- }
- }
- private function leerXml($url, $foro, $nick) {
- $url = chop($url);
- $feeds = simplexml_load_file($url);
- //var_dump($feeds);
- if ($feeds) {
- foreach ($feeds->channel->item as $feed) {
- $this->escribir("PRIVMSG " . $nick . " :________________________________________");
- $mensaje = "[ " . $feed->title . " ] -> " . $feed->link;
- $this->escribir("PRIVMSG " . $nick . " :" . $mensaje);
- }
- } else {
- $mensaje = "No se pudieron cargar los datos del foro " . $foro;
- $this->escribir("PRIVMSG " . $nick . " :" . $mensaje);
- }
- }
- private function leerUrls($nick) {
- $txt = fopen(self::$archivoURL, 'r');
- while (($linea = fgets($txt, 4096)) !== false) {
- $datos = explode('::', $linea);
- $this->escribir("PRIVMSG " . $nick . " :[Ultimos post de " . $datos[0] . "]");
- $this->leerXml($datos[1], $datos[0], $nick);
- }
- fclose($txt);
- }
- private function iniciarTransaccion() {
- $out = '';
- $arrOut = array();
- $in = 0;
- while ($out = socket_read($this->socket, 2048)) {
- $cping = 0;
- $arrOut = explode(" ", $out);
- $_nick = substr($arrOut[0], 1, (strpos($arrOut[0], "!") - 1));
- $_accion = $arrOut[1];
- $_canal = $arrOut[2];
- //$_mensaje = $arrOut[3];
- $arrOut2 = explode(" :", $out);
- //$comando = $arrOut2[0];
- $texto = $arrOut2[1];
- print $_canal . ": " . $_nick . " -> " . $_accion . " - " . $texto . "\r\n";
- if (preg_match('/004/', $out)) {
- print "Aceptado...\r\n";
- } else if (preg_match('/433/', $out)) {
- die(self::$nick . " ya esta en uso...");
- } else if (preg_match('/^PING(.*)$/i', $out)) {
- $pong = explode(" ", $out);
- $this->escribir("PONG " . $pong[1]);
- $cping++;
- } else if (preg_match('/376/i', $out)) {
- print "Accediendo al canal...\r\n";
- $this->escribir("JOIN " . self::$canal);
- print "Adentro y saludando\r\n";
- $this->escribir("PRIVMSG " . self::$canal . " :Listo para el trabajo");
- $in = 1;
- }
- if (preg_match('/NOTICE AUTH/i', $out)) {
- print "Enviando datos...\r\n";
- $this->escribir("NICK " . self::$nick);
- $this->escribir("USER " . self::$usuario . " 8 * :" . self::$nombre);
- } else if (preg_match('/(MOTD)/i', $out) && $in != 1) {
- print "Accediendo al canal...\r\n";
- $this->escribir("JOIN " . self::$canal);
- print "Adentro y saludando\r\n";
- $this->escribir("PRIVMSG " . self::$canal . " :Listo para el trabajo");
- $in = 1;
- } else if (preg_match('/^(!news)/', $texto)) {
- $this->leerUrls($_nick);
- //$this->escribir("PRIVMSG " . $_nick . " :Wola zapatin con cola");
- }
- if ($cping == 100) {
- $cping = 0;
- }
- }
- }
- private function escribir($mensaje = "") {
- socket_write($this->socket, $mensaje . "\r\n");
- }
- }
- new bot_foro();
Advertisement
Add Comment
Please, Sign In to add comment