mirror of
https://github.com/v2board/v2board.git
synced 2025-06-13 13:17:52 +08:00
update: telegram bot modularization
This commit is contained in:
30
app/Plugins/Telegram/Commands/Traffic.php
Normal file
30
app/Plugins/Telegram/Commands/Traffic.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Telegram\Telegram;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class Traffic extends Telegram {
|
||||
public $command = '/traffic';
|
||||
public $description = '查询流量信息';
|
||||
|
||||
public function handle($message, $match = []) {
|
||||
$telegramService = $this->telegramService;
|
||||
if (!$message->is_private) return;
|
||||
$user = User::where('telegram_id', $message->chat_id)->first();
|
||||
if (!$user) {
|
||||
$help = new Help();
|
||||
$help->handle($message);
|
||||
$telegramService->sendMessage($message->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown');
|
||||
return;
|
||||
}
|
||||
$transferEnable = Helper::trafficConvert($user->transfer_enable);
|
||||
$up = Helper::trafficConvert($user->u);
|
||||
$down = Helper::trafficConvert($user->d);
|
||||
$remaining = Helper::trafficConvert($user->transfer_enable - ($user->u + $user->d));
|
||||
$text = "🚥流量查询\n———————————————\n计划流量:`{$transferEnable}`\n已用上行:`{$up}`\n已用下行:`{$down}`\n剩余流量:`{$remaining}`";
|
||||
$telegramService->sendMessage($message->chat_id, $text, 'markdown');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user