Commit 8a152560 authored by MBoretto's avatar MBoretto

some fix

parent eda8c212
<?php
/*
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
......@@ -7,14 +7,15 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
use Longman\TelegramBot\Commands\AdminCommand;
class SendtochannelCommand extends AdminCommand
{
......@@ -33,17 +34,11 @@ class SendtochannelCommand extends AdminCommand
*/
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat = $message->getChat();
$user = $message->getFrom();
$type = $message->getType();
$chat_id = $chat->getId();
$text = trim($message->getText(true));
$user_id = $user->getId();
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$text = $message->getText(true);
$data = [];
......@@ -228,11 +223,11 @@ class SendtochannelCommand extends AdminCommand
* SendBack
*
* Received a message, the bot can send a copy of it to another chat/channel.
* You don't have to care about the type of thei message, the function detect it and use the proper
* You don't have to care about the type of the message, the function detect it and use the proper
* REQUEST:: function to send it.
* $data include all the var that you need to send the message to the propor chat
* $data include all the var that you need to send the message to the proper chat
*
* @todo This method will be moved at an higher level maybe in AdminCommans or Command
* @todo This method will be moved at an higher level maybe in AdminCommand or Command
* @todo Looking for a more significative name
*
* @param Longman\TelegramBot\Entities\Message $message
......
......@@ -35,7 +35,7 @@ class GenericmessageCommand extends SystemCommand
public function executeNoDB()
{
//Do nothing
return true;
return new ServerResponse(['ok' => true, 'result' => true], null);
}
/**
......@@ -45,15 +45,15 @@ class GenericmessageCommand extends SystemCommand
*/
public function execute()
{
//System command, fetch command to execute if track exist
//System command, fetch command to execute if conversation exist
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
//Fetch Track if exist
//Fetch Conversation if exist
$command = (new Conversation($user_id, $chat_id))->getConversationCommand();
if (! is_null($command)) {
return $this->telegram->executeCommand($command, $this->update);
}
return true;
return new ServerResponse(['ok' => true, 'result' => true], null);
}
}
......@@ -95,7 +95,7 @@ class Conversation
*
* @return bool
*/
protected function conversationExist()
protected function exist()
{
//Conversation info already fetched
if ($this->is_fetched) {
......@@ -136,7 +136,7 @@ class Conversation
*/
public function start()
{
if (!$this->conversationExist()) {
if (!$this->exist()) {
$status = ConversationDB::insertConversation($this->command, $this->group_name, $this->user_id, $this->chat_id);
$this->is_fetched = true;
}
......@@ -153,7 +153,7 @@ class Conversation
public function update($data)
{
//Conversation must exist!
if ($this->conversationExist()) {
if ($this->exist()) {
$fields['data'] = json_encode($data);
ConversationDB::updateConversation($fields, ['chat_id' => $this->chat_id, 'user_id' => $this->user_id, 'status' => 'active']);
......@@ -171,7 +171,7 @@ class Conversation
*/
public function stop()
{
if ($this->conversationExist()) {
if ($this->exist()) {
ConversationDB::updateConversation(['status' => 'stopped'], ['chat_id' => $this->chat_id, 'user_id' => $this->user_id, 'status' => 'active']);
}
}
......@@ -183,7 +183,7 @@ class Conversation
*/
public function getConversationCommand()
{
if ($this->conversationExist()) {
if ($this->exist()) {
return $this->conversation['conversation_command'];
}
return null;
......
......@@ -95,7 +95,8 @@ class ConversationDB extends DB
)
');
$active = 'active';
$data = json_encode('');
//$data = json_encode('');
$data = '""';
$created_at = self::getTimestamp();
$sth->bindParam(':status', $active);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment