Show
Ignore:
Timestamp:
02/16/2008 06:06:40 PM (11 months ago)
Author:
Shadowhand
Message:

Updated Kobot:

  • Added login capabilities
  • Proper log level handling
  • Created Kobot_Server and Kobot_Channel, to be more extensible
  • Added "info" and "register" demo commands
  • Added private message capabilities (user-to-user chat)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/kobot/controllers/kobot.php

    r2055 r2067  
    99 
    1010                // Enable debugging 
    11                 $bog->log_level = 4; 
     11                $bog->log_level = 1; 
    1212 
    1313                // Add triggers 
    1414                $bot->set_trigger('^goodnight, bot$', array($this, 'trigger_quit')) 
     15                    ->set_trigger('^register(.+)?$', array($this, 'register')) 
    1516                    ->set_trigger('^tell (.+?) about (.+)$', array($this, 'trigger_say')) 
    1617                    ->set_trigger('^([r|#])(\d+)$', array($this, 'trigger_trac')) 
    1718                    ->set_trigger('^[a-z_]+$', array($this, 'trigger_default')); 
    1819 
    19                 // Add timers 
    20                 $bot->set_timer(5, array($this, 'say_hi')); 
    21  
    2220                // Login and join the default channel 
    23                 $bot->login('koboto'); 
     21                $bot->login('koboto', 'PhoenixRisingKO'); 
    2422                $bot->join('#koboto'); 
    2523                $bot->read(); 
    2624        } 
     25 
     26        public function register(Kobot $bot, array $data, array $params) 
     27        { 
     28                if ($data['target'] === $bot->username) 
     29                { 
     30                        // Send the message back to the sender 
     31                        $data['target'] = $data['sender']; 
     32 
     33                        if (isset($params[1])) 
     34                        { 
     35                                if (preg_match('/[^a-z\d]+/i', $params[1])) 
     36                                { 
     37                                        // Send the confirmation message 
     38                                        $message = 'You have been registered as '.$data['sender']; 
     39                                } 
     40                                else 
     41                                { 
     42                                        // Send the registration error 
     43                                        $message = 'Passwords may only contain letters and numbers'; 
     44                                } 
     45                        } 
     46                        else 
     47                        { 
     48                                // Send the register usage, no password was supplied 
     49                                $message = 'Usage: register <password>'; 
     50                        } 
     51                } 
     52                else 
     53                { 
     54                        // Only allow registration in private messages 
     55                        $message = $data['sender'].': Send me a private message: /msg '.$bot->username.' register <password>'; 
     56                } 
     57 
     58                // Send the response message 
     59                $bot->send('PRIVMSG '.$data['target'].' :'.$message); 
     60        } 
     61 
    2762 
    2863        public function say_hi(Kobot $bot) 
     
    5085        public function trigger_say(Kobot $bot, array $data, array $params) 
    5186        { 
    52                 switch ($params[1]) 
     87                switch ($params[2]) 
    5388                { 
    5489                        case 'yourself': 
    55                                 $bot->send('PRIVMSG '.$data['target'].' :Who wants to know? '.$params[0].'? HA!'); 
     90                                $bot->send('PRIVMSG '.$data['target'].' :Who wants to know? '.$params[1].'? HA!'); 
    5691                        break; 
    5792                }