View file chat/bot/umnik.php

File size: 4.39Kb
<?

function umnik($msg){
global $id_r, $user, $time,$mysql;
$bot_name = 'Ботан';
$q = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]chat` WHERE `id_r` = '$id_r' AND `umnik` <> '0' ORDER BY id DESC LIMIT 1;");
$post_um_k=mysql_result($q, 0);
$q = mysql_query("SELECT * FROM `$mysql[pref]chat` WHERE `id_r` = '$id_r' AND `umnik` <> '0' ORDER BY id DESC LIMIT 1;");
$post_um=mysql_fetch_array($q);
if ($post_um_k!=0 && $post_um['umnik']!=1){
$v_otvet=$post_um['otvet'];
$v_otvet=strtr($v_otvet,array("А"=>"а","Б"=>"б","В"=>"в","Г"=>"г","Д"=>"д","Е"=>"е","Ё"=>"ё","Ж"=>"ж","З"=>"з","И"=>"и","Й"=>"й","К"=>"к","Л"=>"л","М"=>"м","Н"=>"н","О"=>"о","П"=>"п","Р"=>"р","С"=>"с","Т"=>"т","У"=>"у","Ф"=>"ф","Х"=>"х","Ц"=>"ц","Ч"=>"ч","Ш"=>"ш","Щ"=>"щ","Ъ"=>"ъ","Ы"=>"ы","Ь"=>"ь","Э"=>"э","Ю"=>"ю","Я"=>"я"));
$msg=strtr($msg,array("А"=>"а","Б"=>"б","В"=>"в","Г"=>"г","Д"=>"д","Е"=>"е","Ё"=>"ё","Ж"=>"ж","З"=>"з","И"=>"и","Й"=>"й","К"=>"к","Л"=>"л","М"=>"м","Н"=>"н","О"=>"о","П"=>"п","Р"=>"р","С"=>"с","Т"=>"т","У"=>"у","Ф"=>"ф","Х"=>"х","Ц"=>"ц","Ч"=>"ч","Ш"=>"ш","Щ"=>"щ","Ъ"=>"ъ","Ы"=>"ы","Ь"=>"ь","Э"=>"э","Ю"=>"ю","Я"=>"я"));
if (eregi("$v_otvet",$msg))
{
if ($post_um['umnik']==2){$podsk="не используя подсказок";$dbal='5';$user['v_balls'] += 3;$v_balls='3 балла';}
if ($post_um['umnik']==3){$podsk="используя одну подсказку";$dbal='4';$user['v_balls'] += 2;$v_balls='2 балла';}
if ($post_um['umnik']==4){$podsk="используя две подсказки";$dbal='3';$user['v_balls'] += 1;$v_balls='1 балл';}
$botmess="Молодец, $user[nickname], ты первым дал верный ответ ($v_otvet) $podsk. Ты заработал $v_balls, теперь у тебя $user[v_balls].<br />Следующий вопрос через 30 секунд.";
mysql_query("INSERT INTO `$mysql[pref]chat` (id_r, nick, time, msg, otvet, umnik)
values('$id_r', '$bot_name', '$time', '$botmess', '', '1');");
mysql_query("UPDATE `$mysql[pref]users` SET `v_balls` = '$user[v_balls]' WHERE `id` = '$user[id]';");
}}}


$q = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]chat` WHERE `id_r` = '$id_r' AND `umnik` <> '0' ORDER BY id DESC LIMIT 1;");
$post_um_k=mysql_result($q, 0);

$q = mysql_query("SELECT * FROM `$mysql[pref]chat` WHERE `id_r` = '$id_r' AND `umnik` <> '0' ORDER BY id DESC LIMIT 1;");
$post_um=mysql_fetch_array($q, 1);

if ($post_um_k==0 || $post_um['time']<$time-30 && $post_um['umnik']==1)
{
$file_um=file(BASEDIR."SYSTEM/data/chat/umnik.txt");
$que=$file_um[(rand(0, count($file_um)-1))];
$que=trim($que);
$que2=explode("|", $que);
$quest['otvet']=trim($que2[1]);
$quest['vop']=trim($que2[0]);
$otvet_k=strlen($quest['otvet'])/2;
if ($otvet_k=='1'){$b='буква';}
if ($otvet_k=='2'){$b='буквы';}
if ($otvet_k=='3'){$b='буквы';}
if ($otvet_k=='4'){$b='буквы';}
if ($otvet_k>'4'){$b='букв';}
for ($i=0;$i<$otvet_k;$i++){$otvet.="*";}
$vop=$quest['vop'];
$botmess="Вопрос: $vop ($otvet_k $b)";
mysql_query("INSERT INTO `$mysql[pref]chat` (id_r, nick, time, msg, otvet, umnik)
values('$id_r', '$bot_name', '$time', '$botmess', '$quest[otvet]', '2');");
}
elseif($post_um['umnik']==2 && $post_um['time']<$time-30)
{
$otvet2=$post_um['otvet'];
$help=substr($otvet2,0,2);
$otvet_k=strlen($otvet2)/2;
for ($i=0;$i<$otvet_k-1;$i++){$help.="*";}
$botmess="Первая подсказка: $help";
mysql_query("INSERT INTO `$mysql[pref]chat` (id_r, nick, time, msg, otvet, umnik)
values('$id_r', '$bot_name', '$time', '$botmess', '$post_um[otvet]', '3');");
}
elseif($post_um['umnik']==3 && $post_um['time']<$time-30)
{
$otvet2=$post_um['otvet'];
$help=substr($otvet2,0,4);
$otvet_k=strlen($otvet2)/2;
for ($i=0;$i<$otvet_k-2;$i++){$help.="*";}
$botmess="Вторая подсказка: $help";
mysql_query("INSERT INTO `$mysql[pref]chat` (id_r, nick, time, msg, otvet, umnik)
values('$id_r', '$bot_name', '$time', '$botmess', '$post_um[otvet]', '4');");
}
elseif($post_um['umnik']==4 && $post_um['time']<$time-45)
{
$otvet2=$post_um['otvet'];

$botmess="На вопрос никто не ответил. Правильный ответ: $otvet2.<br />Следующий вопрос через 30 секунд";
mysql_query("INSERT INTO `$mysql[pref]chat` (id_r, nick, time, msg, otvet, umnik)
values('$id_r', '$bot_name', '$time', '$botmess', '', '1');");
}






?>