mirror of
https://github.com/v2board/v2board.git
synced 2025-01-10 16:19:10 +08:00
update telegram
This commit is contained in:
parent
bd1b339db8
commit
2e13bab3d8
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketMessage;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TicketController extends Controller
|
||||
@ -194,7 +193,7 @@ class TicketController extends Controller
|
||||
->where('telegram_id', '!=', NULL)
|
||||
->get();
|
||||
foreach ($users as $user) {
|
||||
$text = "📮工单提醒\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$ticketMessage->message}`";
|
||||
$text = "📮工单提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$ticketMessage->message}`";
|
||||
SendTelegramJob::dispatch($user->telegram_id, $text);
|
||||
}
|
||||
}
|
||||
|
@ -98,4 +98,22 @@ class Helper
|
||||
if (!in_array($suffix, $suffixs)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function trafficConvert(int $byte)
|
||||
{
|
||||
$kb = 1024;
|
||||
$mb = 1048576;
|
||||
$gb = 1073741824;
|
||||
if ($byte > $gb) {
|
||||
return round($byte / $gb, 2) . ' GB';
|
||||
} else if ($byte > $mb) {
|
||||
return round($byte / $mb, 2) . ' MB';
|
||||
} else if ($byte > $kb) {
|
||||
return round($byte / $kb, 2) . ' KB';
|
||||
} else if ($byte < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return round($byte, 2) . ' B';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
public/assets/user/umi.js
vendored
2
public/assets/user/umi.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user