Last active
November 9, 2016 14:27
-
-
Save Conobi/f40ce1f1e08a898455cc66f7d5538fdf to your computer and use it in GitHub Desktop.
Toupie Minimale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// On initie l'accès à l'api | |
$botToken = "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
$website = "https://api.telegram.org/bot".$botToken; | |
// On lit les informations et on les formate | |
$update = json_decode(file_get_contents('php://input'), TRUE); | |
// On défini les variables utiles | |
$chatId = $update["message"]["chat"]["id"]; | |
$id = $update["message"]["from"]["id"]; | |
if($update["message"]["text"] != "") { | |
$message = $update["message"]["text"]; | |
switch($message) { | |
case("/about"): | |
sendMessage($chatId, "Je suis une version minimale de Toupie.") | |
break; | |
case(preg_match("#toupie#i", $message) == true): | |
if(rand(0,1) == 1) { | |
sendMessage($chatId,'oui'); | |
} else { | |
sendMessage($chatId,'non'); | |
} | |
break; | |
} | |
} | |
// -+-+-+-+-+-+-+- | |
// FONCTIONS | |
// -+-+-+-+-+-+-+- | |
function sendMessage ($chatId, $message) { | |
$url = $GLOBALS['website']."/sendMessage?chat_id=".$chatId."&parse_mode=HTML&text=".urlencode($message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment