Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

profile added #29

Merged
merged 6 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/Controller/Keyboard/BackKeyboardController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Controller\Keyboard;

use App\Controller\Controller;
use App\Enums\OutputMessageEnum;
use App\Helper\OutputHelper;

class BackKeyboardController extends Controller
{
public function __invoke(): bool
{
// Start Message
OutputHelper::by_type($this->chat_id, OutputMessageEnum::BACK);

return true;
}
}
17 changes: 17 additions & 0 deletions app/Controller/Keyboard/ProfileKeyboardController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Controller\Keyboard;

use App\Controller\Controller;
use App\Enums\OutputMessageEnum;
use App\Helper\OutputHelper;

class ProfileKeyboardController extends Controller
{
public function __invoke(): bool
{
OutputHelper::profile($this->chat_id , $this->user);

return true;
}
}
4 changes: 3 additions & 1 deletion app/Enums/OutputMessageEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ enum OutputMessageEnum: int
case LEVEL = 4;
case FINISH_GAME = 5;

// about keyboards
// Main keyboards
case START_GAME = 20;
case CONTINUE = 21;
case ABOUT = 22;
case CONTACT = 23;
case SUPPORT = 25;
case YOUTUBE = 26;
case PROFILE = 27;
case BACK = 28;

// Commands
case START_COMMAND_GUEST = 30;
Expand Down
162 changes: 49 additions & 113 deletions app/Helper/InputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,30 @@
use App\Controller\Command\ChatIdCommandController;
use App\Controller\Command\StartCommandController;
use App\Controller\Game\GameController;
use App\Controller\Keyboard\AboutKeyboardController;
use App\Controller\Keyboard\BuyCreditKeyboardController;
use App\Controller\Keyboard\ContactKeyboardController;
use App\Controller\Keyboard\FreeCreditKeyboardController;
use App\Controller\Keyboard\GameContinueKeyboardController;
use App\Controller\Keyboard\GameStartKeyboardController;
use App\Controller\Keyboard\HintKeyboardController;
use App\Controller\Keyboard\LeaderBoardKeyboardController;
use App\Controller\Keyboard\SupportKeyboardController;
use App\Controller\Keyboard\YourCreditKeyboardController;
use App\Controller\Keyboard\YoutubeKeyboardController;
use App\Model\User;

