diff --git a/app/Helpers/QuranHelper.php b/app/Helpers/QuranHelper.php index f8d0c5b4..1cebe813 100644 --- a/app/Helpers/QuranHelper.php +++ b/app/Helpers/QuranHelper.php @@ -11,6 +11,7 @@ use App\Models\QuranWord; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; use JetBrains\PhpStorm\NoReturn; use Saber13812002\Laravel\Fulltext\IndexedRecord; @@ -73,7 +74,6 @@ public static function sendAudio($messenger, $suraId, $ayaId, BotUsers $userSett $message_id = $messenger->sendAudio($chat_id, $audio, $caption, null, null, null); } } - } /** @@ -121,7 +121,6 @@ public static function sendAudioByLocale($messenger, $suraId, $ayaId, BotUsers $ $message_id = $messenger->sendAudio($chat_id, $audio, $caption, null, null, null); } } - } /** @@ -685,6 +684,256 @@ public static function getPageNumberFromPhrase(string $searchPhrase): array return [$searchPhrase, 1]; } + /** + * @param Telegram $bot + * @return string + */ + public static function getWordId($bot): string + { + $wordId = substr($bot->Text(), 1, 1); + if ((integer)(substr($bot->Text(), 1, 2)) > 0) { + $wordId = substr($bot->Text(), 1, 2); + } + if ((integer)(substr($bot->Text(), 1, 3)) > 0) { + $wordId = substr($bot->Text(), 1, 3); + } + if ((integer)(substr($bot->Text(), 1, 4)) > 0) { + $wordId = substr($bot->Text(), 1, 4); + } + if ((integer)(substr($bot->Text(), 1, 5)) > 0) { + $wordId = substr($bot->Text(), 1, 5); + } + return $wordId; + } + + /** + * @param int $aya + * @param mixed $suraName + * @param int $sure + * @param string $message + * @return string + */ + public static + function addAyeIdAndBesmella(int $aya, mixed $suraName, int $sure, string $message): string + { + if ($aya == 1) { + $message = $suraName . (($sure == 1 || $sure == 9) ? " +" : " +بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ +") . $message . " :(" . $sure . ":" . $aya . ")"; + } +// else { +// $message .= "(" . $aya . ")"; +// } + return $message; + } + + /** + * @param Telegram $bot + * @param $token + * @return void + * @throws GuzzleException + */ + public + function generateJozKeyBoardThenSendIt(Telegram $bot, $token): void + { + for ($i = 0; $i < 30; $i += 2) { + $inlineKeyboard = BotHelper::makeKeyboard2button(trans("bot.Juz") . ($i + 1), config('juz.' . ($i + 1)), trans("bot.Juz") . ($i + 2), config('juz.' . ($i + 2))); + BotHelper::messageWithKeyboard($token, $bot->ChatID(), trans("bot.Juz") . ($i + 1) . " " . trans("bot.and") . " " . ($i + 2), $inlineKeyboard); + } + } + + /** + * @param Telegram $bot + * @return void + */ + public + function generateJozKeyBoardThenSendItTelegram(Telegram $bot): void + { + for ($i = 0; $i < 30; $i += 2) { + $message = trans("bot.Juz") . ($i + 1) . " " . trans("bot.and") . " " . ($i + 2); + $array = [[trans("bot.Juz") . ($i + 1), config('juz.' . ($i + 1))], [trans("bot.Juz") . ($i + 2), config('juz.' . ($i + 2))]]; + BotHelper::sendTelegram2InlineMessage($bot, $message, $array, true); + } + } + + /** + * @param Telegram $bot + * @return void + */ + public static + function generateJozLinksThenSendItTelegram($bot): void + { + $message = ""; + for ($i = 1; $i <= 30; $i++) { + $message .= trans("bot.Juz") . $i . " + +" . config('juz.' . $i) . " + +"; +// " . trans("bot.Juz") . $i . " + } + BotHelper::sendMessageParseMode($bot, $message); + } + + /** + * @param Telegram $bot + * @param $token + * @return void + * @throws GuzzleException + */ + public static + function generateBaleFehrestThenSendIt(Telegram $bot, $token): void + { + $quranSurahs = QuranSurah::select(['id', 'ayah', 'arabic', 'sajda', 'location']) + ->get(); + + for ($i = 0; $i < 114; $i += 6) { + for ($j = 0; $j < 6; $j++) { + $array[$j] = [$quranSurahs[$i + $j]->id . ":" . $quranSurahs[$i + $j]->arabic . ":" . $quranSurahs[$i + $j]->ayah, "/sure" . ($i + $j + 1) . "ayah1"]; + } + + $inlineKeyboard = BotHelper::makeKeyboard6button($array); + BotHelper::messageWithKeyboard($token, $bot->ChatID(), trans("bot.surah number:") . ($i + 1) . " " . trans("bot.to") . " " . ($i + 6), $inlineKeyboard); + } + } + + /** + * @param Telegram $bot + * @return void + */ + public static + function generateTelegramFehrestThenSendIt(Telegram $bot): void + { + $quranSurahs = QuranSurah::select('id', 'ayah', 'arabic', 'sajda', 'location') + ->get(); + + for ($i = 0; $i < 114; $i += 6) { + for ($j = 0; $j < 6; $j++) { + $array[$j] = [$quranSurahs[$i + $j]->id . ":" . $quranSurahs[$i + $j]->arabic . ":" . $quranSurahs[$i + $j]->ayah, "/sure" . ($i + $j + 1) . "ayah1"]; + } + $message = trans("bot.surah number:") . ($i + 1) . " " . trans("bot.to") . " " . ($i + 6); + BotHelper::sendTelegram6InlineMessage($bot, $message, $array, true); + } + } + + /** + * @param $bot + * @return void + */ + public static + function generateGapFehrestThenSendIt($bot): void + { + $quranSurahs = QuranSurah::select('id', 'ayah', 'arabic', 'sajda', 'location') + ->get(); + $message = ""; + for ($i = 0; $i < 114; $i++) { + $message .= $quranSurahs[$i]->id . ":" . $quranSurahs[$i]->arabic . ":" . $quranSurahs[$i]->ayah . ": + + /sure" . ($i + 1) . "ayah1 + + "; + } + BotHelper::sendMessage($bot, $message); + } + + /** + * @param int $aya + * @param int $sure + * @param Telegram $bot + * @param BotUsers|null $userSettings + * @return void + */ + public static function sendAudioMp3Aye(int $aya, int $sure, $bot, BotUsers $userSettings = null): void + { + if ($aya == 1 && $sure != 1 && $sure != 9) { + QuranHelper::sendAudio($bot, 1, 1, $userSettings); + } + QuranHelper::sendAudio($bot, $sure, $aya, $userSettings); + } + + /** + * @param int $aya + * @param int $sure + * @param Telegram $bot + * @param $postfix + * @param BotUsers|null $userSettings + * @return void + */ + public static function sendAudioMp3AyeByLocale(int $aya, int $sure, $bot, $postfix, BotUsers $userSettings = null): void + { + if ($aya == 1 && $sure != 1 && $sure != 9) { + QuranHelper::sendAudioByLocale($bot, 1, 1, $userSettings, $postfix); + } + QuranHelper::sendAudioByLocale($bot, $sure, $aya, $userSettings, $postfix); + } + + public function generateJozLinksThenSendItBale(Telegram $bot): void + { + $message = ""; + for ($i = 0; $i < 30; $i += 2) { + $message .= trans("bot.Juz") . ($i + 1) . " " . trans("bot.and") . " " . ($i + 2) . " +[" . trans("bot.Juz") . ($i + 1) . "](send:" . config('juz.' . ($i + 1)) . ") [" . trans("bot.Juz") . ($i + 2) . "](send:" . config('juz.' . ($i + 2)) . ") +"; + } + BotHelper::sendMessage($bot, $message); + } + + public static function generateArrayCommands(Model|bool|BotUsers $userSettings): array + { + if (!$userSettings) { + return [ + [ + "text" => trans("bot.disable enable reciter"), + "callback_data" => "/mp3" + ], + [ + "text" => trans("bot.change reciter"), + "callback_data" => "/mp3reciter" + ] + ]; + } else { + $mp3Reciter = $userSettings->setting('mp3_reciter'); + $mp3Enable = $userSettings->setting('mp3_enable'); + + $mp3EnableArray = [ + "text" => trans("bot.enable reciter"), + "callback_data" => "/mp3_true" + ]; + + $mp3DisableArray = [ + "text" => trans("bot.disable reciter"), + "callback_data" => "/mp3_false" + ]; + + + $mp3ReciterParhizgarArray = [ + "text" => trans("bot.reciter :reciter", ['reciter' => trans('bot.parhizgar')]), + "callback_data" => "/mp3reciter_parhizgar" + ]; + + $mp3ReciterAlafasyArray = [ + "text" => trans("bot.reciter :reciter", ['reciter' => trans('bot.alafasy')]), + "callback_data" => "/mp3reciter_alafasy" + ]; + + $resultArray = []; + + if ($mp3Enable == "true") { + $resultArray[] = $mp3DisableArray; + } else { + $resultArray[] = $mp3EnableArray; + } + + if ($mp3Reciter == "parhizgar") { + $resultArray[] = $mp3ReciterAlafasyArray; + } else { + $resultArray[] = $mp3ReciterParhizgarArray; + } + return $resultArray; + } + } + /** * @param mixed $type @@ -709,6 +958,7 @@ private static function getCommandNextPage(string $searchPhrase, int $nextPage): //" . $searchPhrase . "page=" . $nextPage; } + } diff --git a/app/Http/Controllers/QuranWordController.php b/app/Http/Controllers/QuranWordController.php index e1a29d5d..c0011376 100644 --- a/app/Http/Controllers/QuranWordController.php +++ b/app/Http/Controllers/QuranWordController.php @@ -10,7 +10,6 @@ use App\Interfaces\Services\QuranBotUserRankingService; use App\Models\BotLog; use App\Models\BotUsers; -use App\Models\QuranSurah; use Exception; use Gap\SDP\Api as GapBot; use GuzzleHttp\Exception\GuzzleException; @@ -88,7 +87,7 @@ public function index(BotRequest $request) $userSettings = BotUsers::firstOrNew($bot->ChatID(), $request->input('bot_mother_id'), $type); - $arrayCommands = $this->generateArrayCommands($userSettings); + $arrayCommands = QuranHelper::generateArrayCommands($userSettings); // if ((substr($bot->Text(), 0, 2)) == "//") // $request->request->add(['command_type' => 'quran_search']); @@ -123,7 +122,7 @@ public function index(BotRequest $request) } elseif ((integer)(substr($bot->Text(), 1, 1)) > 0) { $command_type = "word"; - $wordId = $this->getWordId($bot); + $wordId = QuranHelper::getWordId($bot); [$message, $isEndAya] = QuranHelper::getQuranWordById($wordId); // BotHelper::sendMessageToSuperAdmin("از طرف تلگرام" . ":" . $bot->Text() . ":" . $wordId . ":" . $message, 'bale'); $next = ((integer)$wordId == 88246 ? "88246" : ((integer)$wordId + 1)); @@ -158,7 +157,7 @@ public function index(BotRequest $request) if ($type == 'telegram' || $type == 'bale') { QuranHelper::sendScanPage($bot, $pageNumber, $hr); - $this->sendAudioMp3Page($bot, $pageNumber); + QuranHelper::sendAudioMp3Page($bot, $pageNumber); } } } @@ -180,7 +179,7 @@ public function index(BotRequest $request) [$maxAyah, $sureName] = QuranHelper::getLastAyeBySurehId($sure); [$maxAyahSureGhabli, $sureGhabliName] = QuranHelper::getLastAyeBySurehId($sure != 1 ? $sure - 1 : 114); - $message = $this->addAyeIdAndBesmella($aya, $sureName, $sure, $message); + $message = QuranHelper::addAyeIdAndBesmella($aya, $sureName, $sure, $message); $nextSure = $commandTemplateSure . ($sure != 114 ? $sure + 1 : 1) . $commandTemplateAyah . "1"; $firstAyaOfLastSure = $commandTemplateSure . ($sure - 1) . $commandTemplateAyah . "1"; @@ -205,15 +204,13 @@ public function index(BotRequest $request) } if ($bot->BotType() != "gap") { - $this->sendAudioMp3Aye($aya, $sure, $bot, $userSettings); + QuranHelper::sendAudioMp3Aye($aya, $sure, $bot, $userSettings); if (App::getLocale()) { $postfix = config("reciter.audio." . App::getLocale(), ''); if ($postfix) { - $this->sendAudioMp3AyeByLocale($aya, $sure, $bot, $postfix, $userSettings); + QuranHelper::sendAudioMp3AyeByLocale($aya, $sure, $bot, $postfix, $userSettings); } } - - } } } @@ -235,18 +232,17 @@ public function index(BotRequest $request) $command = substr($botText, strpos($botText, "/") + Str::length("/")); if ($command == "fehrest") { if ($type == 'telegram') { - $this->generateTelegramFehrestThenSendIt($bot); + QuranHelper::generateTelegramFehrestThenSendIt($bot); } else if ($type == 'gap') { - $this->generateGapFehrestThenSendIt($bot); + QuranHelper::generateGapFehrestThenSendIt($bot); } else { - $this->generateBaleFehrestThenSendIt($bot, $token); + QuranHelper::generateBaleFehrestThenSendIt($bot, $token); } } else if ($command == "joz") { if ($type != 'bale') { - $this->generateJozLinksThenSendItTelegram($bot); - + QuranHelper::generateJozLinksThenSendItTelegram($bot); } else { - $this->generateJozLinksThenSendItBale($bot); + QuranHelper::generateJozLinksThenSendItBale($bot); } } else if ($command == "report") { $chatId = $bot->ChatID(); @@ -507,260 +503,4 @@ function messageToAll(BotRequest $request) } } - /** - * @param Telegram $bot - * @return string - */ - public - function getWordId($bot): string - { - $wordId = substr($bot->Text(), 1, 1); - if ((integer)(substr($bot->Text(), 1, 2)) > 0) { - $wordId = substr($bot->Text(), 1, 2); - } - if ((integer)(substr($bot->Text(), 1, 3)) > 0) { - $wordId = substr($bot->Text(), 1, 3); - } - if ((integer)(substr($bot->Text(), 1, 4)) > 0) { - $wordId = substr($bot->Text(), 1, 4); - } - if ((integer)(substr($bot->Text(), 1, 5)) > 0) { - $wordId = substr($bot->Text(), 1, 5); - } - return $wordId; - } - - /** - * @param int $aya - * @param mixed $suraName - * @param int $sure - * @param string $message - * @return string - */ - public - function addAyeIdAndBesmella(int $aya, mixed $suraName, int $sure, string $message): string - { - if ($aya == 1) { - $message = $suraName . (($sure == 1 || $sure == 9) ? " -" : " -بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ -") . $message . " :(" . $sure . ":" . $aya . ")"; - } -// else { -// $message .= "(" . $aya . ")"; -// } - return $message; - } - - /** - * @param Telegram $bot - * @param $token - * @return void - * @throws GuzzleException - */ - public - function generateJozKeyBoardThenSendIt(Telegram $bot, $token): void - { - for ($i = 0; $i < 30; $i += 2) { - $inlineKeyboard = BotHelper::makeKeyboard2button(trans("bot.Juz") . ($i + 1), config('juz.' . ($i + 1)), trans("bot.Juz") . ($i + 2), config('juz.' . ($i + 2))); - BotHelper::messageWithKeyboard($token, $bot->ChatID(), trans("bot.Juz") . ($i + 1) . " " . trans("bot.and") . " " . ($i + 2), $inlineKeyboard); - } - } - - /** - * @param Telegram $bot - * @return void - */ - public - function generateJozKeyBoardThenSendItTelegram(Telegram $bot): void - { - for ($i = 0; $i < 30; $i += 2) { - $message = trans("bot.Juz") . ($i + 1) . " " . trans("bot.and") . " " . ($i + 2); - $array = [[trans("bot.Juz") . ($i + 1), config('juz.' . ($i + 1))], [trans("bot.Juz") . ($i + 2), config('juz.' . ($i + 2))]]; - BotHelper::sendTelegram2InlineMessage($bot, $message, $array, true); - } - } - - /** - * @param Telegram $bot - * @return void - */ - public - function generateJozLinksThenSendItTelegram($bot): void - { - $message = ""; - for ($i = 1; $i <= 30; $i++) { - $message .= trans("bot.Juz") . $i . " - -" . config('juz.' . $i) . " - -"; -// " . trans("bot.Juz") . $i . " - } - BotHelper::sendMessageParseMode($bot, $message); - } - - /** - * @param Telegram $bot - * @param $token - * @return void - * @throws GuzzleException - */ - public - function generateBaleFehrestThenSendIt(Telegram $bot, $token): void - { - $quranSurahs = QuranSurah::select(['id', 'ayah', 'arabic', 'sajda', 'location']) - ->get(); - - for ($i = 0; $i < 114; $i += 6) { - for ($j = 0; $j < 6; $j++) { - $array[$j] = [$quranSurahs[$i + $j]->id . ":" . $quranSurahs[$i + $j]->arabic . ":" . $quranSurahs[$i + $j]->ayah, "/sure" . ($i + $j + 1) . "ayah1"]; - } - - $inlineKeyboard = BotHelper::makeKeyboard6button($array); - BotHelper::messageWithKeyboard($token, $bot->ChatID(), trans("bot.surah number:") . ($i + 1) . " " . trans("bot.to") . " " . ($i + 6), $inlineKeyboard); - } - } - - /** - * @param Telegram $bot - * @return void - */ - public - function generateTelegramFehrestThenSendIt(Telegram $bot): void - { - $quranSurahs = QuranSurah::select('id', 'ayah', 'arabic', 'sajda', 'location') - ->get(); - - for ($i = 0; $i < 114; $i += 6) { - for ($j = 0; $j < 6; $j++) { - $array[$j] = [$quranSurahs[$i + $j]->id . ":" . $quranSurahs[$i + $j]->arabic . ":" . $quranSurahs[$i + $j]->ayah, "/sure" . ($i + $j + 1) . "ayah1"]; - } - $message = trans("bot.surah number:") . ($i + 1) . " " . trans("bot.to") . " " . ($i + 6); - BotHelper::sendTelegram6InlineMessage($bot, $message, $array, true); - } - } - - /** - * @param $bot - * @return void - */ - public - function generateGapFehrestThenSendIt($bot): void - { - $quranSurahs = QuranSurah::select('id', 'ayah', 'arabic', 'sajda', 'location') - ->get(); - $message = ""; - for ($i = 0; $i < 114; $i++) { - $message .= $quranSurahs[$i]->id . ":" . $quranSurahs[$i]->arabic . ":" . $quranSurahs[$i]->ayah . ": - - /sure" . ($i + 1) . "ayah1 - - "; - } - BotHelper::sendMessage($bot, $message); - } - - /** - * @param int $aya - * @param int $sure - * @param Telegram $bot - * @param BotUsers|null $userSettings - * @return void - */ - public function sendAudioMp3Aye(int $aya, int $sure, $bot, BotUsers $userSettings = null): void - { - if ($aya == 1 && $sure != 1 && $sure != 9) { - QuranHelper::sendAudio($bot, 1, 1, $userSettings); - } - QuranHelper::sendAudio($bot, $sure, $aya, $userSettings); - } - - /** - * @param int $aya - * @param int $sure - * @param Telegram $bot - * @param $postfix - * @param BotUsers|null $userSettings - * @return void - */ - public function sendAudioMp3AyeByLocale(int $aya, int $sure, $bot, $postfix, BotUsers $userSettings = null): void - { - if ($aya == 1 && $sure != 1 && $sure != 9) { - QuranHelper::sendAudioByLocale($bot, 1, 1, $userSettings, $postfix); - } - QuranHelper::sendAudioByLocale($bot, $sure, $aya, $userSettings, $postfix); - } - - private function generateJozLinksThenSendItBale(Telegram $bot) - { - $message = ""; - for ($i = 0; $i < 30; $i += 2) { - $message .= trans("bot.Juz") . ($i + 1) . " " . trans("bot.and") . " " . ($i + 2) . " -[" . trans("bot.Juz") . ($i + 1) . "](send:" . config('juz.' . ($i + 1)) . ") [" . trans("bot.Juz") . ($i + 2) . "](send:" . config('juz.' . ($i + 2)) . ") -"; - } - BotHelper::sendMessage($bot, $message); - } - - private function generateArrayCommands(\Illuminate\Database\Eloquent\Model|bool|BotUsers $userSettings) - { - if (!$userSettings) { - return [ - [ - "text" => trans("bot.disable enable reciter"), - "callback_data" => "/mp3" - ], - [ - "text" => trans("bot.change reciter"), - "callback_data" => "/mp3reciter" - ] - ]; - } else { - $mp3Reciter = $userSettings->setting('mp3_reciter'); - $mp3Enable = $userSettings->setting('mp3_enable'); - - $mp3EnableArray = [ - "text" => trans("bot.enable reciter"), - "callback_data" => "/mp3_true" - ]; - - $mp3DisableArray = [ - "text" => trans("bot.disable reciter"), - "callback_data" => "/mp3_false" - ]; - - - $mp3ReciterParhizgarArray = [ - "text" => trans("bot.reciter :reciter", ['reciter' => trans('bot.parhizgar')]), - "callback_data" => "/mp3reciter_parhizgar" - ]; - - $mp3ReciterAlafasyArray = [ - "text" => trans("bot.reciter :reciter", ['reciter' => trans('bot.alafasy')]), - "callback_data" => "/mp3reciter_alafasy" - ]; - - $resultArray = []; - - if ($mp3Enable == "true") { - $resultArray[] = $mp3DisableArray; - } else { - $resultArray[] = $mp3EnableArray; - } - - if ($mp3Reciter == "parhizgar") { - $resultArray[] = $mp3ReciterAlafasyArray; - } else { - $resultArray[] = $mp3ReciterParhizgarArray; - } - return $resultArray; - } - } - - private function sendAudioMp3Page($bot, string $pageNumber) - { - QuranHelper::sendAudioMp3Page($bot, $pageNumber); - } - }