реализация icq бота

Discussion in 'PHP' started by Fristail, 16 Apr 2010.

  1. Fristail

    Fristail Elder - Старейшина

    Joined:
    25 Oct 2007
    Messages:
    207
    Likes Received:
    145
    Reputations:
    10
    здрасти =)

    подскажите..как реализовать вот такого бота..
    Code:
    /thread193332.html
     
  2. phpdreamer

    phpdreamer Member

    Joined:
    26 Jul 2009
    Messages:
    522
    Likes Received:
    86
    Reputations:
    19
    наверно парсинг rss
     
  3. Vlad&slav

    Vlad&slav Member

    Joined:
    1 Jan 2009
    Messages:
    207
    Likes Received:
    41
    Reputations:
    9
    неее я парсю сам форум)
    там всё оч хитро както сделано
    (писалось в трансе в 4 утра)
     
  4. Deathdreams

    Deathdreams Elder - Старейшина

    Joined:
    8 Nov 2008
    Messages:
    342
    Likes Received:
    116
    Reputations:
    5
    Начал писать свой парсер, допишу - выложу ;)
     
  5. Deathdreams

    Deathdreams Elder - Старейшина

    Joined:
    8 Nov 2008
    Messages:
    342
    Likes Received:
    116
    Reputations:
    5
    Вообщем покорячился и накидал небольшой кодец.
    Самого бота допишите сами, скрипт обрабатывает переменную с предполагаемым сообщением.


    Вот и сам код:

    PHP:
    <?php

    $msg 
    = "t"; //В этой обрабатывается сообщение. Не изменять.






    $forum_suff = "f"; //приставка для команды выбора форума. Без пробелов.
    $thread_suff = "t"; //приставка для команды выбора топика. без пробелов









    $cmd = explode( " ", $msg );

    if( 
    is_numeric($cmd[1]) )

    {

    switch( 
    $cmd[0] )

        {

            case 
    $forum_suff:
                        echo 
    get_forums( "forum{$cmd[1]}", (is_numeric($cmd[2]) ? $cmd[2] : '1') );
            break;

            case 
    $thread_suff:
                        echo 
    get_thread( $cmd[1], (isset($cmd[2]) ? $cmd[2] : '10'), (isset($cmd[3]) ? $cmd[3] : '1') );
            break;

            default:
                        echo 
    get_forums();
            break;

        }

    } else {

    echo 
    get_forums();

    }

    function 
    get_thread($th=false, $count=10, $page=1 )

    {
        if( !
    $th || !is_numeric($page) || !is_numeric($count) ) return "Такой темы/топика не существует или неверно заданы параметры.";

            
    $content = file_get_contents( '/threadnav'.$th.'-'.$page.'-'.$count.'.html' );
            
    preg_match( '#<title>Форум АНТИЧАТ - (.+)</title>#', $content, $title_tmp );
            
    preg_match( '#<a class="bigusername" href="member\.php\?.*">(.+)</a>#i', $content, $author );
            
    $outmsg = "- - - - - ".html_entity_decode($title_tmp[1])."  [ Author: \"".html_entity_decode($author[1])."\" ] - - - - -\r\n\r\n";
            
    preg_match_all( '#<!-- message -->(.+)<!-- / message -->.*<td class="thead">(.+)</td>#Uis', $content, $comments );
            
    $i=1;
            foreach( 
    $comments[1] as $n => $value )
            {

            
    $tmp = str_replace( '<br />', "\r\n", $value );
            
    $tmp = strtr( $tmp, array( 
                            
    '<img src="images/smilies/smile.gif" border="0" alt="" title="Smile" class="inlineimg" />' => ":)",
                            
    '<img src="images/smilies/mad.gif" border="0" alt="" title="Mad" class="inlineimg" />' => ">:|",
                            
    '<img src="images/smilies/tongue.gif" border="0" alt="" title="Stick Out Tongue" class="inlineimg" />' => ":-P",
                            
    '<img src="images/smilies/wink.gif" border="0" alt="" title="Wink" class="inlineimg" />' => ";)",
                            
    '<img src="images/smilies/biggrin.gif" border="0" alt="" title="Big Grin" class="inlineimg" />' => ":D",
                            
    '<img src="images/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />' => ":(",
                            
    '<img src="images/smilies/redface.gif" border="0" alt="" title="Embarrassment" class="inlineimg" />' => ":o",
                            
    '<img src="images/smilies/confused.gif" border="0" alt="" title="Confused" class="inlineimg" />' => ":?",
                            
    '<img src="images/smilies/rolleyes.gif" border="0" alt="" title="Roll Eyes (Sarcastic)" class="inlineimg" />' => "8(",
                            
    '<img src="images/smilies/cool.gif" border="0" alt="" title="Cool" class="inlineimg" />' => "B)",
                            
    '<img src="images/smilies/eek.gif" border="0" alt="" title="EKK!" class="inlineimg" />' => ':O'));

            
    $tmp = str_replace( "\r\n\r\n\r\n", "\r\n", $tmp );
            
    $tmp = str_replace( "\r\n\r\n", "\r\n", $tmp );
            if( 
    strstr( $tmp, 'Цитата:' ) )

            {
                
    $tmp = preg_replace( '|<div style="margin-right: 20px; margin-left: 20px; padding: 10px; background: #44474f; border: 1px solid #e3e3e5; border-left: 1px solid #808084; border-top: 1px solid #808084; margin-bottom: 10px;">.*Сообщение от <strong>(.+)</strong>(.+)<else />|s', ' { Сообщение от \\1: \\2 }  ', $tmp );
            }

            
    $tmp = preg_replace( '#<div class="smallfont" style="margin-bottom:2px">.*</div>.+(<code>|<pre)(.+)(</code>|</pre>)#s', "Код: { <div $2 }", $tmp );
            
    $tmp = strip_tags( $tmp );
            
    $outmsg .= "[ #".$i." ".html_entity_decode($comments[2][$n])." ]\r\n".html_entity_decode(trim($tmp))."\r\n-------------------------------------\r\n";
            
    $i++;
            }

            return 
    trim($outmsg);
    }

    function 
    get_forums($index='index.php', $page='1')

    {
        global 
    $forum_suff,$thread_suff;
        if(
    $index=='index.php') { $content = file_get_contents( '/'.$index ); } else { $content = file_get_contents( "/".$index."-".$page."-lastpost--30--1.html" ); }
        if( 
    strstr( $content, 'Тема отсутствует, либо неверно указаны' ) ) $content = file_get_contents( '/index.php' );
        
    preg_match_all( '#<a\s+href="forum([0-9]+).html"><strong>(.+)</strong></a><br>#', $content, $output_tmp );
        
    $suff = $forum_suff;
        if( 
    $output_tmp[1][0] !== null )

        {
            foreach( 
    $output_tmp[1] as $n => $value )

              {

                @
    $forums .= $suff." ".$value." : \"".trim($output_tmp[2][$n])."\"\r\n";

              }

        }

        
    preg_match_all( '#<a href="thread([0-9]+)\.html"  >(.+)</a>#', $content, $output_tmp );
            
    preg_match_all( '#<span style="cursor:pointer" onclick="window\.open\(\'.*[0-9]+\'\)">(.+)</span>#', $content, $output_a_tmp );
        
    $suff = $thread_suff;
        if( 
    $output_tmp[1][0] !== null )

        {
            foreach( 
    $output_tmp[1] as $n => $value )

              {

                @
    $forums .= $suff." ".$value." : \"".trim($output_tmp[2][$n])."\" [".$output_a_tmp[1][$n]."]\r\n";

              }
        }


        return 
    $forums;
    }


    ?>
    P.S. код криво обрабатывает теги ( [СОDЕ], [РHР] ), некоторые не обрабатывает вообще.
     
  6. Fristail

    Fristail Elder - Старейшина

    Joined:
    25 Oct 2007
    Messages:
    207
    Likes Received:
    145
    Reputations:
    10
    найс.
    phpdreamer,Deathdreams спасибо ребят =)
    сейчас сам буду корячиться.
    у кого есть еще мысли, то сливайте =)
     
  7. Vlad&slav

    Vlad&slav Member

    Joined:
    1 Jan 2009
    Messages:
    207
    Likes Received:
    41
    Reputations:
    9
    ну вот , сплагиатили идею
     
  8. Deathdreams

    Deathdreams Elder - Старейшина

    Joined:
    8 Nov 2008
    Messages:
    342
    Likes Received:
    116
    Reputations:
    5
    Я не собираюсь реализовывать твоего бота, просто переписал твой код + добавил пару функций.