Example #1
0
 private static function processarComando($stringComando, &$args)
 {
     /* Trata uma string que começa com '/', seguido por no maximo 32 numeros, letras ou '_', seguido ou não de '@nomeDoBot */
     $regexComando = '~^/(?P<comando>[\\d\\w_]{1,32})(?:@' . Config::getBotConfig('botName') . ')?~';
     $comando = NULL;
     $args = NULL;
     if (preg_match($regexComando, $stringComando, $match)) {
         $comando = $match['comando'];
         $stringComando = str_replace($match[0], "", $stringComando);
         $args = explode(" ", $stringComando);
     }
     error_log(print_r($comando, true));
     error_log(print_r($args, true));
     error_log(strlen($args[1]));
     return $comando;
 }
Example #2
0
 public function __construct()
 {
     $this->host = Config::getBotConfig("DBHost");
     $this->user = Config::getBotConfig("DBUser");
     $this->pass = Config::getBotConfig("DBPass");
     $this->dbname = Config::getBotConfig("DBName");
     //Set dsn
     $dsn = 'pgsql:host=' . $this->host . ';dbname=' . $this->dbname;
     //define pdo options
     $options = array(PDO::ATTR_PERSISTENT => TRUE, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
     //create instance
     try {
         $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
     } catch (PDOException $e) {
         $this->error = $e->getMessage();
     }
 }
 public static function sendMessage($chatId, $message)
 {
     $url = Config::getBotConfig("ApiRequestUrl") . "/sendMessage?chat_id=" . $chatId . "&text=" . urlencode($message) . "&parse_mode=HTML";
     file_get_contents($url);
 }