Skip to content

Commit

Permalink
Merge pull request #2 from Creeperman007/dev
Browse files Browse the repository at this point in the history
Refund + cosmetics
  • Loading branch information
fajnyCreeper authored Dec 9, 2019
2 parents a55ce9e + 4e0bd04 commit 34d704e
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SEContestChatCommands.credentials.php
credentials.php
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Chat commands for StreamElements' Contests

## Credentials
* Create file called `SEContestChatCommands.credentials.php`
* Create file called `credentials.php`
* The file will contain three variables
* `$key` - random string, that is used in URL
* `$channel` SE Account ID that you can find [here](https://streamelements.com/dashboard/account/channels)
Expand All @@ -29,5 +29,5 @@ Examples are using base command `!bets`
### Request on API
This will show example body of StreamElements command
```
${customapi.example.com/SEContestChatCommands.php?key=my_key&action=${pathescape ${1}}&name=${pathescape ${2|${1}}}&duration=${pathescape ${3|${1}}}&options=${pathescape ${4:|${1}}}&winner=${pathescape ${2:|' '}}}
${customapi.example.com/SEContestChatCommands.php?key=my_key&action=${pathescape ${1}}&name=${pathescape ${2|' '}}&duration=${pathescape ${3|' '}}&options=${pathescape ${4:|' '}}&winner=${pathescape ${2:|' '}}}
```
26 changes: 15 additions & 11 deletions SEContestChatCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
$channel = "SE channelID";
$bearer = "SE JWT token";
*/
require_once("SEContestChatCommands.credentials.php");
require_once("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");
require_once("open.php");
require_once("active.php");
require_once("close.php");
require_once("latest.php");
require_once("pick.php");
require_once("refund.php");

switch(strtolower($_GET["action"]))
{
case "start":
if (isset($_GET["name"], $_GET["duration"], $_GET["options"]) && $_GET["name"] != "" && $_GET["duration"] != "" && $_GET["options"] != "")
if (isset($_GET["name"], $_GET["duration"], $_GET["options"]) && trim($_GET["name"]) != "" && trim($_GET["duration"]) != "" && trim($_GET["options"]) != "")
{
$duration = 10;
try
Expand All @@ -30,9 +31,8 @@
$duration = 15;
}

$name = str_replace("_", " ", $_GET["name"]);
$optionsRaw = preg_split('/ /', $_GET["options"]);
unset($value);
$name = str_replace("_", " ", trim($_GET["name"]));
$optionsRaw = preg_split('/ /', trim($_GET["options"]));
$options = array();
foreach($optionsRaw as $key => $value)
{
Expand Down Expand Up @@ -76,8 +76,12 @@
echo "Wrong format! Expected !bets draw winningOption";
break;

case "refund":
RefundContest($channel, $bearer, GetLatestId($channel, $bearer));
break;

default:
echo "Invalid action! Expected: start|close|draw";
echo "Invalid action! Expected: start|close|draw|refund";
}
}
else
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions refund.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
function RefundContest($channel, $bearer, $contestId)
{
$ch = curl_init("https://api.streamelements.com/kappa/v2/contests/".$channel."/".$contestId."/refund");
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;
}

0 comments on commit 34d704e

Please sign in to comment.