From 4e824cbc5c89a2ad565314e32003d729f91fb6df Mon Sep 17 00:00:00 2001 From: ilias-sp Date: Sat, 25 Sep 2021 20:10:56 +0300 Subject: [PATCH] Twitch API removed --- README.md | 8 - VERSION.md | 2 +- conf/channel_credentials.php.TEMPLATE | 13 - conf/config.php.TEMPLATE | 5 - documentation/Using_Twitch_API.md | 41 --- lib/IzyBot.php | 303 +++++++----------- ...TwitchAPI.php => TwitchAPI.php.deprecated} | 65 ++-- startIzyBot.php | 1 - 8 files changed, 152 insertions(+), 286 deletions(-) delete mode 100755 documentation/Using_Twitch_API.md rename lib/{TwitchAPI.php => TwitchAPI.php.deprecated} (82%) diff --git a/README.md b/README.md index 7d4cd5c..2674264 100755 --- a/README.md +++ b/README.md @@ -86,14 +86,6 @@ Unless, you have defined otherwise in the `conf/config.php`, the bot supports th | !editcmd | used to update the response of an existing command. | | !removecmd | used to remove an existing command. | -- Twitch API v5 commands (to enable these commands, additional configuration is needed, please check [here](documentation/Using_Twitch_API.md)): - -| Command | Purpose | -| ----------------------- | ----------------------- | -| !title | Change the Channel's title | -| !game | Change the Channel's game | -| !issub | Check if a user is subscribed to your channel (this command will only work if you are running the bot using your Channel's account) | - - Bot's administrators management: | Command | Purpose | diff --git a/VERSION.md b/VERSION.md index ac32732..35da9a8 100755 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -VERSION=4.0.2 +VERSION=4.0.3 diff --git a/conf/channel_credentials.php.TEMPLATE b/conf/channel_credentials.php.TEMPLATE index 25a6dfb..5a0d441 100755 --- a/conf/channel_credentials.php.TEMPLATE +++ b/conf/channel_credentials.php.TEMPLATE @@ -19,16 +19,3 @@ $config['nickname'] = ''; // in the URL of your stream, for example if your stream is : https://www.twitch.tv/abc123, you need // to fill in: abc123 $config['channel'] = ''; - - -// FIll in your Twitch App details. Needed for querying the Twitch API (find out if viewer is a channel's sub, change streams title, etc). -$config['app_client_id'] = ''; -$config['app_client_secret'] = ''; -// To generate an Oath token for your Twitch App, you need to open the below URL in your browser querying the below site. -// First replace the string XXXXX with your Twitch App's client-ID: -// -// https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=XXXXXXXXXXXX&redirect_uri=https://twitchapps.com/tokengen/&scope=channel_check_subscription+channel_editor -// -// Make sure your Twitch App has as "OAuth Redirect URLs" the website: "https://twitchapps.com/tokengen/" -// -$config['oath_twitchAPI_token'] = ''; diff --git a/conf/config.php.TEMPLATE b/conf/config.php.TEMPLATE index 42253a7..1f5f9ec 100755 --- a/conf/config.php.TEMPLATE +++ b/conf/config.php.TEMPLATE @@ -107,11 +107,6 @@ $config['loyalty_points_welcome_award'] = 1000; // amount of LP awarded to new v $config['loyaltypoints_keyword'] = '!izyeuros'; -// twitch API related commands: -$config['admin_twitchapi_set_stream_title'] = '!title'; -$config['admin_twitchapi_set_stream_game'] = '!game'; -$config['admin_twitchapi_is_user_a_sub'] = '!issub'; - // twitch VIP commands: $config['admin_addvip_command'] = '!addvip'; $config['admin_removevip_command'] = '!removevip'; diff --git a/documentation/Using_Twitch_API.md b/documentation/Using_Twitch_API.md deleted file mode 100755 index ae6e7fc..0000000 --- a/documentation/Using_Twitch_API.md +++ /dev/null @@ -1,41 +0,0 @@ -# setting up the Bot to use Twitch API - -## step 1 - create a Twitch APP - -To use the Twitch API, you need to set up a Twitch App first. - -1. visit `https://dev.twitch.tv/dashboard`. -2. switch to `Apps`. -3. Create a new App. You **must** set the redirect URL to `https://twitchapps.com/tokengen/`. This is an external website that we can use to generate a token for our application. -4. Get the `Client ID` and `Client Secret` and save them in the `channel_credentials.php` file. - - -## step 2 - get a token with advanced permissions for actions related to the IRC (scopes) - -to change the channel's title or game, the Oath token your bot will use, has to have extra permissions than the default tokens do. - -1. visit the [https://twitchapps.com/tmi/](https://twitchapps.com/tmi/) website. If you are using another Twitch account to run the bot, make sure you visit this URL with a browser that is logged in to Twitch using the Bots account, not the account of your Channel! -2. Right click the `Connect with Twitch` button, copy the URL it points to to your clipboard. -3. Paste the URL to a text editor. -4. Notice the `scope` parameter in the URL. it probably includes only these entries: `chat:read+chat:edit+channel:moderate`. -5. Append more scopes, separating each scope from others with the `+` symbol. List of scopes can be found at [official Twitch website](https://dev.twitch.tv/docs/authentication/#scopes). -6. For your convenience, you can use this scopes collection: `chat:read+chat:edit+channel:moderate+channel_editor+channel_check_subscription`. -7. Paste the updated URL to your browser, and hit enter to visit the link. You will be prompted to confirm your action by Twitch server, then you will receive the Oath token on your screen. Paste this Oath key to `channel_credentials.php` file, at `$config['oath_IRC_chat_pass']` variable. - -Configuration is complete. The bots account should be able to access the Twitch API and run the desired elevated actions. - - -## step 3 - get a token with advanced permissions (scopes) - -To utilize Twitch APIs capabilities to check if a specific user is a subscriber, to change the stream's title etc. We need to get an Oath token first associated with our Twitch App. -This Token should not be confused with the token we use for the chat bot to login to Twitch IRC!. - -1. Inspect the below URL, replace the `XXXXXX` with your Twitch App's Client ID: - -``` -https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=XXXXXX&redirect_uri=https://twitchapps.com/tokengen/&scope=channel_check_subscription+channel_editor -``` -2. Notice the `scope` parameter in the URL. it includes only these entries: `channel_check_subscription+channel_editor`. -7. Paste the updated URL to your browser, and hit enter to visit the link. You will be prompted to confirm your action by Twitch server, then you will receive the Oath token on your screen. Paste this Oath key to `channel_credentials.php` file, at `$config['oath_twitchAPI_token']` variable. - -Configuration is complete. The bots account should be able to access the Twitch API and run the desired elevated actions. diff --git a/lib/IzyBot.php b/lib/IzyBot.php index f13888f..96f1fdc 100755 --- a/lib/IzyBot.php +++ b/lib/IzyBot.php @@ -5,7 +5,7 @@ use \DateTime; // use IZYBOT\lib\AppDataHandler as AppDataHandler; -define('APPVERSION', '4.0.2'); +define('APPVERSION', '4.0.3'); @@ -45,8 +45,8 @@ class IzyBot { private $oath_token_expiration_date; private $twitch_oath_token_data_file; - private $app_client_id; - private $app_client_secret; + // private $app_client_id; + // private $app_client_secret; // bot commands usage stats: private $bot_commands_usage; @@ -131,7 +131,7 @@ public function __construct($config) // classes: $this->appdatahandler = new AppDataHandler($this->bot_config, $this->logger); - $this->twitchapi = new Twitchapi($this->bot_config, $this->TwitchAPI_logger); + // $this->twitchapi = new Twitchapi($this->bot_config, $this->TwitchAPI_logger); // logging info: // $this->log_file = APPPATH . '/log/' . $config['log_file'] . '__' . date('Ymd_H_i') . '.txt'; @@ -143,8 +143,8 @@ public function __construct($config) $this->channel = '#' . $config['channel']; $this->bot_name = $config['bot_name']; - $this->app_client_id = $this->bot_config['app_client_id']; - $this->app_client_secret = $this->bot_config['app_client_secret']; + // $this->app_client_id = $this->bot_config['app_client_id']; + // $this->app_client_secret = $this->bot_config['app_client_secret']; // disable below exception until twitch fix: @@ -185,9 +185,6 @@ public function __construct($config) $config['admin_endbet_keyword'], $config['admin_cancelbet_keyword'], $config['bet_place_keyword'], - $config['admin_twitchapi_set_stream_title'], - $config['admin_twitchapi_set_stream_game'], - $config['admin_twitchapi_is_user_a_sub'], $config['admin_addvip_command'], $config['admin_removevip_command'], $this->bot_config['botinfocommand_keyword'] @@ -420,86 +417,18 @@ private function _read_twitch_oath_token() $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Using the Oauth token found in channel_credentials.php file.'); $this->oath_token = $this->bot_config['oath_IRC_chat_pass']; - goto ENDOFPROCESSING; } - // - $twitch_oath_token_text = $this->appdatahandler->ReadAppDatafile($this->twitch_oath_token_data_file, 'READ'); - - if ($twitch_oath_token_text[0] === TRUE) - { - $twitch_oath_token_array = json_decode($twitch_oath_token_text[2], true); - if (!is_array($twitch_oath_token_array)) - { - - $this->logger->log_it('ERROR', __CLASS__, __FUNCTION__, 'Twitch API oath data file: ' . $this->twitch_oath_token_data_file . ' is malformed.'); - $this->_get_new_twitch_oath_token(); - - } - else { - - $this->oath_token_expiration_date = $twitch_oath_token_array[1]; - - if (date('U') < $this->oath_token_expiration_date) { - - $this->oath_token = $twitch_oath_token_array[0]; - - } - else { - - $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Twitch API oath token expired on: ' . date('d/m/Y, H:i:s', $this->oath_token_expiration_date) . ". Getting a new one.."); - $this->_get_new_twitch_oath_token(); - - } - - } - } else { - - $this->_get_new_twitch_oath_token(); - - } - ENDOFPROCESSING: - $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Twitch API oath token loaded from file: ' . $this->oath_token . ", expires on: " . date('d/m/Y, H:i:s', $this->oath_token_expiration_date) . "."); - - } - //---------------------------------------------------------------------------------- - // - //---------------------------------------------------------------------------------- - private function _get_new_twitch_oath_token() - { - - // NOT WORKING! :() - - $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Getting new oath token from Twitch API..'); - - $url = 'https://id.twitch.tv/oauth2/token?client_id=' . $this->app_client_id . '&client_secret=' . $this->app_client_secret . '&grant_type=client_credentials&scope=' . $this->bot_config['oath_token_scope']; - - $api_call = $this->twitchapi->_run_twitch_api_call($url, 'POST', NULL, NULL, FALSE); - - if (! isset($api_call[1]['http_code'])) { - - echo __CLASS__ . ': API call to get oath token from Twitch API failed. Exiting.. ' . "\n"; - throw new \Exception('API call to get oath token from Twitch API failed. Exiting..'); - - } - // - if ($api_call[1]['http_code'] != 200) { - echo __CLASS__ . ': API call to get returned with error. Exiting.. ' . "\n"; - throw new \Exception('API call to get returned with error. Exiting..'); + echo __CLASS__ . ": No token provided for accessing Twitch Chat. Variable: config['oath_IRC_chat_pass'] is missing. Exiting.. " . "\n"; + throw new \Exception("No token provided for accessing Twitch Chat. Variable: config['oath_IRC_chat_pass'] is missing. Exiting.."); } - // - $json_response = json_decode($api_call[0]); - - $this->oath_token = $json_response->access_token; - $this->oath_token_expiration_date = $json_response->expires_in + date('U'); - - $this->_write_oath_token_data(); - - return TRUE; + ENDOFPROCESSING: + $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Twitch API oath token loaded from file: ' . $this->oath_token . "."); + } //---------------------------------------------------------------------------------- // @@ -771,27 +700,27 @@ private function _process_user_message($username, $channel, $message_text) $this->_bot_command_add_usage($this->bot_config['quote_keyword']); return TRUE; } - elseif ($words_in_message_text[0] === $this->bot_config['admin_twitchapi_set_stream_title']) - { - $this->_set_stream_title($words_in_message_text, $channel, $message_text); - // add the bot command to usage: - $this->_bot_command_add_usage($this->bot_config['admin_twitchapi_set_stream_title']); - return TRUE; - } - elseif ($words_in_message_text[0] === $this->bot_config['admin_twitchapi_set_stream_game']) - { - $this->_set_stream_game($words_in_message_text, $channel, $message_text); - // add the bot command to usage: - $this->_bot_command_add_usage($this->bot_config['admin_twitchapi_set_stream_game']); - return TRUE; - } - elseif ($words_in_message_text[0] === $this->bot_config['admin_twitchapi_is_user_a_sub']) - { - $this->_check_user_is_sub($words_in_message_text, $channel, $message_text); - // add the bot command to usage: - $this->_bot_command_add_usage($this->bot_config['admin_twitchapi_is_user_a_sub']); - return TRUE; - } + // elseif ($words_in_message_text[0] === $this->bot_config['admin_twitchapi_set_stream_title']) + // { + // $this->_set_stream_title($words_in_message_text, $channel, $message_text); + // // add the bot command to usage: + // $this->_bot_command_add_usage($this->bot_config['admin_twitchapi_set_stream_title']); + // return TRUE; + // } + // elseif ($words_in_message_text[0] === $this->bot_config['admin_twitchapi_set_stream_game']) + // { + // $this->_set_stream_game($words_in_message_text, $channel, $message_text); + // // add the bot command to usage: + // $this->_bot_command_add_usage($this->bot_config['admin_twitchapi_set_stream_game']); + // return TRUE; + // } + // elseif ($words_in_message_text[0] === $this->bot_config['admin_twitchapi_is_user_a_sub']) + // { + // $this->_check_user_is_sub($words_in_message_text, $channel, $message_text); + // // add the bot command to usage: + // $this->_bot_command_add_usage($this->bot_config['admin_twitchapi_is_user_a_sub']); + // return TRUE; + // } elseif ($words_in_message_text[0] === $this->bot_config['admin_addvip_command']) { $this->_vip_add_user($words_in_message_text, $channel, $message_text); @@ -1169,14 +1098,14 @@ private function _write_bot_commands_usage() //---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- - private function _write_oath_token_data() - { + // private function _write_oath_token_data() + // { - $this->appdatahandler->WriteAppDatafile($this->twitch_oath_token_data_file, 'appdata', json_encode(array($this->oath_token, $this->oath_token_expiration_date)), 'WRITE'); + // $this->appdatahandler->WriteAppDatafile($this->twitch_oath_token_data_file, 'appdata', json_encode(array($this->oath_token, $this->oath_token_expiration_date)), 'WRITE'); - return TRUE; + // return TRUE; - } + // } //---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- @@ -2680,124 +2609,130 @@ private function _poll_get_random_winner($poll_winning_value) //---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- - private function _set_stream_title($words_in_message_text, $channel, $message_text) - { - $title = implode(' ', array_slice($words_in_message_text, 1)); + // Deprecated: - if ($title === '') { + // private function _set_stream_title($words_in_message_text, $channel, $message_text) + // { + // $title = implode(' ', array_slice($words_in_message_text, 1)); - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'No title specified.'); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . ' : No title specified.'); - return FALSE; + // if ($title === '') { - } + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'No title specified.'); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . ' : No title specified.'); + // return FALSE; + + // } - $api_call = $this->twitchapi->set_channel_title($title); + // $api_call = $this->twitchapi->set_channel_title($title); - if (isset($api_call[2])) { + // if (isset($api_call[2])) { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Reponse: " . $api_call[2]); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : " . $api_call[2]); - return TRUE; + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Reponse: " . $api_call[2]); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : " . $api_call[2]); + // return TRUE; - } - // - if ($api_call[1]['http_code'] === 200) { + // } + // // + // if ($api_call[1]['http_code'] === 200) { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Channel's title update was successful."); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : Stream's title was updated successfully."); + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Channel's title update was successful."); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : Stream's title was updated successfully."); - } - else { + // } + // else { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Channel's title update failed."); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : An error occured while updating the stream's title."); + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Channel's title update failed."); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : An error occured while updating the stream's title."); - } + // } - return TRUE; - } + // return TRUE; + // } //---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- - private function _set_stream_game($words_in_message_text, $channel, $message_text) - { - $game = implode(' ', array_slice($words_in_message_text, 1)); + // Deprecated: - if ($game === '') { + // private function _set_stream_game($words_in_message_text, $channel, $message_text) + // { + // $game = implode(' ', array_slice($words_in_message_text, 1)); - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'No game specified.'); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . ' : No game specified.'); - return FALSE; + // if ($game === '') { - } + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'No game specified.'); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . ' : No game specified.'); + // return FALSE; + + // } - $api_call = $this->twitchapi->set_channel_game($game); + // $api_call = $this->twitchapi->set_channel_game($game); - if (isset($api_call[2])) { + // if (isset($api_call[2])) { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Reponse: " . $api_call[2]); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : " . $api_call[2]); - return TRUE; + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Reponse: " . $api_call[2]); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : " . $api_call[2]); + // return TRUE; - } - // - if ($api_call[1]['http_code'] === 200) { + // } + // // + // if ($api_call[1]['http_code'] === 200) { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Channel's game update was successful."); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : Stream's game was updated successfully."); + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Channel's game update was successful."); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : Stream's game was updated successfully."); - } - else { + // } + // else { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Channel's game update failed."); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : An error occured while updating the stream's game."); + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Channel's game update failed."); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : An error occured while updating the stream's game."); - } + // } - return TRUE; - } + // return TRUE; + // } //---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- - private function _check_user_is_sub($words_in_message_text, $channel, $message_text) - { - if (count($words_in_message_text) != 2) { + // Deprecated: + + // private function _check_user_is_sub($words_in_message_text, $channel, $message_text) + // { + // if (count($words_in_message_text) != 2) { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'No proper username passed.'); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . ' : Username provided has invalid format.'); - return FALSE; - } + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'No proper username passed.'); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . ' : Username provided has invalid format.'); + // return FALSE; + // } - $username = $words_in_message_text[1]; + // $username = $words_in_message_text[1]; - $api_call = $this->twitchapi->check_username_is_sub($username); + // $api_call = $this->twitchapi->check_username_is_sub($username); - if (isset($api_call[2])) { + // if (isset($api_call[2])) { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Reponse: " . $api_call[2]); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : " . $api_call[2]); - return TRUE; + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Reponse: " . $api_call[2]); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : " . $api_call[2]); + // return TRUE; - } - // - if ($api_call[0] === TRUE) { + // } + // // + // if ($api_call[0] === TRUE) { - $user_sub_status = ($api_call[1] === 'is_sub') ? "is a subscriber" : "is not a subscriber"; + // $user_sub_status = ($api_call[1] === 'is_sub') ? "is a subscriber" : "is not a subscriber"; - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Querying the API was successful, user: " . $username . " sub status = " . $user_sub_status ); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : User: " . $username . " " . $user_sub_status . "."); + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "Querying the API was successful, user: " . $username . " sub status = " . $user_sub_status ); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : User: " . $username . " " . $user_sub_status . "."); - } - else { + // } + // else { - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "An error occured while querying the API."); - $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : An error occured while querying the API."); + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, "An error occured while querying the API."); + // $this->send_text_to_server('bot', 'PRIVMSG ' . $channel . " : An error occured while querying the API."); - } + // } - return TRUE; - } + // return TRUE; + // } //---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- diff --git a/lib/TwitchAPI.php b/lib/TwitchAPI.php.deprecated similarity index 82% rename from lib/TwitchAPI.php rename to lib/TwitchAPI.php.deprecated index 19c4805..9e7b4af 100755 --- a/lib/TwitchAPI.php +++ b/lib/TwitchAPI.php.deprecated @@ -43,7 +43,7 @@ public function __construct($config, $logger) $this->twitchapi_channel_data_file = 'twitch_channel_data.cfg'; - if ( strlen($this->bot_config['app_client_id']) > 0 && strlen($this->bot_config['app_client_secret']) > 0 && strlen($this->bot_config['oath_twitchAPI_token']) > 0) { + if ( strlen($this->bot_config['app_client_id']) > 0 && strlen($this->bot_config['app_client_secret']) > 0 && strlen($this->bot_config['twitchAPI_access_token']) > 0) { // $this->_read_twitch_api_oath_token(); $this->module_enabled = TRUE; @@ -83,7 +83,7 @@ private function _read_channel_data() else { $json_text = json_decode($channel_data_text_array[0]); - $this->channel_id = $json_text->users[0]->_id; + $this->channel_id = $json_text->data[0]->id; } } @@ -112,10 +112,10 @@ public function _run_twitch_api_call($web_url, $access_method, $headers, $payloa curl_setopt($ch, CURLOPT_POST, 1); } - elseif ($access_method === 'PUT') { + elseif ($access_method === 'PUT' or $access_method === 'PATCH') { // curl_setopt($ch, CURLOPT_PUT, 1); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $access_method); } @@ -127,7 +127,7 @@ public function _run_twitch_api_call($web_url, $access_method, $headers, $payloa if ($payload !== NULL) { - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload)); + curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); } @@ -176,9 +176,9 @@ public function _get_users_id_by_username($username) } // - $url = 'https://api.twitch.tv/kraken/users?login=' . $username; + $url = 'https://api.twitch.tv/helix/users?login=' . $username; - $headers = array('Accept: application/vnd.twitchtv.' . $this->twitch_api_version . '+json', 'Client-ID: ' . $this->app_client_id); + $headers = array('Client-ID: ' . $this->app_client_id, 'Authorization: Bearer ' . $this->bot_config['twitchAPI_access_token'] ); $api_call = $this->_run_twitch_api_call($url, 'GET', $headers, NULL, FALSE); @@ -191,8 +191,6 @@ public function _get_users_id_by_username($username) public function set_channel_title($title) { - - if ($this->module_enabled === FALSE) { return array(FALSE, NULL, $this->response_module_not_enabled); @@ -200,14 +198,14 @@ public function set_channel_title($title) $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Setting Channels stream title via Twitch API..'); // - $url = 'https://api.twitch.tv/kraken/channels/' . $this->channel_id; + $url = 'https://api.twitch.tv/helix/channels?broadcaster_id=' . $this->channel_id; - $headers = array('Client-ID: ' . $this->app_client_id, 'Accept: application/vnd.twitchtv.' . $this->twitch_api_version . '+json', 'Authorization: OAuth ' . $this->bot_config['oath_twitchAPI_token'] ); + $headers = array('Client-ID: ' . $this->app_client_id, 'Authorization: Bearer ' . $this->bot_config['twitchAPI_access_token'], 'Content-Type: application/json' ); - $payload = array( 'channel[status]' => $title + $payload = array( 'title' => $title ); - $api_call = $this->_run_twitch_api_call($url, 'PUT', $headers, $payload, FALSE); + $api_call = $this->_run_twitch_api_call($url, 'PATCH', $headers, json_encode($payload), FALSE); $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'Twitch API call result: ' . "\n\n" . print_r($api_call, true) . "\n\n"); @@ -217,31 +215,32 @@ public function set_channel_title($title) //---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- - public function set_channel_game($game) - { + // public function set_channel_game($game) + // { - if ($this->module_enabled === FALSE) { + // if ($this->module_enabled === FALSE) { - return array(FALSE, NULL, $this->response_module_not_enabled); + // return array(FALSE, NULL, $this->response_module_not_enabled); - } + // } - $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Setting Channels game via Twitch API..'); - // - $url = 'https://api.twitch.tv/kraken/channels/' . $this->channel_id; + // $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Setting Channels game via Twitch API..'); + // // + // $url = 'https://api.twitch.tv/helix/channels?broadcaster_id=' . $this->channel_id; - $headers = array('Client-ID: ' . $this->app_client_id, 'Accept: application/vnd.twitchtv.' . $this->twitch_api_version . '+json', 'Authorization: OAuth ' . $this->bot_config['oath_twitchAPI_token'] ); + // $headers = array('Client-ID: ' . $this->app_client_id, 'Authorization: Bearer ' . $this->bot_config['twitchAPI_access_token'], 'Content-Type: application/json' ); - $payload = array( 'channel[game]' => $game - ); - $api_call = $this->_run_twitch_api_call($url, 'PUT', $headers, $payload, FALSE); + // $payload = array( 'game_id' => $game + // ); - $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'Twitch API call result: ' . "\n\n" . print_r($api_call, true) . "\n\n"); + // $api_call = $this->_run_twitch_api_call($url, 'PUT', $headers, $payload, FALSE); - return $api_call; + // $this->logger->log_it('DEBUG', __CLASS__, __FUNCTION__, 'Twitch API call result: ' . "\n\n" . print_r($api_call, true) . "\n\n"); - } + // return $api_call; + + // } //---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- @@ -256,9 +255,9 @@ private function _check_user_id_is_sub($user_id) // $this->logger->log_it('INFO', __CLASS__, __FUNCTION__, 'Checking if a user is subscriber to the channel, via Twitch API..'); - $url = 'https://api.twitch.tv/kraken/channels/' . $this->channel_id . '/subscriptions/' . $user_id; + $url = 'https://api.twitch.tv/helix/subscriptions/user?broadcaster_id=' . $this->channel_id . '&user_id=' . $user_id; - $headers = array('Client-ID: ' . $this->app_client_id, 'Accept: application/vnd.twitchtv.' . $this->twitch_api_version . '+json', 'Authorization: OAuth ' . $this->bot_config['oath_twitchAPI_token'] ); + $headers = array('Client-ID: ' . $this->app_client_id, 'Authorization: Bearer ' . $this->bot_config['twitchAPI_access_token'] ); $payload = NULL; @@ -349,8 +348,8 @@ private function _get_channel_data() // if ($api_call[1]['http_code'] != 200) { - echo __CLASS__ . ': API call to get returned with error. Exiting.. ' . "\n"; - throw new \Exception('API call to get returned with error. Exiting..'); + echo __CLASS__ . ': API call to get users id returned with error. Exiting.. ' . "\n"; + throw new \Exception('API call to get users id returned with error. Exiting..'); } @@ -358,7 +357,7 @@ private function _get_channel_data() $json_text = json_decode($api_call[0]); - $this->channel_id = $json_text->users[0]->_id; + $this->channel_id = $json_text->data[0]->id; return $api_call; diff --git a/startIzyBot.php b/startIzyBot.php index 60fd24b..525bbb5 100755 --- a/startIzyBot.php +++ b/startIzyBot.php @@ -16,7 +16,6 @@ require_once(APPPATH . '/lib/Logger.php'); require_once(APPPATH . '/lib/IzyBot.php'); require_once(APPPATH . '/lib/AppDataHandler.php'); -require_once(APPPATH . '/lib/TwitchAPI.php'); // require any potential plugins that reside on plugins folder: