예제 #1
0
require_once "Telegram.class.php";
if (API_KEY == "") {
    die("Please define your API-Key.");
}
global $tg;
$tg = new Telegram(API_KEY);
$availableCommands = ["help", "shorturl", "weather", "bot", "encode", "dns", "mac", "ping", "stats", "traceroute", "permission"];
$commandAlias = ["man" => "help", "l" => "shorturl", "dig" => "dns", "trace" => "traceroute"];
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