NoPaste

Verlinkte Datei

von Skillkiller

SNIPPET_TEXT:
  1. <?php
  2. require_once 'vendor/autoload.php';
  3. require_once 'stopwatch.php';
  4.  
  5. // connect to database
  6. $mysqli = new mysqli('localhost', 'telegram', '(entnommen)', 'telegram');
  7. if (!empty($mysqli->connect_errno)) {
  8.     throw new \Exception($mysqli->connect_error, $mysqli->connect_errno);
  9. }
  10.  
  11. // create a bot
  12. $bot = new \TelegramBot\Api\Client('(entnommen)', '(entnommen)');
  13. // run, bot, run!
  14. $bot->run();
  15.  
  16. $bot->command('start', function ($message) use ($bot) {
  17.     $answer = 'Howdy! Welcome to the stopwatch. Use bot commands or keyboard to control your time.';
  18.     $bot->sendMessage($message->getChat()->getId(), $answer);
  19. });
  20.  
  21.  
  22. $bot->command('go', function ($message) use ($bot, $mysqli) {
  23.     $stopwatch = new Stopwatch($mysqli, $message->getChat()->getId());
  24.     $stopwatch->start();
  25.     $bot->sendMessage($message->getChat()->getId(), 'Stopwatch started. Go!');
  26. });
  27.  
  28.  
  29. $bot->command('status', function ($message) use ($bot, $mysqli) {
  30.     $stopwatch = new Stopwatch($mysqli, $message->getChat()->getId());
  31.     $answer = $stopwatch->status();
  32.     if (empty($answer)) {
  33.         $answer = 'Timer is not started.';
  34.     }
  35.     $bot->sendMessage($message->getChat()->getId(), $answer);
  36. });
  37.  
  38.  
  39. $bot->command('stop', function ($message) use ($bot, $mysqli) {
  40.     $stopwatch = new Stopwatch($mysqli, $message->getChat()->getId());
  41.     $answer = $stopwatch->status();
  42.     if (!empty($answer)) {
  43.         $answer = 'Your time is ' . $answer . PHP_EOL;
  44.     }
  45.     $stopwatch->stop();
  46.     $bot->sendMessage($message->getChat()->getId(), $answer . 'Stopwatch stopped. Enjoy your time!');
  47. });
  48.  
  49.  
  50. ?>

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN