-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.php
171 lines (147 loc) · 4.37 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/*
Credentials structure:
$key = "random string";
$bearer = "SE JWT token";
*/
ini_set('html_errors', false);
require_once("credentials.php");
if (isset($_GET["key"], $_GET["args"]) && $_GET["key"] == $key)
{
require_once("vendor/autoload.php");
require_once("StreamElements.php");
$bot = new StreamElements($bearer, "Bearer");
require_once("open.php");
require_once("active.php");
require_once("close.php");
require_once("latest.php");
require_once("pick.php");
require_once("refund.php");
$args = trim(urldecode($_GET["args"]));
$argsArray = explode(" ", $args);
$action = strtolower($argsArray[0]);
switch($action)
{
case "start":
if (count($argsArray) >= 5)
{
$duration = intval($argsArray[2]);
if ($duration == 0)
$duration = 15;
$title = str_replace("_", " ", trim($argsArray[1]));
$options = array();
for ($i = 3; $i < count($argsArray); $i++)
{
$options[$i - 3] = array("title" => str_replace("_", " ", $argsArray[$i]), "command" => strtolower($argsArray[$i]));
}
OpenContest($bot, $title, 1, 10000, $duration, $options);
}
else
echo "Wrong format! Expected !bets start Bets_title duration Option_1 Option_2 ...";
break;
case "close":
CloseContest($bot, GetActiveId($bot));
break;
case "draw":
if (count($argsArray) >= 2)
{
$winnerText = "";
for ($i = 1; $i < count($argsArray); $i++)
{
$winnerText .= $argsArray[$i] . " ";
}
$winnerText = str_replace(" ", "_", trim(strtolower($winnerText)));
$latest = GetLatestOptions($bot);
$winnerId;
foreach ($latest as $option)
{
if ($option["command"] == $winnerText)
$winnerId = $option["_id"];
}
if (empty($winnerId))
{
echo "Invalid winning option!";
}
else
{
PickWinningOption($bot, GetLatestId($bot), $winnerId);
}
}
else
echo "Wrong format! Expected !bets draw winningOption";
break;
case "refund":
CloseContest($bot, GetActiveId($bot));
RefundContest($bot, GetLatestId($bot));
break;
case "advanced":
$advAction = (count($argsArray) >= 2) ? (strtolower($argsArray[1])) : ("");
switch($advAction)
{
case "start":
if (count($argsArray) >= 8)
{
$duration = intval($argsArray[3]);
if ($duration == 0)
$duration = 15;
$minBet = intval($argsArray[4]);
if ($minBet == 0)
$minBet = 1;
$maxBet = intval($argsArray[5]);
if ($maxBet == 0)
$maxBet = 10000;
$title = str_replace("_", " ", trim($argsArray[2]));
$options = array();
for ($i = 6; $i < count($argsArray); $i++)
{
$options[$i - 6] = array("title" => str_replace("_", " ", $argsArray[$i]), "command" => strtolower($argsArray[$i]));
}
OpenContest($bot, $title, $minBet, $maxBet, $duration, $options);
}
else
echo "Wrong format! Expected !bets advanced start Bets_title duration minBet maxBet Option_1 Option_2 ...";
break;
case "close":
if (count($argsArray) >= 3)
{
CloseContest($bot, $argsArray[2]);
}
else
{
echo "Wrong format! Expected !bets advanced close contestId";
}
break;
case "draw":
if (count($argsArray) >= 4)
{
PickWinningOption($bot, $argsArray[2], $argsArray[3]);
}
else
{
echo "Wrong format! Expected !bets advanced draw contestId winnerId";
}
break;
case "refund":
if (count($argsArray) >= 3)
{
CloseContest($bot, $argsArray[2]);
RefundContest($bot, $argsArray[2]);
}
else
{
echo "Wrong format! Expected !bets advanced refund contestId";
}
break;
default:
echo "Invalid action! Expected: start|close|draw|refund";
break;
}
break;
default:
echo "Invalid action! Expected: start|close|draw|refund|advanced";
}
}
else
{
echo "Something went wrong!";
}