| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- declare(strict_types=1);
- namespace App\Services\Bot\Telegram\Commands;
- use App\Models\Config;
- use App\Services\Bot\Telegram\Message;
- use App\Services\Reward;
- use Telegram\Bot\Actions;
- use Telegram\Bot\Commands\Command;
- /**
- * Class CheckinCommand.
- */
- final class CheckinCommand extends Command
- {
- /**
- * @var string Command Name
- */
- protected string $name = 'checkin';
- /**
- * @var string Command Description
- */
- protected string $description = '[群组/私聊] 每日签到.';
- /**
- * {@inheritdoc}
- */
- public function handle()
- {
- $update = $this->getUpdate();
- $message = $update->getMessage();
- // 消息会话 ID
- $chat_id = $message->getChat()->getId();
- if ($chat_id < 0) {
- if (Config::obtain('telegram_group_quiet')) {
- // 群组中不回应
- return null;
- }
- if ($chat_id !== Config::obtain('telegram_chatid')) {
- // 非我方群组
- return null;
- }
- }
- // 发送 '输入中' 会话状态
- $this->replyWithChatAction(['action' => Actions::TYPING]);
- // 触发用户
- $send_user = [
- 'id' => $message->getFrom()->getId(),
- ];
- $user = Message::getUser($send_user['id']);
- if ($user === null) {
- // 回送信息
- $response = $this->replyWithMessage(
- [
- 'text' => Config::obtain('user_not_bind_reply'),
- 'parse_mode' => 'Markdown',
- 'reply_to_message_id' => $message->getMessageId(),
- ]
- );
- } else {
- if ($user->isAbleToCheckin()) {
- $traffic = Reward::issueCheckinReward($this->user->id);
- if (! $traffic) {
- $msg = '签到失败';
- } else {
- $msg = '获得了 ' . $traffic . 'MB 流量.';
- }
- } else {
- $msg = '你今天已经签到过了';
- }
- // 回送信息
- $response = $this->replyWithMessage(
- [
- 'text' => $msg,
- 'parse_mode' => 'Markdown',
- 'reply_to_message_id' => $message->getMessageId(),
- ]
- );
- }
- return $response;
- }
- }
|