Skip to content

Commit

Permalink
random command supported
Browse files Browse the repository at this point in the history
  • Loading branch information
saber13812002 committed Nov 16, 2023
1 parent 343e657 commit d2f4bda
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/Helpers/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ public static function getWeatherBotCommandsAsPostfixForMessages(): string
*/
public static function getHadithCommandsAsPostfixForMessages(): string
{
$botType = Config::get('config.bot.type', 'bale');
// TODO: random implementation
return self::getStringMessageDivider() . "
برای جستجو
در کل احادیث کتب شیعه دستور /search
و برای نمایش جستجوهای دیگران در کتب شیعی /history
و برای ارسال یک حدیث تصادفی /random
و برای ارسال یک حدیث تصادفی " . " " . BotHelper::generateLink("/random", $botType) . "
را کلیک یا ارسال کنید.";
}

Expand Down
28 changes: 25 additions & 3 deletions app/Http/Controllers/HadithSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function index(BotRequest $request)
// $ifStatusAndPhraseValid = $this->checkStatusAndPhrase($lastStatus, $phrase);

$commands = StringHelper::getHadithCommandsAsPostfixForMessages();

if (str_starts_with($bot->Text(), "/")) {///_id=82Y5Ln0BGWfjTl3qHQNp
$offset = strpos($bot->Text(), "/") + Str::length("/");
$command = substr($bot->Text(), $offset);
Expand All @@ -71,17 +72,38 @@ public function index(BotRequest $request)
} else if ($command == "search") {
// TODO : saveLastCommandInDb($bot); performance said we need to have lastStatus log for any bot mother
$message = trans("hadith.Please send your phrase to search in all shia hadith books.");
} else if ($command == "random") {
$hadithCount = BotHadithItem::count();
$page = 1;
$limit = 1;
// dd($hadithCount);
$id = rand(1, $hadithCount);
// dd($id);
$hadith = BotHadithItem::query()->where("id", $id)->first();
// dd($hadith);

if ($hadith) {
$postFix = "
link: to share in twitter or edit
https://hadith.academyofislam.com/?q=_id:" . $hadith->id2 . "
";
BotHelper::sendLongMessage($this->getHadith($hadith) . $postFix, $bot);
} else {
BotHelper::sendMessage($bot, trans("bot.not found"));
}
return 1;
} else if ($isHadithIdRequested) {
// echo 'id2';
$id2 = substr($bot->Text(), 4);
$hadith = BotHadithItem::query()->where("id2", $id2)->first();
// dd($id2);
if ($hadith) {
$hadith .= "

$postFix = "
link: to share in twitter or edit
https://hadith.academyofislam.com/?q=_id:" . $id2 . "
https://hadith.academyofislam.com/?q=_id:" . $hadith->id2 . "
";
BotHelper::sendLongMessage($this->getHadith($hadith), $bot);
BotHelper::sendLongMessage($this->getHadith($hadith) . $postFix, $bot);
} else {
BotHelper::sendMessage($bot, trans("bot.not found"));
}
Expand Down

0 comments on commit d2f4bda

Please sign in to comment.