forked from monang1611/InstagramLive-PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandLine.php
94 lines (90 loc) · 3.6 KB
/
commandLine.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
<?php
logM("Please wait while while the command line ensures that the live script is properly started!");
sleep(2);
logM("Command Line Ready! Type \"help\" for help.");
newCommand();
function newCommand()
{
print "\n> ";
$handle = fopen("php://stdin", "r");
$line = trim(fgets($handle));
if ($line == 'ecomments') {
sendRequest("ecomments", null);
logM("Enabled Comments!");
} elseif ($line == 'dcomments') {
sendRequest("dcomments", null);
logM("Disabled Comments!");
} elseif ($line == 'stop' || $line == 'end') {
fclose($handle);
logM("Would you like to keep the stream archived for 24 hours? Type \"yes\" to do so or anything else to not.");
print "> ";
$handle = fopen("php://stdin", "r");
$archived = trim(fgets($handle));
if ($archived == 'yes') {
sendRequest("end", ["yes"]);
} else {
sendRequest("end", ["no"]);
}
logM("Command Line Exiting! Stream *should* be ended.");
sleep(2);
exit();
} elseif ($line == 'pin') {
fclose($handle);
logM("Please enter the comment id you would like to pin.");
print "> ";
$handle = fopen("php://stdin", "r");
$commentId = trim(fgets($handle));
//TODO add comment id length check
logM("Assuming that was a valid comment id, the comment should be pinned!");
sendRequest("pin", [$commentId]);
} elseif ($line == 'unpin') {
logM("Please check the other window to see if the unpin succeeded!");
sendRequest("unpin", null);
} elseif ($line == 'pinned') {
logM("Please check the other window to see the pinned comment!");
sendRequest("pinned", null);
} elseif ($line == 'comment') {
fclose($handle);
logM("Please enter what you would like to comment.");
print "> ";
$handle = fopen("php://stdin", "r");
$text = trim(fgets($handle));
logM("Commented! Check the other window to ensure the comment was made!");
sendRequest("comment", [$text]);
} elseif ($line == 'url') {
logM("Please check the other window for your stream url!");
sendRequest("url", null);
} elseif ($line == 'key') {
logM("Please check the other window for your stream key!");
sendRequest("key", null);
} elseif ($line == 'info') {
logM("Please check the other window for your stream info!");
sendRequest("info", null);
} elseif ($line == 'viewers') {
logM("Please check the other window for your viewers list!");
sendRequest("viewers", null);
} elseif ($line == 'help') {
logM("Commands:\nhelp - Prints this message\nurl - Prints Stream URL\nkey - Prints Stream Key\ninfo - Grabs Stream Info\nviewers - Grabs Stream Viewers\necomments - Enables Comments\ndcomments - Disables Comments\npin - Pins a Comment\nunpin - Unpins a comment if one is pinned\npinned - Gets the currently pinned comment\ncomment - Comments on the stream\nstop - Stops the Live Stream");
} else {
logM("Invalid Command. Type \"help\" for help!");
}
fclose($handle);
newCommand();
}
function sendRequest(string $cmd, $values)
{
/** @noinspection PhpComposerExtensionStubsInspection */
file_put_contents(__DIR__ . '/request', json_encode([
'cmd' => $cmd,
'values' => isset($values) ? $values : [],
]));
logM("Please wait while we ensure the live script has received our request.");
sleep(2);
}
/**
* Logs a message in console but it actually uses new lines.
*/
function logM($message)
{
print $message . "\n";
}