Exemplo n.º 1
0
if ($tg->getText() == "debuginfo") {
    $tg->sendMessage(file_get_contents('php://input'));
}
// Request from Telegram-Webhooks
if (isset($_GET["t"]) && $_GET["t"] == "webhook") {
    // Check if message was a command
    if (strpos($tg->getText(), "/") === 0) {
        $command = strtolower(ltrim($tg->getCommand()["command"], "/"));
        if (isset($commandAlias[$command])) {
            $command = $commandAlias[$command];
        }
        if (in_array($command, $availableCommands)) {
            include_once "commands/" . $command . ".php";
        }
    } else {
        if ($tg->getChatType() == "private") {
            // Special commands/action on private messages?
        } else {
            // Normal message. Add to statistics
        }
    }
    echo $tg->webhookAnswer();
    // Chat statistics
    if (!file_exists("data/stats/st" . $tg->getChatID() . ".json")) {
        file_put_contents("data/stats/st" . $tg->getChatID() . ".json", json_encode([]));
    }
    $stats = json_decode(file_get_contents("data/stats/st" . $tg->getChatID() . ".json"), true);
    if (!isset($stats[$tg->getUserID()])) {
        $stats[$tg->getUserID()] = ["messages" => 1, "date" => time(), "username" => $tg->getUserName()];
    } else {
        if (is_numeric($stats[$tg->getUserID()])) {