diff --git a/.gitignore b/.gitignore index 3ce83b3..9672757 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -SEContestChatCommands.credentials.php +credentials.php diff --git a/README.md b/README.md index bb47d62..616ba7c 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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:|' '}}} ``` diff --git a/SEContestChatCommands.php b/SEContestChatCommands.php index 6d64f7a..408b04e 100644 --- a/SEContestChatCommands.php +++ b/SEContestChatCommands.php @@ -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 @@ -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) { @@ -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 diff --git a/SEContestChatCommands.active.php b/active.php similarity index 100% rename from SEContestChatCommands.active.php rename to active.php diff --git a/SEContestChatCommands.close.php b/close.php similarity index 100% rename from SEContestChatCommands.close.php rename to close.php diff --git a/SEContestChatCommands.latest.php b/latest.php similarity index 100% rename from SEContestChatCommands.latest.php rename to latest.php diff --git a/SEContestChatCommands.open.php b/open.php similarity index 100% rename from SEContestChatCommands.open.php rename to open.php diff --git a/SEContestChatCommands.option.php b/option.php similarity index 100% rename from SEContestChatCommands.option.php rename to option.php diff --git a/SEContestChatCommands.pick.php b/pick.php similarity index 100% rename from SEContestChatCommands.pick.php rename to pick.php diff --git a/refund.php b/refund.php new file mode 100644 index 0000000..31f0a10 --- /dev/null +++ b/refund.php @@ -0,0 +1,15 @@ +