Created
August 16, 2020 12:44
-
-
Save KuJoe/0d44704bd9742de5f8b5415d6cc33315 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Quick and dirty script to check and notify me when a Twitch channel gets Affiliate status. | |
# https://github.com/KuJoe | |
$lockfile = '/DIR/TO/FILE.LOCK'; | |
if (file_exists($lockfile)) { | |
exit; | |
} else { | |
$twitch = '<TWITCH_USERNAME>'; | |
function getTwitchAPI($url) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Authorization: Bearer <OAUTH TOKEN>', | |
'Client-ID: <TWITCH_DEV_CLIENT_ID>' | |
)); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
} | |
function usersTwitch($twitch) { | |
$url = 'https://api.twitch.tv/helix/users?login='.$twitch; | |
$result = json_decode(getTwitchAPI($url), true); | |
if(!$result['data'][0]) { | |
return false; | |
} else { | |
if($result['data'][0]['broadcaster_type'] == 'affiliate') { | |
$type = "Affiliate"; | |
} elseif($result['data'][0]['broadcaster_type'] == 'partner') { | |
$type = "Partner"; | |
} else { | |
$type = "Standard"; | |
} | |
return $type; | |
} | |
} | |
$type = usersTwitch($twitch); | |
echo $type; | |
if($type === 'Affiliate') { | |
mail("<YOUR_EMAIL>","<SUBJECT>","<MSG>"); | |
fopen($lockfile, "w"); | |
} else { | |
exit; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment