User:Cakemix/Snippets/PHP/8 Ball

JSBot's 8ball, pure written. public static function onCommand8BALL(event $event, $nick = null, $args = array(1), $dh = null, $alias = '8B', $help = '8BALL my friend 8BALL.') { /* Removed some bot class stuff that was here. */                   if (settings::get('8ball.Random') == "0") $rdn = false; ? $rdn = true;

$responses = array(                       'AMG NO, WHERE DID ALL THE QUESTIONS GO D: (there used to be 62 questions)'); $question = $dh->getCommandTrailing; $Symbols = array('?', '!', '"', '\'', ' ', '.');                   if ($rdn) {                        //↓ Made the little code so dirty :(                        /* Bye letters and Hello numbers *//* Trim for teh lulz *//* I luv md5 (it always include numbers so yea...) :3 *//* Stupid high cases didn't include <.< *//* Stupid high cases didn't include <.< *//* Get the 2 first letters to it can max be 99 :3 */                        $i = substr(preg_replace('/[a-zA-Z]+/', null, trim(md5(strtolower($question)))), 0, 2); //Fixes the little random :3                        if ($i < 62) {                            $response = $responses[$i];                        }

if (!$response) { $i = round($i / 1.6); //If the i is more then 62 it redoes the little i to a smaller i (Max i number is 99, and if i / 1.6 (99/1.6) it gives 61.875 which is rounded to 62 = fail proof :3, now go to your math class and learn something!). if ($i < 62) { $response = $responses[$i]; }

if (!$response) { //Uhm, if this is called we might just go and delete this file because then there is no bullet proof php script... $response = $responses[array_rand($responses)]; }                       }                    } else {//if ($rdn) { $response = $responses[array_rand($responses)]; //Woot for cheap random? }                  if (array_search(substr($response, -1, 1), $Symbols)) { //if the end misses a symbol it adds it (Well I was to lazy to go trough 62 items I took like 20 min to find this (Would be easier to find if I had internet...)). $response.=$Symbols[5]; //Also $response.='.'; in just a more fun way }                   $dh->reply("[\003078 BALL\003]: The magic 8 ball says in response to \"\00305$question\003\": \00305$response\003"); }            }