404

[ Avaa Bypassed ]




Upload:

Command:

botdev@3.139.98.233: ~ $
<?php
include "DictCC.class.php";
include "Linguee.class.php";
include "Leo.class.php";
class LearnSystem extends BaseSerevice
{
    function  __construct(TranslateService $TG, &$callBackData)
    {
        parent::__construct($TG);
        $this->callBackData = &$callBackData;
    }
    function init()
    {
        $this->db = new LearnSystemDatabase($this->getTG());
    }
    function listen()
    {
        $step = $this->getTG()->getUser()->getStep();
        $stepHandler = $this->getStepHandler($step);
        $stepHandler->setParent($this);
        $stepHandler->execute();
        return $stepHandler->isFound();
    }
    public function getStepHandler($step): CallBackhandler
    {
        $steps[ProcessNewWordStepHandler::$key] = new ProcessNewWordStepHandler($this->getTG());
        if (isset($steps[$step])) {
            return $steps[$step];
        } else {
            return new NotFoundCallbackHandler($this->getTG());
        }
    }
    public function getDB(): LearnSystemDatabase
    {
        return $this->db;
    }
    function listen2()
    {
        $step = $this->getTG()->getUser()->getStep();
        if ($step == EnumSteps::USER_ASKED_FOR_INSERTING_NEW_WORD) {
            $this->processNewWord();
            return true;
        } else if ($step == EnumSteps::USER_ASKED_FOR_CONFIRMING_HIS_TRANSLATION) {
            $questionText = " پس بالاخره جواب ترجمه بالا چی شد ؟";
            $answerArray = [
                ['text' => 'بی خیال', 'id' => EnumSteps::USER_IS_TRANSLATING]

            ];
            $this->getTG()->askUserMultipleChoiceQuestion(
                $questionText,
                $answerArray,
                $this->getTG()->getUser()->chatId,
                $this->getTG()->message_id
            );
            return true;
        } else if ($step == EnumSteps::USER_ASKED_FOR_INSERTING_NEW_RELATED_WORD) {
            $contribution = $this->getDB()->getContributionByUserId($this->getTG()->chat_id);
            //                                            $this->getTG()->askToConfirmRelatedWord($contribution['word']);
        }
        return false;
    }

    function listenCallback()
    {
        $callBackData = explode(":", $this->getTG()->callback_data);
        $actionKey = $callBackData[0];
        $callbackHandler = $this->getCallbackHandler($actionKey);
        $callbackHandler->setParent($this);
        $callbackHandler->setActionKey($actionKey);
        if (isset($callBackData[1])) {
            $data = $callBackData[1];
            $callbackHandler->setData($data);
        }
        $callbackHandler->execute();
    }


