示例#1
0
文件: github.php 项目: ZaneA/ProtoIRC
    $irc->send($channel, 'Please wait..');
    $irc->async(function ($irc) use($githubFeed, $channel) {
        $feed = @file_get_contents("https://github.com/api/v2/json/commits/list/{$githubFeed->name}/{$githubFeed->repo}/{$githubFeed->branch}");
        if (!empty($feed)) {
            $json = json_decode($feed);
            for ($i = 0; $i < 3; $i++) {
                if (isset($json->commits[$i])) {
                    $commit = $json->commits[$i];
                    $irc->send($channel, "{$commit->id}: {$commit->message}");
                }
            }
        } else {
            $irc->send($channel, 'Unable to fetch feed at this time');
        }
    });
});
$irc->msg('/^!commit (.*)/', function ($irc, $nick, $channel, $commit) use($githubFeed) {
    $irc->send($channel, 'Please wait..');
    $irc->async(function ($irc) use($githubFeed, $channel, $commit) {
        $feed = @file_get_contents("https://github.com/api/v2/json/commits/show/{$githubFeed->name}/{$githubFeed->repo}/{$commit}");
        if (!empty($feed)) {
            $json = json_decode($feed);
            $commit = $json->commit;
            $irc->send($channel, "{$commit->id}: {$commit->message}");
        } else {
            $irc->send($channel, 'Unable to fetch commit at this time');
        }
    });
});
$irc->go();