Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ...
- /**
- * Команда "/answer"
- *
- * Ответ на обратную связь
- */
- class AnswerCommand extends AdminCommand
- {
- protected $name = 'answer';
- protected $description = 'Ответ на обратную связь';
- protected $usage = '/answer';
- protected $version = '1.0.0';
- protected $need_mysql = true;
- protected $private_only = false;
- protected $conversation;
- /**
- * Проверка наличия фидбека
- *
- * @param $id
- * @return bool
- */
- public static function getFeedback($id) {
- $pdo = DB::getPdo();
- $stmt = $pdo->prepare("SELECT * FROM `feedback` WHERE `id` = :id");
- $stmt->execute([
- 'id' => $id
- ]);
- return ($stmt->rowCount() == 0 ? false : true);
- }
- /**
- * @return \Longman\TelegramBot\Entities\ServerResponse
- * @throws \Longman\TelegramBot\Exception\TelegramException
- */
- public function execute()
- {
- $message = $this->getMessage();
- $chat = $message->getChat();
- $chat_id = $message->getChat()->getId();
- $command = $message->getCommand();
- $from = $message->getFrom();
- $user_id = $from->getId();
- $text = trim($message->getText(true));
- $pdo = DB::getPdo();
- $data = [
- 'chat_id' => $chat_id,
- 'reply_markup' => Keyboard::remove([]),
- 'parse_mode' => 'Markdown'
- ];
- /**
- * Если не в админ чате используется команда
- */
- if ($chat_id !== -1001250405637) {
- $data['text'] = 'Хм.';
- return Request::sendMessage($data);
- }
- $this->conversation = new Conversation($user_id, $chat_id, $this->getName());
- $notes = &$this->conversation->notes;
- !is_array($notes) && $notes = [];
- $state = 0;
- if (isset($notes['state'])) {
- $state = $notes['state'];
- }
- if ($command !== 'answer') {
- $state = 1;
- $notes['id'] = substr($command, 6);
- // $notes['id'] = $text;
- }
- $result = Request::emptyResponse();
- switch ($state) {
- case 0:
- if ($text === '' || !is_numeric($text) || self::getFeedback($text) == false) {
- $notes['state'] = 0;
- $this->conversation->update();
- $data['text'] = "Укажите ID фидбека";
- if ($text !== '') {
- $data['text'] = "Укажите ID фидбека";
- }
- $result = Request::sendMessage($data);
- break;
- }
- $notes['id'] = $text;
- $text = '';
- case 1:
- if ($text === '') {
- $notes['state'] = 1;
- $this->conversation->update();
- $data['text'] = "Feedback ID: {$notes['id']} / Напишите ответ.";
- if ($text !== '') {
- $data['text'] = "Напишите ответ на фидбек.";
- }
- $result = Request::sendMessage($data);
- // break;
- }
- $notes['answer'] = $text;
- $text = '';
- case 2:
- $this->conversation->update();
- unset($notes['state']);
- $data['text'] = "Feedback: {$notes['id']} / Answer: {$notes['answer']} ✅ Сообщение успешно отправлено!";
- $answer = "📫 *Сообщение от администрации!*\n\n" .
- "{$notes['answer']}\n\n" .
- "_С уважением, команда CryptoDoggies_";
- $getQuestion = $pdo->prepare("SELECT * FROM `feedback` WHERE `id` = :id");
- $getQuestion->execute([
- 'id' => $notes['id'],
- ]);
- $question = $getQuestion->fetch();
- Request::sendMessage([
- 'chat_id' => $question['user_id'],
- 'text' => $answer,
- 'parse_mode' => 'Markdown',
- ]);
- $stmt = $pdo->prepare("UPDATE `feedback` SET `answer` = :answer WHERE `id` = :id");
- $stmt->execute([
- 'answer' => $notes['answer'],
- 'id' => $notes['id']
- ]);
- $this->conversation->stop();
- $result = Request::sendMessage($data);
- break;
- }
- return $result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement