<?php
include '../class/bot_bartender.php';
$botB = new bot_bartender($user['alcohol'], $user['many'], $user['id']);

if ($user['alcohol'] > $botB->config['ik'] && (time() - $botB->config['ik_time']) > $_SESSION['last_ik_bot']) {
mysql_query("INSERT INTO `chat_msg` SET `msg` = 'Ик..Ик..Ик..', `ot_user` = '".$id_session."', `room` = '1', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
	$_SESSION['last_ik_bot'] = time();
}

if ($user['alcohol'] && (time() - $botB->config['time']) > $_SESSION['bot_cron']) {
	$user['alcohol'] = $user['alcohol'] ? ($user['alcohol'] - $botB->config['percentage']) : 0;
	if (0 > $user['alcohol']) $user['alcohol'] = 0;
	mysql_query("UPDATE profile SET alcohol = '" . $user['alcohol'] . "' WHERE id = '" . $user['id'] . "'");
	$_SESSION['bot_cron'] = time();
}

if(isset($msg)){
	$botSql = '';
	$botRow = mysql_fetch_assoc(mysql_query("SELECT * FROM profile WHERE id = '" . $botB->config['id_bot'] . "'"));
	$sqlTpl = "
		INSERT INTO chat_msg SET
			ot_user = '316',
			date = '".(time()+1)."',
			msg = '%s',
			room = '1'

	";

	switch ($botB->analysis($msg)) {
	    case '1':
	        $botSql = sprintf($sqlTpl, mysql_real_escape_string('<b>' . $user['login'] . '</b>, ' . $botB->youDrunk()));
	        break;
	    case '2':
	        $botSql = sprintf($sqlTpl, mysql_real_escape_string('<b>' . $user['login'] . '</b>, У тебя не достаточно денег'));
	        break;
	    case '3':
	    	$_SESSION['bot_cron'] = time();
	    	$tost = !$botB->eda ? '<b>Тост:</b> ' . $botB->toast() : '';
	        $botSql = sprintf($sqlTpl, mysql_real_escape_string("<b>" . $user['login'] . "</b>, заказал " . $botB->team . ". Заказ выполнен.\n".$tost));
	        mysql_query("UPDATE profile SET many = '" . $botB->update_money . "', alcohol = '" . $botB->update_alcohol . "' WHERE id = '" . $user['id'] . "'");
	        break;
	}
	$msg = $botB->msg;
	if ($botSql != '') mysql_query ($botSql);
}
//print_r($user);
//print_r($botB->config);
?>