Skip to content

Instantly share code, notes, and snippets.

@KuJoe
Created August 16, 2020 12:44
Show Gist options
  • Save KuJoe/0d44704bd9742de5f8b5415d6cc33315 to your computer and use it in GitHub Desktop.
Save KuJoe/0d44704bd9742de5f8b5415d6cc33315 to your computer and use it in GitHub Desktop.
<?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