Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions scripts/gifme.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?
<?php
require('include/curl.php');
require('include/slack.php');
require('include/slack.config.php');
Expand All @@ -13,13 +13,13 @@

$enc = urlencode($command->Text);

$imageSearchJson = get_url_contents('http://ajax.googleapis.com/ajax/services/search/images?v=1.0&safe=active&as_filetype=gif&rsz=8&imgsz=medium&q=animated+'.$enc);
$imageSearchJson = get_url_contents('http://ajax.googleapis.com/ajax/services/search/images?v=1.0&safe=active&as_filetype=gif&rsz=8&imgsz=medium&q=animated+' . $enc);

$imageresponse = json_decode($imageSearchJson);

$userlink = "<https://cim.slack.com/team/{$command->UserName}|{$command->UserName}>";

if($imageresponse->responseData == null){
if ($imageresponse->responseData == null) {
//{"responseData": null, "responseDetails": "qps rate exceeded", "responseStatus": 503}
$details = $imageresponse->responseDetails;
$status = $imageresponse->responseStatus;
Expand All @@ -29,12 +29,11 @@
die;
}

$whichImage = rand(0,7);
$whichImage = rand(0, 7);
$returnedimageurl = $imageresponse->responseData->results[$whichImage]->url;

$payload = "@{$userlink} asked for '{$command->Text}'\n{$returnedimageurl}";

$ret = slack_incoming_hook_post($hook, "gifbot", $command->ChannelName, $iconurl, $emoji, $payload);
if($ret!="ok")
if ($ret != "ok")
print_r("@tdm, gifbot got this response when it tried to post to the incoming hook for /gifme.\n{$ret}");
?>
35 changes: 15 additions & 20 deletions scripts/imageme.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?
<?php
require('include/curl.php');
require('include/slack.php');
require('include/slack.config.php');
Expand All @@ -14,47 +14,42 @@
$maxtries = 2;
$tries = 0;


startover:

$imageresponse = RunImageSearch($command->Text);
$tries++;

if($imageresponse->responseData == null){
if ($imageresponse->responseData == null) {
//{"responseData": null, "responseDetails": "qps rate exceeded", "responseStatus": 503}
$details = $imageresponse->responseDetails;
$status = $imageresponse->responseStatus;

if($status == 503 && $tries < $maxtries)
{
sleep(1);
goto startover; //yeah, it's a goto. deal with it. http://xkcd.com/292/

if ($status == 503 && $tries < $maxtries) {
sleep(1);
goto startover; //yeah, it's a goto. deal with it. http://xkcd.com/292/
}

print_r("Sorry @{$userlink}, no image for you! [{$details}:{$status}]\n");
//print_r($imageresponse);
die;
}

$whichImage = rand(0,7);
$whichImage = rand(0, 7);
$returnedimageurl = $imageresponse->responseData->results[$whichImage]->url;

$payload = "@{$userlink} asked for '{$command->Text}'\n{$returnedimageurl}";

$ret = slack_incoming_hook_post($hook, "imagebot", $command->ChannelName, $iconurl, $emoji, $payload);
if($ret!="ok")
if ($ret != "ok")
print_r("@tdm, gifbot got this response when it tried to post to the incoming hook for /imageme.\n{$ret}");




function RunImageSearch($text)
{
$enc = urlencode($text);

$imageSearchJson = get_url_contents('http://ajax.googleapis.com/ajax/services/search/images?v=1.0&safe=active&rsz=8&imgsz=medium&q='.$enc);
$imageSearchJson = get_url_contents('http://ajax.googleapis.com/ajax/services/search/images?v=1.0&safe=active&rsz=8&imgsz=medium&q=' . $enc);

$imageresponse = json_decode($imageSearchJson);

$imageresponse = json_decode($imageSearchJson);

return $imageresponse;
return $imageresponse;
}
?>
43 changes: 23 additions & 20 deletions scripts/include/curl.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
<?
<?php
//HTTP Utility Methods

function get_url_contents($url) {
$crl = curl_init($url);
function get_url_contents($url)
{
$crl = curl_init($url);

curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);

$response = curl_exec($crl);
curl_close($crl);
return $response;
$response = curl_exec($crl);
curl_close($crl);
return $response;
}

function get_url_contents_with_basicauth($url, $username, $password) {
$crl = curl_init();
function get_url_contents_with_basicauth($url, $username, $password)
{
$crl = curl_init();

curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_USERPWD, "{$username}:{$password}");
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);

$ret = curl_exec($crl);
curl_close($crl);
return $ret;
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}

function curl_post($uri, $data)
Expand All @@ -33,10 +35,11 @@ function curl_post($uri, $data)
curl_setopt($crl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($crl, CURLOPT_POSTFIELDS, $data);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($crl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data)));
curl_setopt($crl, CURLOPT_HTTPHEADER, array(
'Content-Length: ' . strlen($data)
));

$response = curl_exec($crl);
curl_close($crl);
return $response;
}
?>
39 changes: 18 additions & 21 deletions scripts/include/googleimage.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
<?
<?php
/*
built based on the docs here:
https://developers.google.com/image-search/v1/jsondevguide
*/


