Skip to content

Commit

Permalink
refactor: #29 profile, better code when we have text. add funny text …
Browse files Browse the repository at this point in the history
…and get success levels
  • Loading branch information
geeksesi committed Apr 9, 2022
1 parent af19ea7 commit 4ab26d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/Helper/OutputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public static function by_type(string $_chat_id, OutputMessageEnum $_type, bool
$text = $message->text;
}


if (!empty($data)) {
$text = self::fill_data($message->text, $data);
}
Expand Down Expand Up @@ -102,20 +101,22 @@ 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)
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;

$message = "شما {$user->name} هستی، فقط هم مال مایی 😌";
$message .= "\n";
$message .= "ماشالله {$user->credit} 💰 سکه داری 🤧";
$message .= "\n";
$message .= "اولین بار از {$diff->days} روز پیش داری بازی می کنی 😍";
$message .= "\n";
$message .= "تو این چند وقت به {$user->level_count()} تا مرحله جواب دادی 😦";

TelegramHelper::send_photo($image, $_chat_id, $message, $keyboard);
}
}
14 changes: 14 additions & 0 deletions app/Model/GameLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,18 @@ public static function action(Level $level, User $user, GameLogActionEnum $actio
}
$log->save();
}

public static function user_level_count(User $user): int
{
$table = self::$table;
$db = self::connection();

$query = $db->prepare("SELECT count(*) FROM {$table} WHERE user_id=:user_id");

if (!$query->execute([":user_id" => $user->id])) {
return 0;
}
$result = $query->fetch(PDO::FETCH_ASSOC);
return $result["count(*)"];
}
}
5 changes: 5 additions & 0 deletions app/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ public function invite_link(): string
}
return $_ENV["BOT_LINK"] . "?start=" . $this->invite_key;
}

public function level_count(): int
{
return GameLog::user_level_count($this);
}
}

0 comments on commit 4ab26d6

Please sign in to comment.