🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.php
Article #231336

Re: php else if

#231336
From: ww
Date: Fri, 29 Apr 2016 07:52
88 lines
3786 bytes
W dniu 2016-04-27 o 17:49, mattia.farinaro@gmail.com pisze:
> Ciao a tutti,
> Sto facendo un BoT Telegram con comando PHP.
> Vorrei che il BoT rispondesse con risposte automatiche solamente se la domanda presenta il "?" alla fine.
> Ho creato questo file execute.php ma il BoT mi continua a dare "null" come risposta....ecco il file:
>
> ---------------------------------------------------------------------
>
> <?php
> $content = file_get_contents("php://input");
> $update = json_decode($content, true);
>
> if(!$update)
> {
>   exit;
> }
>
> $message = isset($update['message']) ? $update['message'] : "";
> $messageId = isset($message['message_id']) ? $message['message_id'] : "";
> $chatId = isset($message['chat']['id']) ? $message['chat']['id'] : "";
> $senderId = isset($message['chat']['id']) ? $message['chat']['id'] : "";
> $firstname = isset($message['chat']['first_name']) ? $message['chat']['first_name'] : "";
> $lastname = isset($message['chat']['last_name']) ? $message['chat']['last_name'] : "";
> $username = isset($message['chat']['username']) ? $message['chat']['username'] : "";
> $date = isset($message['date']) ? $message['date'] : "";
> $text = isset($message['text']) ? $message['text'] : "";
>
> $text=trim($text);
>
> $text=strtolower($text);
>
> if (!$text) { // ?????

if (strlen($text)) {

> 	// Verificare che l'ultimo carattere sia un punto di domanda
> 	if (!$text[sizeof($text) - 1] == '?') {

if (substr($text, -1) == '?') {

> 		// Da qui mandi la risposta	

$answers = array(
	{...}
);

> 		$answer = $answers[rand(0, sizeof($answers)-1)];
> 	} else {
> 		// Da qui gli mandi "ehy fammi una domanda"
> 		$answer = "Per poterti rispondere, mi devi fare una domanda con un ? alla fine...";
> 	}
> }
>
> $answers = array(
> 	"Per quanto posso vedere, sì",
> 	"È certo",
> 	"È decisamente così",
> 	"Molto probabilmente",
> 	"Le prospettive sono buone",
> 	"I segni indicano di sì",
> 	"Senza alcun dubbio",
> 	"Sì",
> 	"Sì",
> 	"Ci puoi contare",
> 	"È difficile rispondere, prova di nuovo",
> 	"Rifai la domanda più tardi",
> 	"Meglio non risponderti adesso",
> 	"Non posso predirlo ora",
> 	"Concentrati e rifai la domanda",
> 	"Non ci contare",
> 	"La mia risposta è no",
> 	"Le mie fonti dicono di no",
> 	"Le prospettive non sono buone",
> 	"Molto incerto"
> 	);
>
> header("Content-Type: application/json");
> $parameters = array('chat_id' => $chatId, "text" => $answer);
> $parameters["method"] = "sendMessage";
> echo json_encode($parameters);
>
>
> ---------------------------------------------------------------------
>
> Dove sbaglio???
>
> Grazie in anticipo...
>
Technical Details
Message-ID: <nfv3ku$r5h$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
References: <335ec8a0-1bb4-4cd2-bd40-fe84c5534cac@googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From: ww <ww@o2.pl>
Newsgroups: pl.comp.lang.php
Subject: Re: php else if
Date: Fri, 29 Apr 2016 09:52:22 +0200
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <nfv3ku$r5h$1@dont-email.me>
References: <335ec8a0-1bb4-4cd2-bd40-fe84c5534cac@googlegroups.com>
Mime-Version: 1.0
Injection-Date: Fri, 29 Apr 2016 07:48:46 -0000 (UTC)
Injection-Info: mx02.eternal-september.org; posting-host="79da0216cafa04b507ff2c39029b3bea"; logging-data="27825"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iUtR1LBeHqLevPQo50Tqn"
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0
In-Reply-To: <335ec8a0-1bb4-4cd2-bd40-fe84c5534cac@googlegroups.com>
Cancel-Lock: sha1:xot+JbaShig1JievaHlX+oVsUNs=
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit