Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created February 15, 2014 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikr7/9019043 to your computer and use it in GitHub Desktop.
Save ikr7/9019043 to your computer and use it in GitHub Desktop.
tmhOAuth( https://github.com/themattharris/tmhOAuth ) が必要です
<?php
require "/tmhOAuth.php";
$consumer_key = "";
$consumer_secret = "";
$user_token = "";
$user_secret = "";
$tmhOAuth = new tmhOAuth(
array(
"consumer_key" => $consumer_key,
"consumer_secret" => $consumer_secret,
"user_token" => $user_token,
"user_secret" => $user_secret
)
);
$method = "https://userstream.twitter.com/2/user.json";
$params = array();
$tmhOAuth -> streaming_request("POST", $method, $params, "callback", false);
function callback($data, $length, $metrics){
global $tmhOAuth;
@$res = json_decode($data);
if(isset($res -> text)){
$text = $res -> text.PHP_EOL;
$pattern = "/^\s*@iku_iku_ikura\s+(Sabatora|Walls1|ZD|Blitz|Chatora|CTW|Chatora 2|Paintball)\s*$/";
$result = preg_match($pattern, $text, $m);
if($result == 1){
$servers = json_decode(file_get_contents("https://pvp.minecraft.jp/servers.json")) -> servers;
foreach($servers as $server){
if($server -> Server -> name == $m[1]){
$tmhOAuth -> request("POST", $tmhOAuth->url("1.1/statuses/update"), array(
"status" => "@".$res->user->screen_name." ".$server -> Server -> name." の現在のマップは ".$server -> Server -> currentMap." で、 ".$server -> Server -> player_count." 名のプレイヤーがオンラインです。次のマップは ".$server -> Server -> nextMap." です。",
"in_reply_to_status_id" => $res->id_str
));
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment