Skip to content

Instantly share code, notes, and snippets.

@mreidsma
Created October 9, 2012 21:17
Show Gist options
  • Select an option

  • Save mreidsma/3861503 to your computer and use it in GitHub Desktop.

Select an option

Save mreidsma/3861503 to your computer and use it in GitHub Desktop.
Bukk.it Roulette - pull a random image from Bukk.it with your Botriot Campfire bot.
<?php
$gotit = 0; // BOOLEAN for knowing that a command has been found
// Get the data from Bruce, our Campfire bot
$data = file_get_contents('php://input');
if($data == NULL) {
$command = "Weird.";
} else {
$values = json_decode($data);
$command = $values->{'text'};
$person = $values->from->name;
}
// Break up command into units
$cmd = explode(" ", $command);
if(($cmd[0] == "bukkit") && ($gotit != 1)) {
header('HTTP/1.1 200 OK');
$url = 'http://bukk.it/';
$html = file_get_contents($url);
$count = preg_match_all('/<td><a href="([^"]+)">[^<]*<\/a><\/td>/i', $html, $files);
$number = rand(1,$count);
//echo '{"speak": "Ok, here is your random image from Bukk.it"}';
echo '{"image": "http://bukk.it/' . $files[1][$number] . '"}';
$gotit = 1;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment