/**
  * @inheritdoc
  */
 public function handle($arguments)
 {
     // This will update the chat status to typing...
     $this->replyWithChatAction(Actions::TYPING);
     if (!$arguments) {
         $this->replyWithMessage('Enter your duolingo username, example:');
         $this->replyWithMessage('/register MyUsername');
     } else {
         $profile = json_decode(file_get_contents('https://www.duolingo.com/users/' . $arguments));
         if ($profile) {
             $update = $this->telegram->getWebhookUpdates()->all();
             $db = DB::getInstance();
             try {
                 $db->perform("INSERT INTO users (username, registered_by, chat_id, created) VALUES (:username, :registered_by, :chat_id, :created)", ['username' => $profile->username, 'registered_by' => $update['message']['from']['id'], 'chat_id' => $update['message']['chat']['id'], 'created' => date('Y-m-d H:i:s', $update['message']['date'])]);
                 $this->replyWithMessage('Welcome ' . ($profile->fullname ?: $profile->username) . '!');
             } catch (\Exception $e) {
                 if ($update['message']['from']['id'] == 37900977) {
                     $this->replyWithMessage(print_r($e->getMessage(), true));
                 }
                 $this->replyWithMessage(($profile->fullname ?: $profile->username) . ' already registered.');
             }
         } else {
             $this->replyWithMessage('Invalid username');
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function handle($arguments)
 {
     // This will update the chat status to typing...
     $this->replyWithChatAction(Actions::TYPING);
     if (!$arguments) {
         $this->replyWithMessage('Enter duolingo username for remove, example:');
         $this->replyWithMessage('/remove Username');
     } else {
         $profile = json_decode(file_get_contents('https://www.duolingo.com/users/' . $arguments));
         if ($profile) {
             $update = $this->telegram->getWebhookUpdates()->all();
             $db = DB::getInstance();
             try {
                 $db->perform("DELETE FROM users WHERE username = :username AND chat_id = :chat_id;", ['username' => $profile->username, 'chat_id' => $update['message']['chat']['id']]);
                 $this->replyWithMessage('User ' . ($profile->fullname ?: $profile->username) . ' removed!');
             } catch (\Exception $e) {
                 if ($update['message']['from']['id'] == 37900977) {
                     $this->replyWithMessage(print_r($e->getMessage(), true));
                 }
                 $this->replyWithMessage('Error removing ' . ($profile->fullname ?: $profile->username));
             }
         } else {
             $this->replyWithMessage('Invalid username');
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function handle($arguments)
 {
     // This will update the chat status to typing...
     $this->replyWithChatAction(Actions::TYPING);
     $update = $this->telegram->getWebhookUpdates()->all();
     try {
         $db = DB::getInstance();
         $stmt = $db->perform("SELECT * FROM users WHERE chat_id = :chat_id;", ['chat_id' => $update['message']['chat']['id']]);
         while ($user = $stmt->fetch(\PDO::FETCH_ASSOC)) {
             $profile = json_decode(file_get_contents('https://www.duolingo.com/users/' . $user['username']));
             $data[$profile->fullname ?: $profile->username] = 0;
             foreach ($profile->languages as $lang) {
                 $data[$profile->fullname ?: $profile->username] += $lang->points;
             }
         }
         if ($data) {
             $tmp_filename = $this->getGraph($data);
             $this->replyWithPhoto($tmp_filename);
             unlink($tmp_filename);
         } else {
             $this->replyWithMessage('No users registered');
         }
     } catch (\Exception $e) {
         $this->replyWithMessage(print_r($data, true));
         $this->replyWithMessage('Fail in graphic generate');
     }
 }
 /**
  * @inheritdoc
  */
 public function handle($arguments)
 {
     // This will update the chat status to typing...
     $this->replyWithChatAction(Actions::TYPING);
     $update = $this->telegram->getWebhookUpdates()->all();
     $db = DB::getInstance();
     try {
         $sth = $db->perform("SELECT username FROM users WHERE chat_id = :chat_id;", ['chat_id' => $update['message']['chat']['id']]);
         $all = $sth->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($all as $user) {
             $this->replyWithMessage($user['username']);
         }
     } catch (\Exception $e) {
         if ($update['message']['from']['id'] == 37900977) {
             $this->replyWithMessage(print_r($e->getMessage(), true));
         }
         $this->replyWithMessage('Error listing users');
     }
 }
示例#5
0
<?php

// セッション開始
session_start();
// オートロード設定
require __DIR__ . '/../vendor/autoload.php';
// 設定ファイル読み込み
require __DIR__ . '/../config.php';
// 設定をテスト用DB設定で上書き
$db_settings = ['driver' => 'sqlite', 'database' => ":memory:"];
define("TEST_SCHEMA_SQL", __DIR__ . "/../schema.sqlite3.sql");
// DB接続セットアップ
\Base\DB::registerIlluminate($db_settings);