Exemple #1
0
 public function apostar($endpoint, $request, $currentCMD)
 {
     $apostarCMDDAO = new ApostarCMDDAO();
     $resultApostarCMD = $apostarCMDDAO->select($request->get_chat_id());
     if (!isset($resultApostarCMD['partido'])) {
         $this->log->debug("No hay partido");
         $this->updatePartido($endpoint, $request);
         //se borra el teclado.Y se pide Descripción
         $object = new stdClass();
         $object->hide_keyboard = true;
         return Response::create_text_replymarkup_response($endpoint, $request->get_chat_id(), '¿A qué quieres apostar?', json_encode($object));
     } else {
         if (!isset($resultApostarCMD['descrip'])) {
             $this->log->debug("Ya hay partido, no hay descrip");
             $this->updateDescrip($endpoint, $request, $resultApostarCMD, $currentCMD);
             //Se pide la importe
             $text = 'Vale, dime el importe';
             return Response::create_text_response($endpoint, $request->get_chat_id(), $text);
         } else {
             if (!isset($resultApostarCMD['importe'])) {
                 $this->log->debug("Ya hay partido y descrip, pero no hay importe");
                 $importe = $request->get_text();
                 $importe = str_replace(',', '.', $importe);
                 if (is_numeric($importe)) {
                     $this->updateImporte($endpoint, $request, $resultApostarCMD);
                 } else {
                     $this->log->debug("Error, no es un número");
                     $text = 'El importe de la apuesta debe ser un número, ' . Utils::getInsultoSingular();
                     return Response::create_text_response($endpoint, $request->get_chat_id(), $text);
                 }
                 $this->log->debug("Ya tengo todo para hacer la apuesta");
                 //Llamar api apostar
                 $result = $this->crearApuesta($endpoint, $request, $currentCMD);
                 //Se borra el comando actual
                 $currentCMDDAO = new CurrentCMDDAO();
                 $currentCMD = $currentCMDDAO->delete($request->get_chat_id());
                 if ($result == null) {
                     $text = 'Apuesta creada correctamente.' . PHP_EOL . 'Puedes verla con el comando /mispartidos';
                     return Response::create_text_response($endpoint, $request->get_chat_id(), $text);
                 }
                 $emoji_alert = Utils::convert_emoji(0x26a0);
                 $text = $emoji_alert . '*Error:*' . PHP_EOL . $result;
                 return Response::create_text_response($endpoint, $request->get_chat_id(), $text);
             } else {
                 $this->log->debug("Aqui no debería llegar nunca.");
             }
         }
     }
 }
Exemple #2
0
 private function deletecurrent($endpoint, $request)
 {
     $currentCMDDAO = new CurrentCMDDAO();
     $result = $currentCMDDAO->delete($request->get_chat_id());
     $text = '';
     if ($result) {
         $text = 'Borrando con exito';
     } else {
         $text = 'Error al borrar';
     }
     $response = new Response($endpoint, $request->get_chat_id(), Response::TYPE_TEXT);
     $response->text = $text;
     return $response;
 }
Exemple #3
0
 private function apostar($endpoint, $request, $grupoVO)
 {
     $urlApi = $grupoVO->url_api;
     //Se comprueba si es un chat privado, para obtener el token del usuario
     $text = '';
     if ($request->is_private_chat()) {
         $currentCMDDAO = new CurrentCMDDAO();
         $result = $currentCMDDAO->select($request->get_chat_id());
         if ($result != null) {
             //Si hay comando en curso, se borra y se inserta este
             $currentCMDDAO->delete($request->get_chat_id());
         }
         $cmd = new CurrentCMDVO();
         $cmd->chat_id = $request->get_chat_id();
         $cmd->cmd = 'apostar';
         $cmd->grupo = $grupoVO->id;
         $resultInsertCMD = $currentCMDDAO->insert($cmd);
         $apostarCMDDAO = new ApostarCMDDAO();
         $cmd = new ApostarCMDVO();
         $cmd->chat_id = $request->get_chat_id();
         $resultInsertApostarCMD = $apostarCMDDAO->insert($cmd);
         $this->log->debug("apostar al grupo: " . $grupoVO->nombre);
         return self::preguntarPartido($endpoint, $request, $urlApi);
     } else {
         $text = 'Esto solo se puede usar en privado, n***a!!';
     }
     return Response::create_text_response($endpoint, $request->get_chat_id(), $text);
 }
Exemple #4
0
 static function ejecutar($endpoint, $request)
 {
     $logStatic = Logger::getLogger('com.hotelpene.limbBot.Comandos');
     $func = $request->get_command();
     if ($func != null) {
         if ($request->is_private_chat()) {
             //Sólo se permiten estos comandos desde chats privados
             if ($func == 'cancel') {
                 $currentCMDDAO = new CurrentCMDDAO();
                 $currentCMD = $currentCMDDAO->delete($request->get_chat_id());
                 $object = new stdClass();
                 $object->hide_keyboard = true;
                 $response = Response::create_text_replymarkup_response($endpoint, $request->get_chat_id(), 'Cancelado', json_encode($object));
             } else {
                 $response = ComandosDev::ejecutar($func, $endpoint, $request);
             }
         }
         if (!isset($response)) {
             $response = ComandosLimb::ejecutar($func, $endpoint, $request);
         }
         if (!isset($response)) {
             $response = ComandosFutbol::ejecutar($func, $endpoint, $request);
         }
         if (!isset($response)) {
             $response = ComandosOffTopic::ejecutar($func, $endpoint, $request);
         }
         return $response;
     } else {
         $logStatic->debug("No es un comando: " . $request->get_text());
         //Buscar si hay algun comando en curso
         $currentCMDDAO = new CurrentCMDDAO();
         $currentCMD = $currentCMDDAO->select($request->get_chat_id());
         if ($currentCMD['grupo'] == null) {
             $grupoDAO = new GrupoDAO();
             $grupoVO = $grupoDAO->selectByNombre($request->get_text());
             if ($grupoVO != null) {
                 $currentCMDDAO->updateGrupo($request->get_chat_id(), $grupoVO->id);
                 $func = $currentCMD['cmd'];
                 return $response = ComandosLimb::ejecutar($func, $endpoint, $request);
             }
         }
         if ($currentCMD != null) {
             $logStatic->debug("Hay un comando en marcha: " . $currentCMD['cmd']);
             if ($currentCMD['cmd'] == 'apostar') {
                 $apostarCMD = new ApostarCMD();
                 return $apostarCMD->apostar($endpoint, $request, $currentCMD);
             } else {
                 $grupoDAO = new GrupoDAO();
                 $grupoVO = $grupoDAO->selectByNombre($request->get_text());
                 if ($grupoVO != null) {
                     $currentCMDDAO->updateGrupo($request->get_chat_id(), $grupoVO->id);
                     $func = $currentCMD['cmd'];
                     return $response = ComandosLimb::ejecutar($func, $endpoint, $request);
                 }
             }
         } else {
             $logStatic->debug("NO Hay un comando en marcha.");
         }
     }
     return false;
 }