function dicebot($info)
{
    $obj = arr2obj($info);
    /* username to send reply to */
    $to_username = $obj->notifo_from_username;
    /* compute response here */
    $msg = strtolower($obj->notifo_message);
    $arr = explode(" ", $msg);
    $commands_arr = array("flip", "help", "hi", "hello");
    $command = strtolower($arr[0]);
    if (!in_array($command, $commands_arr)) {
        /* invalid command, tell them to send help for info */
        $message = "Send the command 'help' for more info.";
    } else {
        if ($command == "flip") {
            $coins = array("Heads", "Tails");
            $flip = mt_rand(0, 99);
            if ($flip < 50) {
                $flip = 0;
            } else {
                $flip = 1;
            }
            $message = "You flipped a coin: " . $coins[$flip] . ".";
        } else {
            /* sent help, hi, or hello */
            $message = "Hello, send the command 'flip' to flip a coin!";
        }
    }
    $notifo = new Notifo_API(NOTIFO_SERVICE_USERNAME, NOTIFO_APISECRET);
    $notifo->send_message(array("to" => $to_username, "msg" => $message));
}
Example #2
0
/**
 * Converts an array into an object.
 */
function arr2obj($arg_array)
{
    $tmp = new stdClass();
    // start off a new (empty) object
    foreach ($arg_array as $key => $value) {
        if (is_array($value)) {
            // if its multi-dimentional, keep going :)
            $tmp->{$key} = arr2obj($value);
        } else {
            if (is_numeric($key)) {
                // can't do it with numbers :(
                die("Cannot turn numeric arrays into objects!");
            }
            $tmp->{$key} = $value;
        }
    }
    return $tmp;
    // return the object!
}
Example #3
0
 public function dbAttUpdate($db, $filename, $type)
 {
     assert('$this->pub_id != null');
     $filename = $this->pub_id . '/' . $filename;
     $pub->additional_info[] = arr2obj(array('location' => $filename, 'type' => $type));
     // check if already in database
     $r = $db->selectRow('additional_info', 'add_id', array('location' => $filename), 'pdPublication::dbAttUpdate');
     if ($r !== false) {
         return;
     }
     $db->insert('additional_info', array('location' => $filename, 'type' => $type), 'pdPublication::dbAttUpdate');
     $add_id = $db->insertId();
     $db->insert('pub_add', array('pub_id' => $this->pub_id, 'add_id' => $add_id), 'pdPublication::dbAttUpdate');
 }