function BuildSearchCommand($query, $size, $maxresults, $safe, $filetype)
{
$cmd = new stdClass();
$cmd->Size = $size;
$cmd->Query = $query;
$cmd->Count = $maxresults;
$cmd->Safe = $safe;
$cmd->FileType = $filetype;
return $cmd;

$cmd = new stdClass();
$cmd->Size = $size;
$cmd->Query = $query;
$cmd->Count = $maxresults;
$cmd->Safe = $safe;
$cmd->FileType = $filetype;

return $cmd;
}

function GetImageSearchResponse($cmd)
{

$googleImageSearch = "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&safe={$cmd->Safe}&as_filetype={$cmd->FileType}&rsz={$cmd->Count}&imgsz={$cmd->Size}&q={$cmd->Query}";

$result = CallAPI($googleImageSearch);
$googleImageSearch = "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&safe={$cmd->Safe}&as_filetype={$cmd->FileType}&rsz={$cmd->Count}&imgsz={$cmd->Size}&q={$cmd->Query}";

return $result;
$result = CallAPI($googleImageSearch);

return $result;
}

function GetRandomResultFromResponse($n, $result)
{
$resultArray = $result->responseData->results;
$count = count($resultArray);
$item = rand(0,$count-1);
return $resultArray[$item];
$resultArray = $result->responseData->results;
$count = count($resultArray);
$item = rand(0, $count - 1);
return $resultArray[$item];
}

?>
16 changes: 8 additions & 8 deletions scripts/include/log.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?
<?php

function mylog($logfile, $payload)
{
$fh = fopen($logfile,"ra+");
fwrite($fh,time()."\n");
fwrite($fh,$payload);
fwrite($fh,"\n____________________\n");
fclose($fh);
$fh = fopen($logfile, "ra+");
fwrite($fh, time() . "\n");
fwrite($fh, $payload);
fwrite($fh, "\n____________________\n");

fclose($fh);
}
?>
19 changes: 9 additions & 10 deletions scripts/include/memegenerator.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?
<?php

$generators['yodawg'] = "Yo+Dawg+Heard+You";
$generators['allthethings'] = "X+All+The+Y";
$generators['yuno'] = "Y+U+No";
$generators['amitheonlyone'] = "Am+I+The+Only+One+Around+Here";


function CreateNewMeme($gen, $top, $bottom)
{
global $generators;
$meme = $generators[$gen];
$API = "http://apimeme.com/meme?meme={$meme}&top={$top}&bottom={$bottom}";
return $API;
global $generators;

$meme = $generators[$gen];

$API = "http://apimeme.com/meme?meme={$meme}&top={$top}&bottom={$bottom}";

return $API;
}
?>
Loading