class InputHelper
{
private $update;

private array $replays = [
'سکه رایگان' => 'FreeCreditKeyboardController',
'برترین ها' => 'LeaderBoardKeyboardController',
'ادامه بازی' => 'GameContinueKeyboardController',
'خرید سکه' => 'BuyCreditKeyboardController',
'آموزش ساخت بازی' => 'YoutubeKeyboardController',
'شروع بازی' => 'GameStartKeyboardController',
'درباره ما' => 'AboutKeyboardController',
'پروفایل' => 'ProfileKeyboardController',
'تماس با ما' => 'ContactKeyboardController',
'کمک می‌خوای' => 'HintKeyboardController',
'حمایت از ما' => 'SupportKeyboardController',
'سکه‌های شما' => 'YourCreditKeyboardController',
'بازگشت' => 'BackKeyboardController',
];

private string $controllersNs = 'App\Controller\Keyboard';

public function __construct(array $update)
{
// sanitize frequent access variable
Expand All @@ -51,25 +58,22 @@ public function __invoke()

public function run()
{
switch ($this->update["message"]["chat"]["type"]) {
case "private":
return $this->private();
break;
case "group":
case "supergroup":
return $this->group();
break;
}
return match ($this->update["message"]["chat"]["type"]) {
"private" => $this->private(),
"group", "supergroup" => $this->group(),
};
}

private function private()
{
if (!User::get_first("WHERE chat_id=:chat_id", [":chat_id" => $this->update["message"]["chat"]["id"]])) {
if ( ! User::get_first("WHERE chat_id=:chat_id", [":chat_id" => $this->update["message"]["chat"]["id"]])) {
return (new StartCommandController($this->update))();
}

if (isset($this->update["message"]["text"])) {
return $this->text();
}

return null;
}

Expand Down Expand Up @@ -111,74 +115,27 @@ private function text()
if ($admin = $this->admin()) {
return $admin;
}

return $this->game();
}

private function native_commands()
{
switch ($this->update["message"]["text"]) {
case "/start":
return (new StartCommandController($this->update))();
break;
case "/chat_id":
return (new ChatIdCommandController($this->update))();
break;

default:
return null;
break;
}
return match ($this->update["message"]["text"]) {
"/start" => (new StartCommandController($this->update))(),
"/chat_id" => (new ChatIdCommandController($this->update))(),
default => null,
};
}

private function reply_keyboard()
{
switch ($this->update["message"]["text"]) {
case "💸 سکه رایگان":
return (new FreeCreditKeyboardController($this->update))();
break;
case "🥇 برترین ها":
return (new LeaderBoardKeyboardController($this->update))();
break;
case "❣️ ادامه بازی":
return (new GameContinueKeyboardController($this->update))();
break;
case "💳 خرید سکه":
return (new BuyCreditKeyboardController($this->update))();
break;
// case "💵 سکه‌های شما‌ : ":
// return (new YourCreditKeyboardController($this->update))();
// break;
case "آموزش ساخت بازی 🕹":
return (new YoutubeKeyboardController($this->update))();
break;
case "شروع بازی":
return (new GameStartKeyboardController($this->update))();
break;
case "ادامه بازی":
return (new GameStartKeyboardController($this->update))();
break;
case "🖥 درباره ما":
return (new AboutKeyboardController($this->update))();
break;
case "📞 تماس با ما":
return (new ContactKeyboardController($this->update))();
break;
// case "🪄 کمک می‌خوای ؟":
// return (new HintKeyboardController($this->update))();
// break;
case "😍 حمایت از ما":
return (new SupportKeyboardController($this->update))();
break;

default:
break;
}
foreach ($this->replays as $text => $class) {
if (str_contains($this->update["message"]["text"], $text)) {
$class = $this->controllersNs.'\\'.$class;

if (stripos($this->update["message"]["text"], "کمک می‌خوای")) {
return (new HintKeyboardController($this->update))();
}
if (stripos($this->update["message"]["text"], "سکه‌های شما‌")) {
return (new YourCreditKeyboardController($this->update))();
return (new $class($this->update))();
}
}

return false;
Expand All @@ -197,40 +154,19 @@ private function admin()
return false;
}
$command = substr($this->update["message"]["text"], 0, 10);
switch ($command) {
case "!help":
return (new HelpController($this->update))();
break;
case "!aNewLevel":
return (new AddLevelController($this->update))();
break;
case "!aNewHints":
return (new AddHintController($this->update))();
break;
case "!aOuttexts":
return (new AddOutputMessageController($this->update))();
break;
case "!listLevel":
return (new ListLevelsController($this->update))();
break;
case "!listHints":
return (new ListHintsController($this->update))();
break;
case "!listOMesg":
return (new ListOutputMessagesController($this->update))();
break;
case "!getUserId":
return (new GetUserByChatIdController($this->update))();
break;
case "!newAds":
return (new AddNewAdvertiseController($this->update))();
break;

default:
return false;
break;
}
return false;

return match ($command) {
"!help" => (new HelpController($this->update))(),
"!aNewLevel" => (new AddLevelController($this->update))(),
"!aNewHints" => (new AddHintController($this->update))(),
"!aOuttexts" => (new AddOutputMessageController($this->update))(),
"!listLevel" => (new ListLevelsController($this->update))(),
"!listHints" => (new ListHintsController($this->update))(),
"!listOMesg" => (new ListOutputMessagesController($this->update))(),
"!getUserId" => (new GetUserByChatIdController($this->update))(),
"!newAds" => (new AddNewAdvertiseController($this->update))(),
default => false,
};
}

private function game()
Expand Down
21 changes: 20 additions & 1 deletion app/Helper/KeyboardMakerHepler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class KeyboardMakerHepler
"contact" => "📞 تماس با ما",
"hint" => "🪄 کمک می‌خوای ؟",
"support" => "😍 حمایت از ما",
"profile" => "💀 پروفایل",
"profile" => "👤 پروفایل",
"change" => "تغییر پروفایل 📝",
"back" => "بازگشت 🔙",
];

public static function by_type(OutputMessageEnum $type)
Expand Down Expand Up @@ -117,8 +119,25 @@ public static function no_mission()
true
);
}

public static function FINISH_GAME()
{
return self::no_mission();
}

public static function profile(): array
{
return TelegramHelper::make_keyboard(
[
[["text" => self::$texts["change"]], ["text" => self::$texts["back"]]],
],
true,
true
);
}

public static function back(): array
{
return self::default_keyboard();
}
}
22 changes: 20 additions & 2 deletions app/Helper/OutputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public static function by_type(string $_chat_id, OutputMessageEnum $_type, bool
$message = OutputMessage::by_type($_type);
}
if (empty($message)) {
return false;
$text = $_type->name;
} else {
$text = $message->text;
}

$text = $message->text;

if (!empty($data)) {
$text = self::fill_data($message->text, $data);
Expand Down Expand Up @@ -100,4 +101,21 @@ public static function low_credit(string $_chat_id)
{
self::by_type($_chat_id, OutputMessageEnum::LOW_CREDIT);
}

public static function profile(string $_chat_id , User $user)
{
$image = $user->image_id ?? TelegramHelper::get_user_profile_photo($_chat_id);
$keyboard = KeyboardMakerHepler::by_type(OutputMessageEnum::PROFILE);
$now = new \DateTime();
$from = new \DateTime($user->created_at);
$diff = $now->diff($from);
$message = <<<EOT
نام : {$user->name}
تعداد سکه : {$user->credit}
سطح : {$user->level()->difficulty}
عضو از : {$diff->days} روز قبل
------
EOT;
TelegramHelper::send_photo($image, $_chat_id, $message, $keyboard);
}
}
Loading