update telegram

This commit is contained in:
Tokumeikoi
2020-05-25 16:39:35 +08:00
parent bd1b339db8
commit 2e13bab3d8
4 changed files with 41 additions and 3 deletions

View File

@ -6,6 +6,7 @@ use App\Services\TelegramService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Utils\Helper;
class TelegramController extends Controller
{
@ -26,6 +27,8 @@ class TelegramController extends Controller
switch($this->msg->command) {
case '/bind': $this->bind();
break;
case '/traffic': $this->traffic();
break;
default: $this->help();
}
} catch (\Exception $e) {
@ -84,4 +87,22 @@ class TelegramController extends Controller
$text = implode(PHP_EOL, $commands);
$telegramService->sendMessage($msg->chat_id, "你可以使用以下命令进行操作:\n\n$text", 'markdown');
}
private function traffic()
{
$msg = $this->msg;
if (!$msg->is_private) return;
$user = User::where('telegram_id', $msg->chat_id)->first();
if (!$user) {
$this->help();
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总流量:`{$transferEnable}`\n已用上行:`{$up}`\n已用下行:`{$down}`\n剩余流量:`{$remaining}`";
$telegramService = new TelegramService();
$telegramService->sendMessage($msg->chat_id, $text, 'markdown');
}
}