29 lines
772 B
PHP
29 lines
772 B
PHP
<?php
|
|
|
|
require __DIR__.'/lib/main.php';
|
|
|
|
// Build all the commands array
|
|
$commands = [];
|
|
foreach(scandir("commands") as $f) {
|
|
if ($f == "." || $f == "..") continue;
|
|
$filepath = "commands/$f";
|
|
if (substr($f,-8) == ".inc.php") {
|
|
$array = require $filepath;
|
|
$commands[$array["command"]] = $array;
|
|
}
|
|
}
|
|
|
|
|
|
// 1. PRINT JSON COMMAND LIST
|
|
if ($argc > 1 && $argv[1] == "--print-json-command-list") {
|
|
$out = []; foreach($commands as $k => $v) $out[] = ["command"=>$v["command"],"description"=>$v["description"]];
|
|
echo json_encode(array_values($out));
|
|
exit(0);
|
|
}
|
|
|
|
// 2. PROCESS COMMAND
|
|
extract(json_decode(file_get_contents('php://stdin'),1)["message"]); // from, chat, date, text
|
|
if (isset($commands[$text])) {
|
|
$commands[$text]["callback"]($from, $chat, $date, $text);
|
|
}
|