PHPIRC Bot RSS-Feed Parser
#1
RSS-Feed Autospam

.conf
Code:
file rss_mod modules/rss_mod/rss_mod.php

section rss_mod "RSS-Feed Parser spam to Chan"

join rss_mod on_join
priv !rss true true true 0 rss_mod get_reply                    rssfeed "" ""
priv !rssadminhelp true true true 0 rss_mod printAdminHelp      rssfeed "" ""
priv !rsshelp true true true 0 rss_mod printUserHelp            rssfeed "" ""
priv !rsslast true true true 0 rss_mod show_last                rssfeed "" ""
priv !rsslist true true true 0 rss_mod get_list                rssfeed "" ""

.ini file es kann auch leer gelassen werden, wird automatisch erstellt.

Code:
[admins]
[config]
[links]
[feed2chan]
[lastpost]
PHP Modul

PHP-Code:
<?php

/*
*   ToDo
*      Mögliche fehler beim feed holen abfangen, feed nicht erreichbar etc.      
*/

error_reporting(0);

class 
rss_mod extends module {


    public 
$title "RSS Feeder module";
    public 
$author "zer0.de";
    public 
$version "1.0";
    
    
/**
    * Configuration
    **/
    
    
public $cachedir "./modules/rss_mod/cache";
    public 
$inifile "./modules/rss_mod/rss_feed.ini";
    
    
    public function 
init() {
        
$this->rss = new ini($this->inifile);
        include_once(
'./modules/rss_mod/autoloader.php');
        
        
$this->timerClass->addTimer("rss_show"$this"show"""60*3false);
    }
    
    public function 
get_list($line) {
        
$chan irc::myStrToLower($line['to']);
        
$nick $line['fromNick'];
        
        if (
$links $this->rss->getVars("links")) {
                
$this->ircClass->privMsg($chan"These are the links with her ids. You can use it for !rsslast {name} to show the last 5 entries");
                foreach (
$links as $name => $link) {
                    if (
$name) {
                        
$this->ircClass->privMsg($chanBOLD $name);
                                }
                }
            } else {
                
$this->ircClass->privMsg($chan"No link found.");
            }
    }
    
    public function 
get_reply($line$args) {
        
$chan irc::myStrToLower($line['to']);
        
$nick $line['fromNick'];
        
        
        if (!
$this->rss->getVars("admins"))
        {
            
//no admin yet so the first to talk to bot becomes admin
            
$this->rss->setIniVal("admins"$nicktime());
            
$this->rss->writeIni();
            
$this->ircClass->privMsg($chan"You are now admin. Please set the interval, channel and add links.");
            
$this->printAdminHelp($line);
            return;
        }
        
        
        if (!
$this->rss->getIniVal("admins"$nick))
        {
            
//not admin, skip
            
$this->ircClass->privMsg($chan"You are not admin!");
            return;
        }
        
        if (
$args['nargs'] == 0)
        {
            
$this->printAdminHelp($line);
            
            return;
        }
        
        switch (
$args['arg1'])
        {
            case 
"on":
                
$this->timerClass->addTimer("rss_show"$this"show"""60false);
                
$this->ircClass->privMsg($chan"rss is now on");
            break;
            case 
"off":
                
$this->timerClass->removeTimer("rss_show");
                
$this->ircClass->privMsg($chan"rss is now off");
            break;
            case 
"set":
                if (!isset(
$args['arg2']))
                {
                    
$this->printAdminHelp($line);
                    return;
                }
                switch (
$args['arg2'])
                {
                    case 
"timer":
                    if (isset(
$args['arg3']) && intval($args['arg3']) > 60)
                    {
                        
$this->timerClass->removeTimer("rss_show");
                        
$this->timerClass->addTimer("rss_show"$this"show"""intval($args['arg3']), false);
                        
$this->ircClass->privMsg($chan"Interval set to " $args['arg3']);
                    }
                    else
                    {
                        
$this->ircClass->privMsg($chan"Interval not valid, please use !rss set timer {interval} where interval is a value in second bigger than 60");
                    }
                    break;
                    case 
"channel":
                    if (isset(
$args['arg3']) && (substr($args['arg3'], 01) == "#"))
                    {
                        
$this->rss->setIniVal("config""channel"$args['arg3']);
                        
                        
$this->ircClass->privMsg($chan"Channel is set to " $args['arg3']);
                        
$this->rss->writeIni();
                        return;
                    }
                    else
                    {
                        
$this->ircClass->privMsg($chan"Channel not valid, please use !rss set channel {#name} where name is the channel name.");
                        return;
                    }
                    break;
                    case 
"feed2chan":
                    if (isset(
$args['arg3']) && (substr($args['arg4'], 01) == "#"))
                        {
                            
$this->rss->setIniVal("feed2chan"$args['arg3'], $args['arg4']);
                        
                            
$this->ircClass->privMsg($chan"Custom Channel for ".$args['arg3']." is set to " $args['arg4']);
                            
$this->rss->writeIni();
                            return;
                        }
                        else
                        {
                            
$this->ircClass->privMsg($chan"Channel not valid, please use !rss set feed2chan {feedname} {#channel}.");
                            return;
                        }
                        break;
                }
            break;
            case 
"admin":
                if (!isset(
$args['arg2']))
                {
                    
$this->printAdminHelp($line);
                    return;
                }
                switch (
$args['arg2'])
                {
                    case 
"add":
                        if (isset(
$args['arg3']))
                        {
                            
$this->rss->setIniVal("admins"$args['arg3'], time());
                            
$this->ircClass->privMsg($chan$args['arg3'] . " is now admin");

                            
$this->rss->writeIni();

                            return;
                        }
                        else
                        {
                            
$this->ircClass->privMsg($chan"Please use !rss admin add {nick}");
                            return;
                        }
                    break;
                    case 
"del":
                        if (isset(
$args['arg3']))
                        {
                            if (
$this->rss->getIniVal("admins"$args['arg3']))
                            {
                                
$this->rss->deleteVar("admins"$args['arg3']);
                                
$this->ircClass->privMsg($chan"Admin removed");
                                return;
                            }
                            else
                            {
                                
$this->ircClass->privMsg($chan"Admin not found. Please use !rss admin list to see the list of links");
                                return;
                            }
                        }
                        else
                        {
                            
$this->ircClass->privMsg($chan"Please use !rss admin del {nick} to delete the admin.");
                        }
                    break;
                    case 
"list":
                        if (
$admins $this->rss->getVars("admins"))
                        {
                            
$this->ircClass->privMsg($chan"These are the admins. !rss admin del {nick} to delete");
                            
$msg join (", " array_keys($admins));
                            
$this->ircClass->privMsg($chan$msg);
                        }
                        else
                        {
                            
$this->ircClass->privMsg($chan"No admin found.");
                        }
                    break;
                    default:
                        
$this->printAdminHelp($line);
                        return;
                    break;
                }
            
            break;
            case 
"link":
                if (!isset(
$args['arg2']))
                {
                    
$this->printHelp($line);
                    return;
                }
                switch (
$args['arg2'])
                {
                    case 
"add":
                        if (isset(
$args['arg3']) && (isset($args['arg4'])))
                        {
                            
$this->rss->setIniVal("links",$args['arg3'], $args['arg4']);
                            
$this->ircClass->privMsg($chan"Link added");
                            
$this->rss->writeIni();
                            return;
                        }
                        else
                        {
                            
$this->ircClass->privMsg($chan"Please use !rss link add {rss name} {rss link} by rss name, use only one word no whitespaces etc.") ;
                            return;
                        }
                    break;
                    case 
"del":
                        if (isset(
$args['arg3']))
                        {
                            if (
$this->rss->getIniVal("links"$args['arg3']))
                            {
                                
$this->rss->deleteVar("links"$args['arg3']);
                                
$this->ircClass->privMsg($chan"Link removed");
                                return;
                            }
                            else
                            {
                                
$this->ircClass->privMsg($chan"Link not found. Please use !rss link list to see the list of links");
                                return;
                            }
                        }
                        else
                        {
                            
$this->ircClass->privMsg($chan"Please use !rss link del {id} to delete a link. If you don't know the id, then use !rss link list");
                        }
                    break;
                    case 
"list":
                        if (
$links $this->rss->getVars("links"))
                        {
                            
$this->ircClass->privMsg($chan"These are the links with their ids. You can remove a link with !rss link del {id}");
                            foreach (
$links as $name => $link)
                            {
                                if (
$name)
                                {
                                
$this->ircClass->privMsg($chanBOLD $name " : " BOLD $link);
                                }
                            }
                        }
                        else
                        {
                            
$this->ircClass->privMsg($chan"No link found.");
                            }
                    break;
                    default:
                            
                
$this->printAdminHelp($line$args);
                return;
                break;
            }
        break;
        }
    }
    
    public function 
printAdminHelp($line)    {
        
$chan irc::myStrToLower($line['to']);
        
$nick $line['fromNick'];
        
        
//is Admin?
        
if ($this->rss->getIniVal("admins"$nick)) {
        
            
$this->ircClass->notice($chanBOLD "!rss {on|off} " BOLD "To activate/deactivate rssfeeder");
            
$this->ircClass->notice($chanBOLD "!rss set channel #rss " BOLD "Set channel to #rss.");
            
$this->ircClass->notice($chanBOLD "!rss set feed2channel {feedname} {#channel}  " BOLD "Set feed to custom channel.");
            
$this->ircClass->notice($chanBOLD "!rss set timer 300 " BOLD "Set timer to 300 sec.");
            
$this->ircClass->notice($chanBOLD "!rss admin {add|del} user" BOLD "To add or remove user as admin (can add or remove rss link)");
            
$this->ircClass->notice($chanBOLD "!rss link add {ID/Name} {rss url} " BOLD "To add rss link defined by name without whitespaces");
            
$this->ircClass->notice($chanBOLD "!rss link list " BOLD "To see saved links with their id");    
            
$this->ircClass->notice($chanBOLD "!rss link del {id} " BOLD "To remove the rss link defined by name");    
        } else {
            
$this->ircClass->notice($chanBOLD "You are not admin!");
                }
    }
        
    public function 
printUserHelp($line)    {
        
$chan irc::myStrToLower($line['to']);
        
$nick $line['fromNick'];
    
        
$this->ircClass->notice($chanBOLD "!rsslist " BOLD "Shows the list of all Feeds with names");
        
$this->ircClass->notice($chanBOLD "!rsslast {Name} " BOLD "Show the last 5 entries of {name}");
    }
        
    public function 
show() {
        
        if (!
$this->rss->getIniVal("config""channel")) {
            
$this->ircClass->privMsg($chanBOLD "No Channel set to Output");
            return 
true;
        }

            
$feeds $this->rss->getVars("links");
                    foreach(
$feeds as $name => $link) {
                            
$feed2chan $this->rss->getVars("feed2chan");
                                foreach (
$feed2chan as $val => $cchan) {
                            
                                    if (
$name == $val) {
                                        
$chan $cchan;
                                        break;
                                    } else {
                                        
                                        
$chan $this->rss->getIniVal("config""channel");
                                    }
                             
       }
                                        
$feed = new SimplePie();
                                        
$feed->enable_cache(false);
                                        
$feed->set_cache_location($this->cachedir);
                                        
$feed->set_feed_url($link);
                                        
$feed->init();
                                        
$items $feed->get_items(01);

                                    if (
$feed_title $feed->get_title()) {
                                        foreach (
$items as $item) {
                                            if(
$item->get_date('d-m-Y H:i:s') != $this->rss->getIniVal("lastpost"$link)) {
                                            
//delete old stamp and post
                                                
$this->rss->deleteVar("lastpost",$link);
                                            
                                                    
//$this->ircClass->privMsg($chan, BOLD . "04[".$feed_title."]");
                                                    
$desc substr(strip_tags(html_entity_decode($item->get_title())), 0180);
                                                    
$desc str_replace("\n","",$desc);
                                                    
$desc str_replace("\r","",$desc);
                                                    
$this->ircClass->privMsg($chan,BOLD "04[".$feed_title."] " $desc " - (" $item->get_date('d/m/Y') . ") " UNDERLINE $this->UrlShorter($item->get_link()) . UNDERLINE);
                                                        
                                                    
//put the last date 2 feed
                                                    
$this->rss->setIniVal("lastpost"$link$item->get_date('d-m-Y H:i:s'));
                                                    
$this->rss->writeIni();
                                                    break;
                                    } else {
                                        
//nothing new? break
                                        
continue;
                                     
       }
                             
              
                                    
}
                }
        return 
true;
    }

    public function 
show_last($line,$args) {
        
$chan irc::myStrToLower($line['to']);
        
$nick $line['fromNick'];
        
        
$name $args['arg1'];
        
        if (!
$this->rss->getIniVal("links"$name)) {
            
$this->ircClass->privMsg($chan"Link or Name not found use. ".$name." !rss link list to view the List of available Feeds");
        }
        
        
$link $this->rss->getIniVal("links"$name);
        
        
$this->ircClass->privMsg($chanBOLD "Show now the last 5 Post of ".$name." in query!");
        
                
$feed = new SimplePie();
                
$feed->enable_cache(true);
                
$feed->set_cache_location($this->cachedir);
                
$feed->set_feed_url($link);
                
$feed->init();
                
$items $feed->get_items(0,5);
                
$cleaner = array("\n","\r","\t");
                
                
$this->ircClass->privMsg($nickBOLD "04[".$feed->get_title()."]");
                foreach (
$items as $item) {
                        
$desc strip_tags(html_entity_decode($item->get_description()));
                        
$desc str_replace($cleaner,"",$desc);
                        
$this->ircClass->privMsg($nick $desc " - (" $item->get_date('d/m/Y') . ") " UNDERLINE $this->UrlShorter($item->get_link()) . UNDERLINE);
                    }
    }
    
 
   public function on_join($line) {
 
       $nick $line['fromNick'];
 
       $chan irc::myStrToLower($line['to']);
    
        if (
strtolower($line['cmd']) == "join")
        {
            
$this->ircClass->notice($nickBOLD "RSS-News Feed Channel - Automaticly Spam of News---use " .UNDERLINE"!rsshelp".UNDERLINE." for Options");;
        }
    }
    
    function 
urlShorter($url) {
        
$res "";
        
$handle = @fopen("http://is.gd/api.php?longurl=".urlencode($url), "rb");
        if(
$handle) {
            while (!
feof($handle)) {
                
$res .= fgets($handle,2000);
            }
            
fclose($handle);
        }
    
        return 
$res;
    }


    
/* eof */

}
?>

Autoloader

PHP-Code:
<?php
/**
 * SimplePie
 *
 * A PHP-Based RSS and Atom Feed Framework.
 * Takes the hard work out of managing a complete RSS/Atom solution.
 *
 * Copyright (c) 2004-2016, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *     * Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *
 *     * Neither the name of the SimplePie Team nor the names of its contributors may be used
 *       to endorse or promote products derived from this software without specific prior
 *       written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @package SimplePie
 * @copyright 2004-2016 Ryan Parman, Geoffrey Sneddon, Ryan McCue
 * @author Ryan Parman
 * @author Geoffrey Sneddon
 * @author Ryan McCue
 * @link http://simplepie.org/ SimplePie
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
 */


// autoloader
spl_autoload_register(array(new SimplePie_Autoloader(), 'autoload'));

if (!
class_exists('SimplePie'))
{
    
trigger_error('Autoloader not registered properly'E_USER_ERROR);
}

/**
 * Autoloader class
 *
 * @package SimplePie
 * @subpackage API
 */
class SimplePie_Autoloader
{
    
/**
     * Constructor
     */
    
public function __construct()
    {
        
$this->path dirname(__FILE__) . DIRECTORY_SEPARATOR 'library';
    }

    
/**
     * Autoloader
     *
     * @param string $class The name of the class to attempt to load.
     */
    
public function autoload($class)
    {
        
// Only load the class if it starts with "SimplePie"
        
if (strpos($class'SimplePie') !== 0)
        {
            return;
        }

        
$filename $this->path DIRECTORY_SEPARATOR str_replace('_'DIRECTORY_SEPARATOR$class) . '.php';
        include 
$filename;
    }


ordner Cache muss mind. 644 haben besser ist noch 666, 755 im notfall
Class im Anhang


Angehängte Dateien
.gz   RSS_Mod_Class.tar.gz (Größe: 76.66 KB / Downloads: 0)
Dein Neid ist meine Anerkennung - dein Hass mein Sieg!

[Bild: ximg.php?fid=83617361]
Zitieren


Gehe zu: