-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
128 lines (115 loc) · 3.6 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
<?php
ini_set('html_errors', false);
header("Content-Type: text/plain; charset=utf-8");
require_once("vendor/autoload.php");
require_once("config.php");
require_once("StreamElements.php");
require_once("Timer.php");
if (isset($_GET["key"], $_GET["action"], $_GET["params"]) && $_GET["key"] == $key)
{
$timer = new Timer($bearer, "Bearer", $baseUrl, $key);
$action = $_GET["action"];
$params = explode(" ", $_GET["params"]);
$params = str_replace("_", " ", $params);
switch ($action)
{
case "create":
if (count($params) >= 5)
{
$res = $timer->createTimer($params);
if (array_key_exists("error", $res))
echo $res["error"];
else
echo "Timer \"".$params[0]."\" created.";
}
else
echo "Invalid format. Expected !timer create <Name> <OnlineInterval> <OfflineInterval> <ChatLines> <Message1> ...";
break;
case "update":
if (count($params) >= 5)
{
$res = $timer->updateTimer($params);
if ($res === null)
echo "Could not find timer called \"".$params[0]."\".";
else
echo "Timer \"".$params[0]."\" updated.";
}
else
echo "Invalid format. Expected !timer update <Name> <OnlineInterval> <OfflineInterval> <ChatLines> <Message1> ...";
break;
case "enable":
if (count($params) >= 1)
{
$res = $timer->toggleTimer($params[0], true);
if ($res === null)
echo "Could not find timer called \"".$params[0]."\".";
else
echo "Timer \"".$params[0]."\" enabled.";
}
else
echo "Invalid format. Expected !timer enable <Name>";
break;
case "disable":
if (count($params) >= 1)
{
$res = $timer->toggleTimer($params[0], false);
if ($res === null)
echo "Could not find timer called \"".$params[0]."\".";
else
echo "Timer \"".$params[0]."\" disabled.";
}
else
echo "Invalid format. Expected !timer disable <Name>";
break;
case "delete":
if (count($params) >= 1)
{
$res = $timer->deleteTimer($params[0]);
if ($res === null)
echo "Could not find timer called \"".$params[0]."\".";
else
echo "Timer \"".$params[0]."\" deleted.";
}
else
echo "Invalid format. Expected !timer delete <Name>";
break;
case "print":
if (count($params) >= 1)
{
$res = $timer->toString($params[0]);
if ($res == "")
echo "Could not find timer called \"".$params[0]."\".";
else
echo $res;
}
else
echo "Invalid format. Expected !timer print Timer_name";
break;
case "list":
echo $timer->listTimers();
break;
case "bind":
if (count($params) >= 2)
{
$res = $timer->bindCommand($params[0], $params[1]);
if ($res === null)
echo "Command or timer with provided name doesn't exist.";
else
echo "Command bound.";
}
else
echo "Invalid format. Expected !timer bind Timer_name Command_name";
break;
default:
echo "Invalid action! Expected create|update|enable|disable|delete|print|list|bind";
break;
}
}
/*
main.php?key=&action=${1}¶ms=${2:|''}
create Timer_name intervalOnline(minutes) intervalOffline(minutes) chatLines Timer_message_1 Timer_message_2 ...
update Timer_name intervalOnline(minutes) intervalOffline(minutes) chatLines Timer_message_1 Timer_message_2 ...
enable Timer_name
disable Timer_name
delete Timer_name
*/