    public function getCallbackHandler($actionKey): CallBackhandler
    {
        

            $answers[AddNewWordCallbackHandler::$key] = new AddNewWordCallbackHandler($this->getTG());
            $answers[CancelProcessCallbackHandler::$key] = new CancelProcessCallbackHandler($this->getTG());
            $answers[EditNewWordCallbackHandler::$key] = new EditNewWordCallbackHandler($this->getTG());
            $answers[RewriteMeaningCallbackHandler::$key] = new RewriteMeaningCallbackHandler($this->getTG());
            $answers[SetWordTypeCallbackHandler::$key] = new SetWordTypeCallbackHandler($this->getTG());
            $answers[SetTypeVerbCallbackHandler::$key] = new SetTypeVerbCallbackHandler($this->getTG());
            $answers[SetTypeNounCallbackHandler::$key] = new SetTypeNounCallbackHandler($this->getTG());
            $answers[SetTypeOtherCallbackHandler::$key] = new SetTypeOtherCallbackHandler($this->getTG());
            $answers[SetArtikelTypeCallbackHandler::$key] = new SetArtikelTypeCallbackHandler($this->getTG());
            $answers[ConfirmSelfAddedWordCallbackHandler::$key] = new ConfirmSelfAddedWordCallbackHandler($this->getTG());
            // $this->getTG()->sendMessageLog(var_export($answers, true));
    
        if (isset($answers[$actionKey])) {
            return $answers[$actionKey];
        } else {
            return new NotFoundCallbackHandler($this->getTG());
        }
    }
    function listenCallback2()
    {
        //			if($callBackData[0] == "task" && $callBackData[1] == "approve"){

        if ($this->callBackData[0] == EnumOrder::DELETE_ME) {
            $this->getTG()->deleteMessage();
        }
        if ($this->callBackData[0] == EnumSteps::USER_ASKED_FOR_CONFIRMING_HIS_TRANSLATION) {
            $this->confirmedByUser();
            //ss                        $textCall
        }
        // else if($this->callBackData[0] == EnumSteps::USER_WANTS_INSERT_MEANING)
        //     $this->waitForMeaning();
        // else if($this->callBackData[0] == EnumSteps::USER_WANTS_INSERT_COMPLETE_MEANING){
        //     $this->getTypeOfWord();
        // }
        // else if($this->callBackData[0] == EnumSteps::USER_WANTS_EDIT_MEANING)
        //     $this->waitForEditedMeaning();
        // else if($this->callBackData[0] == EnumWord::TYPE_NOUN)
        //     $this->askTranslatorArtikel();
        // else if($this->callBackData[0] == EnumWord::TYPE_VERB)
        //     $this->waitForMeaningOfVerb();
        // else if($this->callBackData[0] == EnumWord::TYPE_OTHER)
        //     $this->waitForMeaning(true);
        // else if($this->callBackData[0] == EnumWord::ARTIKEL_DIE)
        //     $this->waitForMeaningOfNoun("f");
        // else if($this->callBackData[0] == EnumWord::ARTIKEL_DER)
        //         $this->waitForMeaningOfNoun("m");
        // else if($this->callBackData[0] == EnumWord::ARTIKEL_DAS)
        // $this->waitForMeaningOfNoun("n");
        else if ($this->callBackData[0] == EnumOrder::GET_WORD_MEANING_BY_CONTRIBUTION_ID) {
            $contId = $this->callBackData[1];
            $contribution = $this->getDB()->getContributionById($contId);
            $translated = $this->getTG()->getTranslatedText($contribution['word']);
            if (empty($translated))
                $translated = "Ach sorry nochmal";
            $answerArray = [
                ['text' => 'حذف کن', 'id' => "deleteMe"]
            ];

            $this->getTG()->askUserMultipleChoiceQuestion($translated, $answerArray, $this->chat_id, $this->getTG()->message_id);
            //                            $this->getTG()->sendMessage($translated, $this->chat_id, $this->getTG()->message_id);
            $textCallback = "ادامه";
        } else if ($this->callBackData[0] == EnumOrder::GET_WORD_MEANING_BY_YANDEX) {
            $this->getTranslationByYandex();
        } else if ($this->callBackData[0] == EnumSteps::USER_IS_TRANSLATING) {
            // $this->getTG()->editAskUserMultipleChoiceQuestion("باشه می تونی به ترجمه ادامه بدی",$this->getTG()->chat_id);
            // $this->getTG()->getUser()->setStep(EnumSteps::USER_IS_TRANSLATING);
            // $this->getDB()->setContributionStatus($this->getTG()->chat_id, EnumStatus::CONTRIBIUTION_CANCELED, $this->getTG()->message_id);
        } else if ($this->callBackData[0] == EnumAdmins::ADMIN_ALLOWS_TO_USE_POWOP) {
            if (false) {
                $contId = $this->callBackData[1];
                $rate = $this->getDB()->increaseContributionRate($contId);
                $this->askTranslationFromPeople($contId, $people = 10);
                $this->getTG()->editAskUserMultipleChoiceQuestion("رفتم بپرسم");
            } else {
                $this->getTG()->editAskUserMultipleChoiceQuestion("این گزینه فعلا قابل اعتماد نیست، تا زمانی که مترجمان دقیق تری اعلام آمادگی کنند");
                $this->getTG()->deleteMessage();
            }
        } else if ($this->callBackData[0] == EnumWord::GET_TRANSLATION) {

            $contId = $this->callBackData[1];
            $contribution = $this->getDB()->getWordById($contId);
            $this->getTG()->word = $contribution['searchedWord'];
            $translated = $this->getTG()->handleTranslate();
            $textCallback = "ادامه";
        } else if ($this->callBackData[0] == EnumDecisions::USER_CONFIRMED_A_TRANSLATION) {
            $rate = $this->getDB()->increaseContributionRate($this->callBackData[1]);
            $this->getTG()->editAskUserMultipleChoiceQuestion("ممنونم عزیزم");
            if ($rate >= 2) {
                $contribution = $this->getDB()->getContributionById($this->callBackData[1]);
                if ($contribution['adminOpinion'] != "adminConfirmed") {
                    $questionText = "سلام ادمین عزیز ، یک لغت با موفقیت ترجمه شد تائیید می کنی توی دیتا بیس قرار بگیره؟";
                    $questionText .= PHP_EOL . $contribution['word'] . ": " . $contribution['translation'] . ": " . $contribution['relatedWord'];
                    $this->getTG()->askUser($questionText, EnumApprove::ADMIN_CONFIRMED_SELF_TRANSLATION . ":" . $contribution['id'], "@acceptword");
                    //                                $this->getTG()->askUser($questionText, EnumApprove::ADMIN_CONFIRMED_SELF_TRANSLATION.":".$contribution['id'], $this->getTG()->adminId);
                }
            }
        } else if ($this->callBackData[0] == EnumApprove::ADMIN_CONFIRMED_SELF_TRANSLATION) {
            $contId = $this->callBackData[1];
            $answerUserMsg = "این لغتی که یاد دادی رو حفظ کردم☺️";
            $answerUserMsg .= PHP_EOL;
            $answerUserMsg .= "در ضمن می تونی لغتت و معنیش رو داخل کانال";
            $answerUserMsg .= " @razazmoon ";
            $answerUserMsg .= " ببینی ";
            $contribution = $this->getDB()->setContributionAdminStatus($contId, EnumApprove::ADMIN_CONFIRMED);
            $word = $contribution['word'];
            //                            $this->getTG()->editAskUserMultipleChoiceQuestion("با تشکر از شما");
            $answerArray[] = ['text' => $word, 'id' => EnumOrder::GET_WORD_MEANING_BY_CONTRIBUTION_ID . ":" . $contId];
            $this->getTG()->askUserMultipleChoiceQuestion($answerUserMsg, $answerArray, $contribution['userid']);

            $razazmoonMsg = "ربات لغتنامه یه لغت جدید یاد گرفت ";
            $razazmoonMsg .= "😃" . PHP_EOL . PHP_EOL;
            $razazmoonMsg .= $contribution['artikel'] . " - " . $word . " : " . $contribution['translation'] . PHP_EOL . PHP_EOL;
            $razazmoonMsg .= "@TranslateGerman_bot 😊";
            $this->getTG()->sendMessage($razazmoonMsg, "@razazmoon");
            $resutlText = "لغت ";
            $resutlText .= " " . $word . " ";
            $resutlText .= " تائید شد ";
            $resutlText .= PHP_EOL . " خیلی ممنون";
            $answerArray = [
                ['text' => 'پاکم کن', 'id' => "deleteMe"]
            ];
            //                            $this->getTG()->editAskUserMultipleChoiceQuestion($resutlText,$answerArray);
            $this->getTG()->editAskUserMultipleChoiceQuestion($resutlText, $answerArray);

            $textCallback = "تمام";
        } else if ($this->callBackData[0] == EnumApprove::ADMIN_REFUSED) {
            $contId = $this->callBackData[1];
            //                            $answerUserMsg = "این لغتی که یاد دادی رو حفظ کردم☺️";
            $contribution = $this->getDB()->getContributionById($contId);
            $rejectedWord = $contribution['word'];
            $userTextBack = "اووم خب چطور بگم";
            $userTextBack .= " " . PHP_EOL;
            $userTextBack .= "لغتی که بهم یاد دادی تائیید نشد";
            $userTextBack .= " " . PHP_EOL;
            $userTextBack .= "شاید باید آرتیکلش رو درست وارد کنی";
            $userTextBack .= " " . PHP_EOL;
            $userTextBack .= "معنیش رو دقیق تر وارد کنی";
            $userTextBack .= " " . PHP_EOL;
            $userTextBack .= "یا حروف کلمه رو درست بنویسی";

            $this->getTG()->sendMessage($userTextBack, $contribution['userid']);
            $this->getDB()->setContributionAdminStatus($contId, EnumApprove::ADMIN_REFUSED);
            //                            $word = $contribution['word'];
            $text = "لغت ";
            $text .= $rejectedWord;
            $text .= " تائیید نشد. با تشکر ";
            //                            $this->getTG()->editAskUserMultipleChoiceQuestion($text);
            $answerArray = [
                ['text' => 'حذف کن', 'id' => "deleteMe"]
            ];
            $this->getTG()->editAskUserMultipleChoiceQuestion($text, $answerArray);
            //                            $answerArray [] = ['text'=>$word, 'id'=> EnumOrder::GET_WORD_MEANING_BY_CONTRIBUTION_ID.":".$contId];
            //                            $this->getTG()->askUserMultipleChoiceQuestion($answerUserMsg, $answerArray, $contribution['userid']);
            $textCallback = "تمام";
        } else if ($this->callBackData[0] == EnumDecisions::USER_REFUSED_A_TRANSLATION) {
            $this->getDB()->decreaseContributionRate($this->callBackData[1]);
            $this->getTG()->editAskUserMultipleChoiceQuestion("ممنونم عزیزم");
        } else if ($this->callBackData[0] == EnumAnswer::NO)
            $this->getTG()->editAskUserMultipleChoiceQuestion("اصلا مسئله ای نیست");

        //sdfff
        if (false) {
            if ($callBackData[0] == EnumApprove::ADMIN_CONFIRMED) {
                $contId = $callBackData[1];
                $this->getDB()->setContributionAdminStatus($contId, EnumApprove::ADMIN_CONFIRMED);
                $contribution = $this->getDB()->getContributionById($contId);
                $seachedWord = $contribution['word'];
                $answerUserMsg = "یادمه این کلمه '$seachedWord' فرستادی که معنیش رو نمی دونستم، الان یاد گرفتم";
                $answerArray[] = ['text' => $seachedWord, 'id' => "get:$contId"];
                $this->getTG()->askUserMultipleChoiceQuestion($answerUserMsg, $answerArray, $contribution['askedByUser']);
                $razazmoonMsg = "ربات لغتنامه یه لغت جدید یاد گرفت ";
                $razazmoonMsg .= "😃" . PHP_EOL;
                $razazmoonMsg .= $seachedWord . " : " . $contribution['translation'];
                $razazmoonMsg .= "@TranslateGerman_bot 😊";
                $this->getTG()->sendMessage($razazmoonMsg, "@razazmoon");
                $resutlText = "لغت ";
                $resutlText .= $seachedWord;
                $resutlText .= " تائید شد ";
                $resutlText .= PHP_EOL . " خیلی ممنون";
                $this->getTG()->editAskUserMultipleChoiceQuestion($resutlText);
                $textCallback = "تمام";
            } else if ($callBackData[0] == EnumApprove::ADMIN_ALLOWS_TO_ASK_PEOPLE) {
                $userActivityId = $callBackData[3];

                $seachedWord = $this->getDB()->getWordFromActivityById($userActivityId);
                // 					$seachedWord = $contribution['word'];
                $this->getTG()->sendContributionMessageg($userActivityId, $seachedWord);
                $this->getTG()->editAskUserMultipleChoiceQuestion("ارسال شد");
                $textCallback = "تمام";
            } else if ($callBackData[0] == EnumSteps::USER_ACCEPTED_HELP) {
                $contributionTableId = $callBackData[1];
                $activity = $this->getDB()->getActivity($contributionTableId);
                $word = $activity['searchedWord'];
                //					$lastContribution = $this->getDB()->getLastContribution($this->chat_id);
                // 					$this->cancelMessage(":*", $lastContribution['message_id']);
                $this->getDB()->insertContribution($activity['searchedWord'], $activity['userid'], $this->getTG()->chat_id, $this->getTG()->message_id);
                $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_TYPE_OF_PROBLEM);
                $textCallback = "ممنون";
                $questionText = "به نظرت چرا من این کلمه  '$word' رو متوجه نشدم ؟  ";
                $answerArray = [
                    ['text' => 'اشتباه تایپی داره', 'id' => "1:$contributionTableId"],
                    ['text' => 'حالت دیگه ای از یکه کلمه است', 'id' => "2:$contributionTableId"],
                    ['text' => 'یک عبارت از ترکیب چند کلمه هست', 'id' => "3:$contributionTableId"],
                    ['text' => 'معنی خاص خودش رو داره', 'id' => "4:$contributionTableId"],
                    ['text' => ' اصلا معنی نداره', 'id' => "5:$contributionTableId"],
                    ['text' => 'منم در این مورد نظری ندارم', 'id' => "6:$contributionTableId"],
                ];
                $this->editAskUserMultipleChoiceQuestion($questionText, $answerArray);
            } else if ($callBackData[0] == "task" && $callBackData[1] == "select"  && $callBackData[2] == "get") {
                $contId = $callBackData[3];
                $contribution = $this->getDB()->getContributionById($contId);


                $translated = $this->translateWordProcess($contribution['relatedWord']);
                if (empty($translated))
                    $translated = "Ach sorry nochmal";
                $this->getTG()->sendMessage($translated, $this->chat_id);
                $textCallback = "ادامه";
            } else if ($callBackData[0] == "task" && $callBackData[1] == "select"  && $callBackData[2] != "deny") {
                $step = $this->getDB()->getUserStep($this->chat_id);
                $textCallback = $this->decideBySelectedIdAndStep($callBackData[2], $callBackData[3], $step);
                $textCallback = "ادامه";
            } else if ($callBackData[0] == "task" && $callBackData[1] == "select" && $callBackData[2] == "deny") {
                $answerArray[] = ['text' => 'باشه تایپ می کنم', 'id' => 1];
                $this->editAskUserMultipleChoiceQuestion("خیلی ممنون");
                $this->getDB()->setContributionStatus($this->chat_id, EnumStatus::CONTRIBIUTION_CANCELED, $this->message_id);
                $textCallback = "خیلی ممنون";
                $this->getDB()->setUserStep($this->chat_id, "");
            } else if ($callBackData[0] == "task" && $callBackData[1] == "deny") {
                $this->getDB()->setUserStep($this->chat_id, "");
                $textCallback = "باشه مسئله ای نیست";
                $this->editAskUserMultipleChoiceQuestion($textCallback);
                // 				$this->getDB()->setContributionStatus($this->chat_id, EnumStatus::CONTRIBIUTION_CANCELED);ssfa

            }
        }
        return "gut";
    }
    public function processNewWord2()
    {
        //						$this->askToConfirmNewWord($this->);;;
        $contribution = $this->getDB()->getContributionByUserId($this->getTG()->chat_id);
        if ($this->compareLanguage($contribution['word'], $this->getTG()->message['text'])) {
            //                                                    $questionText = "معنی کلمه با خود کلمه نمی شه به یک زبان باشه. دوباره بنویس ";
            $questionText = "عزیزم این کلمه  ";
            $questionText .= $contribution['word'];
            $questionText .= " با معنیش  ";
            $questionText .= $this->getTG()->message['text'];
            $questionText .= " به یک زبان هستن. اینجوری که نمی شه. ";
            $questionText .= " لطفا معنیش رو درست تایپ کن پایین و بفرست ";
            $questionText .= PHP_EOL . "و اگه معنیش رو نمی دونی دکمه زیر رو فشار بده";
            $answerArray = [
                ['text' => 'بی خیال', 'id' => EnumSteps::USER_IS_TRANSLATING]

            ];
            $this->getTG()->askUserMultipleChoiceQuestion($questionText, $answerArray, $userId);
            //                    }                                $this->getTG()->sendMessage("معنی کلمه با خود کلمه نمی شه به یک زبان باشه. دوباره بنویس ");
        } else if ($this->isInDatabase($contribution['word'], $this->getTG()->message['text'])) {
            $this->getTG()->sendMessage("این ترجمه قبلا توی لغتنامه وارد شده. یه معنی دیگه بنویس");
        } else if ($contribution['type'] == "verb" && !$this->validateVerb($this->getTG()->message['text'])) {
            //                         && !$this->validateVerb($this->getTG()->message['text']
            //                         $this->validateVerb($this->getTG()->message['text'];
            $validationMsg = "فعل باید به صورت مصدری";
            $validationMsg .= " یا ";
            $validationMsg .= " infinitive ";
            $validationMsg .= " نوشته بشه ";
            $validationMsg .= " مثلا فعل ";
            $validationMsg .= " به چیزی نگاه کردن ";
            $validationMsg .= " anschauen : ";
            $validationMsg .= " هردو در انتها حرف ن یا ";
            $validationMsg .= " n ";
            $validationMsg .= " رو دارن حالا سعی کن مصدر فعل رو بنویسی";
            $this->getTG()->sendMessage($validationMsg);
        } else if (false && !$this->getTG()->isPersianLanguage($this->getTG()->message['text']) && $this->isInOnlineDictionaries($this->getTG()->message['text'])) {

            $this->getTG()->sendMessage("it is not in dict maybe false spelled");
        } else {
            $this->askToConfirmNewWord($contribution['word']);
            $this->getDB()->setTranslatedWord($this->getTG()->message['text'], $this->getTG()->chat_id);
            $this->getTG()->getUser()->setStep(EnumSteps::USER_ASKED_FOR_CONFIRMING_HIS_TRANSLATION);
        }

        return true;
    }
    public function decideBySelectedId($selectedId, $contributionTableId)
    {
        $word = $this->db->getWordFromActivityById($contributionTableId);
        switch ($selectedId) {
            case 1:
                $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_ACCEPTING_TO_WRITE_RELATED_WORD);
                $this->getDB()->setContributionProblemType(EnumProblems::WORD_IS_MISSTYPED, $this->chat_id, $this->message_id);
                $answerArray[] = ['text' => 'باشه تایپ می کنم', 'id' => 1];
                $answerArray[] = ['text' => 'بی خیال', 'id' => "deny"];
                $qMsg = "خب می تونی بگی درست این کلمه '$word' چطور نوشته می شه؟";
                $this->editAskUserMultipleChoiceQuestion($qMsg, $answerArray);

                break;
            case 2:
                $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_ACCEPTING_TO_WRITE_RELATED_WORD);
                $this->getDB()->setContributionProblemType(EnumProblems::WORD_IS_REFORMED, $this->chat_id, $this->message_id);
                $answerArray[] = ['text' => 'باشه تایپ می کنم', 'id' => 1];
                $answerArray[] = ['text' => 'بی خیال', id => "deny"];
                $this->editAskUserMultipleChoiceQuestion("میشه بگی این کلمه '$word' حالت دیگه از چه کلمه ای بوده ؟", $answerArray);
                break;
            case 3:
                $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_ACCEPTING_TO_WRITE_NEW_WORD);
                $this->getDB()->setContributionProblemType(EnumProblems::WORD_IS_COMBINED, $this->chat_id, $this->message_id);
                $answerArray[] = ['text' => 'باشه تایپ می کنم', 'id' => 1];
                $answerArray[] = ['text' => 'بی خیال', 'id' => "deny"];
                $this->editAskUserMultipleChoiceQuestion("خب می تونی معنی کل عبارت '$word' رو بنویسی؟", $answerArray);
                break;
            case 4:
                $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_ACCEPTING_TO_WRITE_NEW_WORD);
                $answerArray[] = ['text' => 'باشه تایپ می کنم', 'id' => 1];
                $answerArray[] = ['text' => 'بی خیال', 'id' => "deny"];
                $this->editAskUserMultipleChoiceQuestion("می شه معنی کلمه '$word' رو اگه می دونی برام بفرستی؟", $answerArray);
                break;
            case 5:
                $this->editAskUserMultipleChoiceQuestion("باشه پس ممنون");
                $this->getDB()->setContributionStatus($this->chat_id, EnumStatus::CONTRIBIUTION_CANCELED, $this->message_id);
                $this->getDB()->setUserStep($this->chat_id, '');
                break;
            case 6:
                $this->editAskUserMultipleChoiceQuestion("خیلی ممنون");
                $this->getDB()->setContributionStatus($this->chat_id, EnumStatus::CONTRIBIUTION_CANCELED, $this->message_id);
                $this->getDB()->setUserStep($this->chat_id, '');
                break;
        }
        // 		$answerArray[] = ['text'=>'بی خیال', 'id'=>"deny"];
        return "مرحله بعد";
    }
    public function decideBySelectedIdAndStep($selectedId, $contributionTableId, $step)
    {
        // $this->getDB() = new DictionaryDatabaseHandler($this->getTG());
        if ($step == EnumSteps::USER_ASKED_FOR_TYPE_OF_PROBLEM)
            $this->decideBySelectedId($selectedId, $contributionTableId);
        else if ($step == EnumSteps::USER_ASKED_FOR_ACCEPTING_TO_WRITE_NEW_WORD) {
            $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_INSERTING_NEW_WORD);
            $this->getTG()->editAskUserMultipleChoiceQuestion($this->message['text']);
            $this->getTG()->sendMessage("لطفا معنی لغت را وارد کنید");
        } else if ($step == EnumSteps::USER_ASKED_FOR_ACCEPTING_TO_WRITE_RELATED_WORD) {
            $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_INSERTING_NEW_RELATED_WORD);
            $this->getTG()->editAskUserMultipleChoiceQuestion($this->message['text']);
            $this->getTG()->sendMessage("لطفا کلمه را به صورت صحیح وارد کنید");
        } else if ($step == EnumSteps::USER_ASKED_FOR_CONFIRMING_HIS_TRANSLATION) {
            $this->getDB()->setUserStep($this->chat_id, "");
        } else if ($step == EnumSteps::USER_ASKED_FOR_ACCEPTING_TO_WRITE_NEW_WORD)
            $this->getTG()->sendMessage("لطفا کلمه جدید را وارد کنید", $this->chat_id);
        else if ($step == EnumSteps::USER_ADDED_NEW_WORD) {
            switch ($selectedId) {
                case "approve":
                    $this->getDB()->setUserStep($this->chat_id, "");
                    $questionText = "😊خیلی ممنونم عزیزم، مرسی کمکم کردی این لغت رو یاد بگیرم";
                    $this->getTG()->editAskUserMultipleChoiceQuestion($questionText);

                    $contribution = $this->getDB()->getContributionByUserId($this->chat_id);
                    $this->getDB()->setContributionStatus($this->chat_id, EnumStatus::CONTRIBIUTION_CLOSED, $contribution['message_id']);
                    $questionText = "سلام ادمین عزیز ، یک لغت با موفقیت ترجمه شد تائیید می کنی توی دیتا بیس قرار بگیره؟";
                    $questionText .= PHP_EOL . $contribution['word'] . ": " . $contribution['translation']
                        . ": " . $contribution['relatedWord'];
                    $this->getTG()->askUser($questionText, EnumApprove::ADMIN_CONFIRMED . ":" . $contribution['id'], "@acceptword");
                    break;
                case "edit":
                    $this->getTG()->editAskUserMultipleChoiceQuestion("نیاز به اصلاح داشت");
                    $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_INSERTING_NEW_WORD);
                    $this->getTG()->sendMessage("لطفا کلمه صحیح را وارد کنید", $this->chat_id);
                    break;
                case "editRelated":
                    $this->getTG()->editAskUserMultipleChoiceQuestion("نیاز به اصلاح داشت");
                    $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ASKED_FOR_INSERTING_NEW_RELATED_WORD);
                    $this->getTG()->sendMessage("لطفا کلمه صحیح را وارد کنید", $this->chat_id);
                    break;
            }
        }
    }
    public function  suggestContribution($userActivityId, $userId, $word)
    {
        $askIt = "یه نفر این کلمه رو به من داده تا ترجمه کنم، ولی بلد نیستم 😔، استرس دارم، می تونی کمکم کنی؟";
        $askIt .= PHP_EOL . "کلمه اینه : " . $word;
        $this->getTG()->askUser($askIt, $userActivityId, (int) $userId);
    }
    public function  askAdminToSuggestContribution($userActivityId, $word)
    {
        $askIt = "می تونم معنی این کلمه رو از بقیه بپرسم؟";
        $askIt .= PHP_EOL . "کلمه اینه : " . $word;

        //		$this->getTG()->askUser($askIt, EnumApprove::ADMIN_ALLOWS_TO_ASK_PEOPLE.":".$userActivityId, "@sendword");
        $this->getTG()->askUser($askIt, EnumApprove::ADMIN_ALLOWS_TO_ASK_PEOPLE . ":" . $userActivityId, "@sendword");
    }
    public function  askAdminForPOWOP($contId)
    {
        $askIt = "معنی این لغت درست وارد شده ؟";
        $translation = $this->getDB()->getContributionById($contId);
        $translation['trustRate'] = $this->getDB()->getTranslationsTrustOfUser($translation['userid']);
        //                $user = $this->getDB()->getUser($translation['userid']);
        $askIt .= PHP_EOL . "ترجمه اینه : " . $translation['artikel'] . " - " . $translation['word'] . " (" . $translation['type'] . ") "
            . " : " . $translation['translation'];
        $askIt .= PHP_EOL . "فرستنده " . $translation['userid'];
        $askIt .= PHP_EOL . "rate of user " . $translation['trustRate'];

        $answerArray = [
            ['text' => 'تائید نهایی', 'id' => EnumApprove::ADMIN_CONFIRMED_SELF_TRANSLATION . ":" . $contId],
            ['text' => 'از بقیه بپرس', 'id' => EnumAdmins::ADMIN_ALLOWS_TO_USE_POWOP . ":" . $contId],
            ['text' => 'مشاهده معنی در لغتنامه', 'id' => EnumOrder::GET_WORD_MEANING_BY_CONTRIBUTION_ID . ":" . $contId],
            ['text' => 'ترجمه از منابع دیگر', 'id' => EnumOrder::GET_WORD_MEANING_BY_YANDEX . ":" . $contId],
            ['text' => 'خیر', 'id' => EnumApprove::ADMIN_REFUSED . ":" . $contId],
        ];
        if ($translation['trustRate'] >= 0)
            $this->getTG()->askUserMultipleChoiceQuestion($askIt, $answerArray, "@sendword");
        else {
            $this->getTG()->askUserMultipleChoiceQuestion($askIt, $answerArray, "@sendwordsbad");
        }
        //		$this->getTG()->askUser($askIt, EnumAdmins::ADMIN_ALLOWS_TO_USE_POWOP.":".$contId, "@sendword");
    }
    public function confirmedByUser()
    {
        // 		$this->getTG()->getUser()->setStep(EnumSteps::USER_IS_TRANSLATING);
        //                 $cont = $this->getDB()->getContributionByUserId($this->getTG()->chat_id);
        //                 $this->getDB()->setContributionStatus($this->getTG()->chat_id, EnumStatus::CONTRIBIUTION_CONFIRMED, $this->getTG()->message_id);
        //                 $this->askAdminForPOWOP($cont['id']);


        // //		$this->getTG()->sendMessage("ممنون عزیزم از این که این لغت رو به من آموزش دادی");;;;:
        //                 $confirmedMsg = "ممنون عزیزم از این که این لغت رو به من آموزش دادی".PHP_EOL;
        //                 $confirmedMsg .= "هر موقع این لغت ذخیره شد توی حافظه ام بهت خبر می دم";
        // //                $confirmedMsg .= "اگه لغت و معنیش درست باشه حفظش می کنم و یک قلب برات می فرستم";
        // 		$this->getTG()->editAskUserMultipleChoiceQuestion($confirmedMsg);
    }
    public function waitForMeaningOfVerb()
    {
        //             $contId = $this->callBackData[1];
        //             $this->getTG()->getUser()->setStep(EnumSteps::USER_ASKED_FOR_INSERTING_NEW_WORD);
        //             $this->getDB()->setContributionType("verb", $contId);

        //     //        $this->getDB()->insertContribution($this->callBackData[1],$this->getTG()->chat_id, $this->getTG()->chat_id, $this->getTG()->message_id);
        //     //                $word = $this->getTG()->message['text'];
        //             $contribution = $this->getDB()->getContributionById($contId);
        //             $word=$contribution['word'];
        //             $textResult = "چه معنی جدیدی می تونی برای فعل ";
        //             $textResult .= " (".$word.") ";
        //             $textResult .= "وارد کنی؟ ";
        // //            $this->getTG()->sendMessage("چه معنی جدیدی می تونی برای این کلمه$word  وارد کنی ؟ اینجا بنویس");
        //             $this->getTG()->editAskUserMultipleChoiceQuestion($textResult);
    }
    public function waitForMeaningOfNoun($artikel, $contId = "")
    {
        if (strlen($contId) < 2)
            $contId = $this->callBackData[1];
        $this->getTG()->getUser()->setStep(EnumSteps::USER_ASKED_FOR_INSERTING_NEW_WORD);

        $this->getDB()->setContributionArtikel($artikel, $contId);
        //        $this->getDB()->insertContribution($this->callBackData[1],$this->getTG()->chat_id, $this->getTG()->chat_id, $this->getTG()->message_id);
        //                $word = $this->getTG()->message['text'];
        //		$this->getTG()->sendMessage("چه معنی جدیدی می تونی برای این کلمه$word  وارد کنی ؟ اینجا بنویس");
        $this->getTG()->editAskUserMultipleChoiceQuestion("چه معنی جدیدی می تونی برای این کلمه$word  وارد کنی ؟ اینجا بنویس");
    }
    public function askTranslatorArtikel()
    {
        //             $contId = $this->callBackData[1];
        //             $askIt = "خب این اسم رو همراه با آرتیکلش به من یاد بده ";
        //             $askIt .= $word;
        //             $askIt .=  " کدوم آرتیکل درست این کلمه هست؟";
        //             $this->getTG()->getUser()->setStep(EnumSteps::USER_ASKED_FOR_CONFIRMING_HIS_TRANSLATION);
        //             $this->getDB()->setContributionType("noun", $contId);
        // //            $contId = $this->getDB()->insertContribution($word,$this->getTG()->chat_id, $this->getTG()->chat_id, $this->getTG()->message_id);
        //             $answerArray = [
        //                             ['text'=>'Der', 'id'=> EnumWord::ARTIKEL_DER.":".$contId],
        //                             ['text'=>'Die', 'id'=> EnumWord::ARTIKEL_DIE.":".$contId],
        //                             ['text'=>'Das', 'id'=> EnumWord::ARTIKEL_DAS.":".$contId],
        //                             ['text'=>'بی خیال', 'id'=> EnumAnswer::NO.": "],
        //             ];
        //             $this->getTG()->editAskUserMultipleChoiceQuestion($askIt, $answerArray);

    }
    public function getTypeOfWord()
    {

        //         $word = $this->callBackData[1];
        //         $contId = $this->getDB()->insertContribution($word,$this->getTG()->chat_id, $this->getTG()->chat_id, $this->getTG()->message_id);
        //         $onlineDic = new Leo();
        //         if($onlineDic->findWord($word)){
        //             if($onlineDic->isSubstantive() &&  $onlineDic->getWordArtikel()){
        //                 $artikel = $onlineDic->getWordArtikel();
        //                 $askIt = "هاها 😃 آرتیکل این لغت رو می دونستم".PHP_EOL;
        // //                        $askIt .= $artikel;
        //                 $askIt.= strpos($artikel, "das");
        //                 $askIt .= $artikel=="m"?"der":"";
        //                 $askIt .= $artikel=="f"?"die":"";
        //                 $askIt .= $artikel=="n"?"das":"";
        //                 $askIt .= " $word ".PHP_EOL;
        //                 $askIt .= "لطفا معنیش رو برام بنویس";
        //                 $this->getTG()->sendMessage($askIt);
        // //                        $this->getTG()->getUser()->setStep(EnumSteps::USER_ASKED_FOR_CONFIRMING_HIS_TRANSLATION);
        //                 $this->getDB()->setContributionType("noun", $contId);
        //                 $this->waitForMeaningOfNoun($artikel,$contId );
        //                 return true;
        //             }
        //         }
        //         $askIt = "می دونم می خوای معنی کلمه ";
        //         $askIt .= " '".$word."' ";
        //         $askIt .=  "رو وارد کنی اما قبلش می تونی بگی نوع این کلمه چی هست؟";
        //         $this->getTG()->getUser()->setStep(EnumSteps::USER_ASKED_FOR_CONFIRMING_HIS_TRANSLATION);

        //         $answerArray = [
        //                         ['text'=>'اسم', 'id'=> EnumWord::TYPE_NOUN.":".$contId],
        //                         ['text'=>'فعل', 'id'=> EnumWord::TYPE_VERB.":".$contId],
        //                         ['text'=>'غیره', 'id'=> EnumWord::TYPE_OTHER.":".$contId],
        //                         ['text'=>'بی خیال', 'id'=> EnumAnswer::NO.": "],
        //         ];
        //         $this->getTG()->askUserMultipleChoiceQuestion($askIt, $answerArray);

    }
    // public function waitForEditedMeaning(){
    // 	$this->getTG()->getUser()->setStep(EnumSteps::USER_ASKED_FOR_INSERTING_NEW_WORD);
    // 	$this->getTG()->sendMessage("اشکال نداره، معنی درست رو دوباره اینجا بنویس. مرسی ");

    // }
    public function askTranslationFromPeople($contId, $numberOfPeople)
    {
        $cont = $this->getDB()->getContributionById($contId);
        $users = $this->getDB()->getSomeUsers($cont['userid']);
        for ($i = 0; $i < count($users); $i++) {
            if (!empty($users[$i]['userid'])) {
                //                    $this->askToRateTranslation($cont, $this->getTG()->adminId);
                $this->askToRateTranslation($cont, $users[$i]['userid']);
            }
        }
        //            $this->askToRateTranslation($cont, $this->getTG()->adminId);

    }
    public function askToRateTranslation($cont, $userId)
    {
        $questionText = "سلام، یه لغت ترجمه شده، می خواستم نظرت رو بدونم، به نظرت درست ترجمه شده ؟";
        $questionText .= PHP_EOL . $cont['word'] . " : " . $cont['translation'];
        $answerArray = [
            ['text' => 'بله درسته', 'id' => EnumDecisions::USER_CONFIRMED_A_TRANSLATION . ":" . $cont['id']],
            ['text' => 'نه فکر نمی کنم', 'id' => EnumDecisions::USER_REFUSED_A_TRANSLATION . ":" . $cont['id']],
            ['text' => 'نظری ندارم', 'id' => EnumSteps::USER_IS_TRANSLATING]

        ];
        $this->getTG()->askUserMultipleChoiceQuestion($questionText, $answerArray, $userId);
    }

    public function isInOnlineDictionaries($word)
    {
        $dict = new DictCC($this->getTG());
        $dict->checkWord($word);
        $ling = new Linguee($this->getTG());
        $ling->checkWord($word);
        return false;
    }

    public function compareLanguage($word1, $word2)
    {
        $wordPart = explode($word2, " ");
        //            if(is_array($wordPart) && !empty($wordPart[0]))
        //                $word2= $wordPart[0];
        if (strpos($word2, " ")) {
            $wordPart = explode(" ", $word2);
            $word2 = $wordPart[0];
        }
        if (strpos($word1, " ")) {
            $wordPart = explode(" ", $word1);
            $word1 = $wordPart[0];
        }
        return $this->getTG()->isPersianLanguage($word1) == $this->getTG()->isPersianLanguage($word2);
    }

    public function getTranslationByYandex()
    {
        $contId = $this->callBackData[1];
        $contribution = $this->getDB()->getContributionById($contId);
        if ($this->getTG()->isPersianLanguage($contribution['word'])) {
            $lang = "fa-de";
            $this->isInOnlineDictionaries($contribution['translation']);
        } else {
            $lang = "de-fa";
            $this->isInOnlineDictionaries($contribution['word']);
        }

        $key = "trnsl.1.1.20161227T200147Z.ea68ee52a784814b.d57d90672c621ed4b707e054a845d8e0367ad95d";
        $translated = file_get_contents("https://translate.yandex.net/api/v1.5/tr.json/translate?key="
            . $key . "&lang=$lang&text=" . $contribution['word']);
        $jsonTranslation = json_decode($translated, true);
        $answerArray = [
            ['text' => 'حذف کن', 'id' => "deleteMe"]
        ];
        $yantext = $jsonTranslation['text'][0] . "(" . $jsonTranslation['code'] . ")";
        $this->getTG()->askUserMultipleChoiceQuestion($yantext, $answerArray, $this->getTG()->chat_id, $this->getTG()->message_id);
        //            $this->getTG()->sendMessage($jsonTranslation['text'][0]."(".$jsonTranslation['code'].")","",$this->getTG()->message_id);



        //            $pspell_link = pspell_new("de");
        //
        //            if (pspell_check($pspell_link, "Testt")) {
        //                $this->getTG()->sendMessage("Das ist eine gültige Schreibweise");
        //            } else {
        //                $this->getTG()->sendMessage("Sorry, falsche Schreibweise");
        //            }



    }

    public function askToConfirmRelatedWord($word)
    {
        $qText = " 👇 پس می شه گفت کلمه به صورت زیر نوشته می شه ؟";
        $qText .= PHP_EOL;;
        $qText .= $word . " : " . $this->message['text'];
        $this->getDB()->setUserStep($this->chat_id, EnumSteps::USER_ADDED_NEW_WORD);
        // 		$contribution = $dictionary->getContributionByUserId($this->chat_id);
        // 		$this->cancelMessage("nothing", $contribution['message_id']);
        $this->getDB()->setRelatedWord($this->message['text'], $this->chat_id);
        $answerArray = [
            ['text' => 'تائید می eeeکنم', 'id' => "approve"],
            ['text' => 'نیاز به اصلاح داسسسره', 'id' => "editRelated"],
        ];
        $this->getTG()->askUserMultipleChoiceQuestion($qText, $answerArray);
    }
}

Filemanager

Name Type Size Permission Actions
handlers Folder 0755
DictCC.class.php File 1.66 KB 0755
LearnSystem.database.class.php File 11.86 KB 0755
LearnSystem.php File 42.87 KB 0755
Leo.class.php File 2.79 KB 0755
Linguee.class.php File 1.96 KB 0755