verify = array(); // register module (for use in custom raid module) $this->register_module('roll'); // register commands $this -> register_command('all', 'roll', 'ANONYMOUS'); $this -> register_command('all', 'verify', 'ANONYMOUS'); $this -> help['description'] = 'Leader starts roll for item and then people roll'; $this -> help['command']['roll start '] = "Starts roll. You need to put item for which is roll."; $this -> help['command']['roll end'] = "Ends roll and shows result."; $this -> help['command']['roll verify'] = "Shows the result of last roll."; $this -> help['command']['roll me'] = 'Rolls for person that sent a tell, return result of that persons roll.'; $this -> help['command']['roll for '] = 'Rolls for separated by comma ( , ).'; $this -> help['command']['roll all'] = 'Shows ALL rolls that were rolled on bot'; $this -> help['command']['verify'] = "Same as roll verify, but guests can also use this command."; $this->help['notice'] = 'Everyone can roll and everyone can see who rolled what...'; } /* command handler */ public function command_handler($name, $msg, $origin) { // parse the message $com = $this->parse_com($msg, array('cmd', 'sub', 'args')); // roll if ($com['cmd'] == 'roll') { // start roll (people will roll for themselves) if ($com['sub'] == 'start') { return $this->roll_start($name, $com['args']); } // roll for yourself else if ($com['sub'] == 'me') { return $this->roll_me($name); } // end roll else if ($com['sub'] == 'end') { return $this->roll_end($name); } // roll for some people (person1,person2,person3) else if($com['sub'] == 'for') { return $this->roll_for($name, $com['args']); } // show all rolls else if ($com['sub'] == 'all') { return $this->roll_show_all($name); } // clear all rols, ADMIN and above access level else if ($com['sub'] == 'clear' && $this->bot->core("security")->check_access($name, "ADMIN")) { return $this->roll_clear(); } // verify roll else if ($com['sub'] == 'verify') { return $this->verify(); } } // verify roll else if ($com['cmd'] == 'verify') { return $this->verify(); } else { $this->bot->send_help($name); } } /* start roll (people will roll for themselves) */ public function roll_start($name, $item) { // if roll is allready on if ($this->roll_on) {return 'Roll is allready running!';} // if there is no item if (empty($item)) {$item = 'Unknown item';} $this->item = $item; $this->cur_id++;// id of this roll $text = 'Roll for item '.$this->item.' has started! Rollers can roll now!'; $this->roll_on = true; // info on roll $this->info[ $this->cur_id ] = array( 'user' => $name, 'time' => time(), ); $this->rollers[ $this->cur_id ] = array(); $this->rolled[ $this->cur_id ] = array(); unset($name, $item); return $text; } /* person rolls */ public function roll_me($name) { // if roll is on its ok, othrwise return if (!$this->roll_on) {return 'There is no roll running!';} // if person allready has rolled... if (isset($this->rollers[ $this->cur_id ][ $name ])) {return 'No cheating please!';} // roll itself $b = $this->bot->core("tools")->my_rand(1, 100); // loop so there are no 2 same rolls while(isset($this->rolled[ $this->cur_id ][ $b ])) {$b = $this->bot->core("tools")->my_rand(1, 100);} // add roll to array $this->rollers[ $this->cur_id ][ $name ] = $b; $this->rolled[ $this->cur_id ][ $b ] = $name; return 'Yu have rolled '.$b.', wait for roll to end to see results.'; } /* end roll */ public function roll_end() { // if there is no rolls return if (!$this->roll_on) {return 'No rolls have started! Start a roll first!';} // sort rolls so last one is the winner ksort($this->rolled[ $this->cur_id ]); // window creation $window = "##blob_title##::: Roll verification :::##end##\n\n"; $window .= "Rolled on item: ".$this->item."\n"; $window .= "Roller: ##highlight##".$this->name."##end##\n"; $window .= "Time of roll: ##highlight##".date('H:i:s d.m.Y.', time())."##end##\n"; $window .= "-----------------\n"; foreach ($this->rolled[ $this->cur_id ] as $v => $r) { $window .= $r.": ".$v."\n"; unset($r, $v); } $window .= "-----------------\n"; // make blob and put it into variable $this->last_roll_blob = $this->bot->core('tools')->make_blob("Roll results", $window); unset($window); // set roll status to false $this->roll_on = false; // return window return $this->last_roll_blob; } /* roll for somebody */ public function roll_for($name, $msg) { $msg = trim($msg); $text = 'There is nobody to roll for!'; $this->name = $name; // there needs to be a list of who to roll for (separated by ,) if ($rollers = explode(',', $msg)) { // must be more than one in array if (count($rollers) > 1) { $this->cur_id++;// id of this roll // info on roll $this->info[ $this->cur_id ] = array( 'user' => $name, 'time' => time(), ); // go throught foreach ($rollers as $r) { $r = trim($r); // name can contain only alfanumerical symbols if (eregi("^([a-zA-Z0-9]+)$", $r)) { // check that there is no 2 same names if (!isset($this->rollers[ $this->cur_id ][ $r ])) { $b = $this->bot->core("tools")->my_rand(1, 100); while(isset($this->rolled[ $this->cur_id ][ $b ])) {$b = $this->bot->core("tools")->my_rand(1, 100);} $this->rolled[ $this->cur_id ][ $b ] = $r; $this->rollers[ $this->cur_id ][ $r ] = $b; } } unset($r); } // sort array so winner is last ksort($this->rolled[ $this->cur_id ]); $window = "##blob_title##::: Roll verification :::##end##\n\n"; $window .= "Roller: ##highlight##".$this->name."##end##\n"; $window .= "Time of roll: ##highlight##".date('H:i:s d.m.Y.', time())."##end##\n"; $window .= "-----------------\n"; foreach ($this->rolled[ $this->cur_id ] as $v => $r) { $window .= $r.": ".$v."\n"; unset($r, $v); } $window .= "-----------------\n"; // make blob and put it into variable $this->last_roll_blob = $this->bot->core('tools')->make_blob("Roll results", $window); unset($window); // return window return $this->last_roll_blob; } else { $text = 'There is no point in rolling for only 1 character!'; } } unset($name, $msg); return $text; } /* last roll */ public function verify() { // if roll is turned on if ($this->roll_on) {return 'Roll is still running!';} // if there is no last roll blob else if(empty($this->last_roll_blob)) {return "No previous roll!";} // return last roll blob return $this->last_roll_blob; } /* show all rolls */ public function roll_show_all($name) { // is there any data if (count($this->rolled) == 0) {return 'There is no rolls!';} // header part of window $window = "##blob_title##::: All rolls :::##end##\n\n"; $window .= "-----------------\n"; // go through ALL rolls and create window foreach ($this->info as $id => $i) { $window .= "-----------------\n"; $window .= "Roller: ##highlight##".$i['user']."##end##\n"; $window .= "Time of roll: ##highlight##".date('H:i:s d.m.Y.', $i['time'])."##end##\n"; // sort roller so winner is last ksort($this->rolled[ $id ]); foreach ($this->rolled[ $id ] as $r => $v) { $window .= $r.": ".$v."\n"; unset($r, $v); } $window .= "-----------------\n"; unset($id, $i); } // make blob $window = $this->bot->core('tools')->make_blob("All roll results", $window); // return window return $window; } /* očisti roll buffer */ public function roll_clear() { unset($this->rolled, $this->rollers, $this->info); $this->rolled = $this->rollers = $this->info = array(); $this->last_roll_blob = ''; $this->cur_id = 0; } } ?>