| Deathdreams |
17.04.2010 00:36 |
Вообщем покорячился и накидал небольшой кодец.
Самого бота допишите сами, скрипт обрабатывает переменную с предполагаемым сообщением.
Вот и сам код:
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( 'http://forum.antichat.ru/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( 'http://forum.antichat.ru/'.$index ); } else { $content = file_get_contents( "http://forum.antichat.ru/".$index."-".$page."-lastpost--30--1.html" ); }
if( strstr( $content, 'Тема отсутствует, либо неверно указаны' ) ) $content = file_get_contents( 'http://forum.antichat.ru/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Р] ), некоторые не обрабатывает вообще.
[QUOTE] обрабатывать стал терпимо.
Пример запросов:
Код:
f 46 4 - получить 4 страницу тем форума 46
t 1121 30 2 - получить 30 комментариев со 2 страницы в топике 12111
f - получить ID и названия всех топиков
|