Пример #1
0
<?php

require 'include/curl.php';
require 'include/slack.php';
require 'include/slack.config.php';
$command = BuildSlashCommand($_REQUEST);
$hook = $config['slack']['hook'];
//use one or the other of $emoji or $iconurl
$emoji = null;
$iconurl = "http://upload.wikimedia.org/wikipedia/en/1/13/Stick_figure.png";
$comicid = $command->Text;
$xkcdapi = "http://xkcd.com/{$comicid}/info.0.json";
$json = get_url_contents($xkcdapi);
$xkcdresponse = json_decode($json);
$alt = $xkcdresponse->alt;
$image = $xkcdresponse->img;
$payload = "{$image}\n<http://xkcd.com/{$comicid}/|{$alt}>\n";
$ret = slack_incoming_hook_post($hook, "xkcdbot", $command->ChannelName, $iconurl, $emoji, $payload);
if ($ret != "ok") {
    print_r("@tdm, gifbot got this response when it tried to post to the incoming hook.\n{$ret}");
}
Пример #2
0
/*
token=K2gDHdWZvZSmwOkW9O6yVbA7
team_id=T0001
channel_id=C2147483705
channel_name=test
timestamp=1355517523.000005
user_id=U2147483697
user_name=Steve
text=googlebot: What is the air-speed velocity of an unladen swallow?
*/
//meme generator API
$cmd = BuildSlashCommand($_REQUEST);
$payload = json_encode($cmd);
mylog('received.txt', $payload);
$cmdText = $cmd->Text;
$memetext = str_replace("memebot ", "", $cmdText);
$parts = explode("/", $memetext);
$gen = $parts[0];
$top = urlencode($parts[1]);
$bottom = urlencode($parts[2]);
$meme = CreateNewMeme($gen, $top, $bottom);
mylog('sent.txt', $meme);
$response = slack_incoming_hook_post($config['slack']['hook'], $cmd->UserName, $cmd->ChannelName, null, ":bow:", $meme);
mylog('sent.txt', $response);
//str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
//print_r($cmd->Text);die;
//$out = new stdClass();
//$out->text = $meme;
//$json = json_encode($out);
//mylog('sent.txt',$json);
//print_r($json);