Вход Регистрация
Файл: social12/chat/bartender.php
Строк: 84
<?php

class bot_bartender {
    public 
$msg;
    public 
$team;
    public 
$update_balls;
    public 
$update_alcohol;
    public 
$config;
    public 
$drinks = array();
    public 
$food = array();
    public 
$youDrunk = array();
    public 
$userProfile = array();
    public 
$eda;

    
/*
    * $login   - Логин юзера
    * $alcohol - уровень опьянения юзера
    * $balls   - Количество бубликов на счету у юзера
    * $keyLog  - Ключ (ид юзера) для лога его покупок
    */

    
function __construct($alcohol$balls$keyLog) {
        
$this->alcohol $alcohol;
        
$this->balls $balls;
        
//Лог файл
        
$this->logFole '../bot_bartender/log/'.$keyLog.'.dat';
        
$this->config parse_ini_file('../bot_bartender/config.ini');
        
//Авто Очистка лога
        
if (!$alcohol && file_exists($this->logFole)) unlink($this->logFole);

    }

    
/*
    * Анализ сообщение
    * $msg - Сообшение
    * Функция возвращает
    * 1 - если чел слишком пьян
    * 2 - если у чела нет бубликов для оплаты
    * 3 - Заказ выполнен
    */

    
public function analysis($msg) {
        global 
$user;
        
$this->msg $msg;
        
preg_match("#!(.*?)(s|$)#i"$msg$arr);
        if (
$this->alcohol $this->config['font']) {
                
$this->msg $this->font($msg);
        }
        
/*Стриптиз*/
        
$mony_strip 5//Цена стриптиза
        
$strip = array('стрип''стриптиз''strip''striptiz');

        if (
in_array(mb_strtolower($arr[1], 'UTF-8'), $strip)) {
            if (
$mony_strip $this->balls) return 2;
            
$this->eda true//Чтоб тост не говорило
            
$this->team 'стриптиз';
            
$this->setLog();
            
$this->team .= ' <img src="../resize.php?img='.ltrim($this->randImg(), './').'&width=80&height=0" alt="" />';
            
$this->update_balls $this->balls $mony_strip;
            
$this->update_alcohol $user['alcohol'];
            return 
3;
        }

        
$sql mysql_query("SELECT * FROM `bot_bartender_product` WHERE `name` = '".mysql_real_escape_string(mb_strtolower($arr[1], 'UTF-8'))."'");
        
$res mysql_fetch_assoc($sql);
        if (!empty(
$res['name'])) {
            
$this->eda $res['alcohol'] < true false;
            
$this->update_alcohol $this->alcohol $this->alcohol $res['alcohol'] : $res['alcohol'];
            if (!
$this->eda && ($this->update_alcohol $this->config['youdrunk'])) {
                return 
1;
            } elseif (
$res['price'] > $this->balls) {
                return 
2;
            } else {
                
$this->update_balls $this->balls $res['price'];
                if (
$this->update_alcohol >= 100) {
                    
$this->update_alcohol 100;
                } elseif (
$this->update_alcohol 0) {
                    
$this->update_alcohol 0;
                }
                
$this->update_alcohol abs($this->update_alcohol);
                
$this->team $res['name'];
                
$this->setLog();
                if (
is_file('../upload/bot_bartender/'.$res['id'].'.img')) {
                    
$this->team .= ' <img src="../resize.php?img=upload/bot_bartender/'.$res['id'].'.img&width=55&height=0" alt="" />';
                }

                return 
3;
            }
        }
    }

    
//Случайный тост
    
public function toast() {
        
$data file('../bot_bartender/toast.dat');
        return 
$data[array_rand($data)];
    }
    
//Случайное оповешение о том что юзер пьян
    
public function youDrunk() {
        
$data file('../bot_bartender/you_drunk.dat');
        return 
$data[array_rand($data)];
    }
    
//Преобразование текста в ПрЫгАюЩиЙ регистр
    
public function font($msg) {
        
$msg iconv('UTF-8''windows-1251'$msg);
        
$count strlen($msg);
        for(
$i 0$i $count$i++) {
            
$r $r 1;
            
$txt .= $r mb_strtoupper($msg[$i], 'windows-1251') : mb_strtolower($msg[$i], 'windows-1251');
        }
        return 
iconv('windows-1251',  'UTF-8'$txt);
    }
    
//Запись в лог покупок
    
public function setLog() {
        
$fp fopen($this->logFole'a+');
        
flock ($fpLOCK_EX);
        if (
$this->team != 'стриптиз'fwrite($fp$this->team '(' date("d.m.Y H:i") . ')<br/>');
        
flock ($fpLOCK_UN);
        
fclose($fp);
        @
chmod($this->logFole0666);
    }
    
//Загрузка лога
    
public function getLog() {
        return 
file_exists($this->logFole) ? file_get_contents($this->logFole) : 'История пока пуста...';
    }
    
//Случайная картинка стриптиза
    
public function randImg() {
        
$data unSerialize(file_get_contents('../bot_bartender/strip.dat'));
        return 
$data[array_rand($data)];
    }
}
?>
Онлайн: 0
Реклама