-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4fbbaa2
Showing
10 changed files
with
890 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SEContestChatCommands.credentials.php |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# SEContestCommands | ||
Chat commands for StreamElements' Contests |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
function GetActiveId($channel, $bearer) | ||
{ | ||
$ch = curl_init("https://api.streamelements.com/kappa/v2/contests/".$channel); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'Accept: application/json', | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '.$bearer) | ||
); | ||
$result = curl_exec($ch); | ||
$result_array = json_decode($result, true); | ||
return $result_array["active"]["_id"]; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
function CloseContest($channel, $bearer, $contestId) | ||
{ | ||
$ch = curl_init("https://api.streamelements.com/kappa/v2/contests/".$channel."/".$contestId."/close"); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'Accept: application/json', | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '.$bearer) | ||
); | ||
$result = curl_exec($ch); | ||
|
||
return $result; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
function GetLatestId($channel, $bearer) | ||
{ | ||
$ch = curl_init("https://api.streamelements.com/kappa/v2/contests/".$channel); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'Accept: application/json', | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '.$bearer) | ||
); | ||
$result = curl_exec($ch); | ||
$result_array = json_decode($result, true); | ||
return $result_array["contests"][0]["_id"]; | ||
} | ||
|
||
function GetLatestOptions($channel, $bearer) | ||
{ | ||
$ch = curl_init("https://api.streamelements.com/kappa/v2/contests/".$channel); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'Accept: application/json', | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '.$bearer) | ||
); | ||
$result = curl_exec($ch); | ||
$result_array = json_decode($result, true); | ||
return $result_array["contests"][0]["options"]; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
function OpenContest($channel, $bearer, $data) | ||
{ | ||
/*$data = array( | ||
"botResponses" => false, | ||
"title" => "Test", | ||
"minBet" => 10, | ||
"maxBet" => 10000, | ||
"duration" => 15, | ||
"options" => array( | ||
array( | ||
"title" => "AAA", | ||
"command" => "aaa" | ||
), | ||
array( | ||
"title" => "BBB", | ||
"command" => "bbb" | ||
) | ||
) | ||
);*/ | ||
$ch = curl_init("https://api.streamelements.com/kappa/v2/contests/".$channel); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'Accept: application/json', | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '.$bearer) | ||
); | ||
$result = curl_exec($ch); | ||
$result_array = json_decode($result, true); | ||
$contestId = $result_array["_id"]; | ||
|
||
|
||
|
||
$ch = curl_init("https://api.streamelements.com/kappa/v2/contests/".$channel."/".$contestId."/start"); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'Accept: application/json', | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '.$bearer) | ||
); | ||
$result = curl_exec($ch); | ||
|
||
return $result; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/* | ||
Credentials structure: | ||
$key = "random string"; | ||
$channel = "SE channelID"; | ||
$bearer = "SE JWT token"; | ||
*/ | ||
require_once("SEContestChatCommands.credentials.php"); | ||
|
||
if (isset($_GET["key"], $_GET["action"]) && $_GET["key"] == $key) | ||
{ | ||
require_once("SEContestChatCommands.open.php"); | ||
require_once("SEContestChatCommands.active.php"); | ||
require_once("SEContestChatCommands.close.php"); | ||
require_once("SEContestChatCommands.latest.php"); | ||
require_once("SEContestChatCommands.pick.php"); | ||
|
||
switch(strtolower($_GET["action"])) | ||
{ | ||
case "start": | ||
if (isset($_GET["name"], $_GET["duration"], $_GET["options"]) && $_GET["name"] != "" && $_GET["duration"] != "" && $_GET["options"] != "") | ||
{ | ||
$duration = 10; | ||
try | ||
{ | ||
$duration = intval($_GET["duration"]); | ||
} | ||
catch (\Exception $e) | ||
{ | ||
$duration = 15; | ||
} | ||
|
||
$name = str_replace("_", " ", $_GET["name"]); | ||
$optionsRaw = preg_split('/ /', $_GET["options"]); | ||
unset($value); | ||
$options = array(); | ||
foreach($optionsRaw as $key => $value) | ||
{ | ||
$options[$key] = array("title" => str_replace("_", " ", $value), "command" => strtolower($value)); | ||
} | ||
unset($value); | ||
|
||
$data = array( | ||
"botResponses" => false, | ||
"title" => "$name", | ||
"minBet" => 10, | ||
"maxBet" => 10000, | ||
"duration" => $duration, | ||
"options" => $options | ||
); | ||
|
||
OpenContest($channel, $bearer, $data); | ||
} | ||
else | ||
echo "Wrong format! Expected !bets start Bets_title duration Option_1 Option_2 ..."; | ||
break; | ||
|
||
case "close": | ||
CloseContest($channel, $bearer, GetActiveId($channel, $bearer)); | ||
break; | ||
|
||
case "draw": | ||
if (isset($_GET["winner"]) && trim($_GET["winner"]) != "") | ||
{ | ||
$winnerText = str_replace(" ", "_", trim(strtolower($_GET["winner"]))); | ||
$latest = GetLatestOptions($channel, $bearer); | ||
$winnerId; | ||
foreach ($latest as $option) | ||
{ | ||
if ($option["command"] == $winnerText) | ||
$winnerId = $option["_id"]; | ||
} | ||
PickWinningOption($channel, $bearer, GetLatestId($channel, $bearer), $winnerId); | ||
} | ||
else | ||
echo "Wrong format! Expected !bets draw winningOption"; | ||
break; | ||
|
||
default: | ||
echo "Invalid action! Expected: start|close|draw"; | ||
} | ||
} | ||
else | ||
{ | ||
echo "Something went wrong!"; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
function PickWinningOption($channel, $bearer, $contestId, $winnerId) | ||
{ | ||
$data = array( | ||
"winnerId" => "$winnerId" | ||
); | ||
$ch = curl_init("https://api.streamelements.com/kappa/v2/contests/".$channel."/".$contestId."/winner"); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | ||
'Accept: application/json', | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '.$bearer) | ||
); | ||
$result = curl_exec($ch); | ||
|
||
return $result; | ||
} |