mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-20 10:57:22 +08:00
支持ipv6并完善astrbot run子命令
* 默认host修改为::,同时新增两个环境变量DASHBOARD_HOST,DASHBOARD_ENABLE,和DASHBOARD_PORT对齐 * feat: systemd support (#4880) * fix: pyright lint (#4874) * feat: 将 MessageSession 的 platform_id 改为 init=False,实例化时无需传入 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 将 isinstance 检查改为元组、将默认模型值设为空字符串、将类型注解改为 Any 并导入 * refactor: 为 _serialize_job 增加返回类型注解 dict * fix: 使用 cast 获取百度 AIP 的 msg 并对 psutil_addr 引入 type: ignore Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 引入 _AddrWithPort 协议并替换 conn.laddr 的 cast Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: 在构建 AstrBotMessage 时对 ctx.channel 可能为 None 进行兜底处理 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> --------- Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: TypeError when MCP schema type is a list (#4867) * Fix TypeError when MCP schema type is a list Fixes crash in Gemini native tools with VRChat MCP. * Refactor: avoid modifying schema in place per feedback * Fix formatting and cleanup comments * docs: update watashiwakoseinodesukara Removed duplicate text and added a new image. * 修复/跨平台一致性 * 琐事/类型标注和一些简单错误修正 * 修复/检查端口时候包含ipv6 * 修复/enable变量的赋值逻辑 --------- Co-authored-by: Dt8333 <25431943+Dt8333@users.noreply.github.com> Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> Co-authored-by: boushi1111 <95118141+boushi1111@users.noreply.github.com> Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
@@ -7,6 +8,7 @@ import ssl
|
||||
import time
|
||||
import uuid
|
||||
import zipfile
|
||||
from ipaddress import IPv4Address, IPv6Address, ip_address
|
||||
from pathlib import Path
|
||||
|
||||
import aiohttp
|
||||
@@ -217,18 +219,51 @@ def file_to_base64(file_path: str) -> str:
|
||||
return "base64://" + base64_str
|
||||
|
||||
|
||||
def get_local_ip_addresses():
|
||||
def get_local_ip_addresses() -> list[IPv4Address | IPv6Address]:
|
||||
net_interfaces = psutil.net_if_addrs()
|
||||
network_ips = []
|
||||
network_ips: list[IPv4Address | IPv6Address] = []
|
||||
|
||||
for interface, addrs in net_interfaces.items():
|
||||
for _, addrs in net_interfaces.items():
|
||||
for addr in addrs:
|
||||
if addr.family == socket.AF_INET: # 使用 socket.AF_INET 代替 psutil.AF_INET
|
||||
network_ips.append(addr.address)
|
||||
if addr.family == socket.AF_INET:
|
||||
network_ips.append(ip_address(addr.address))
|
||||
elif addr.family == socket.AF_INET6:
|
||||
# 过滤掉 IPv6 的 link-local 地址(fe80:...)
|
||||
# 用这个不如用::1
|
||||
ip = ip_address(addr.address.split("%")[0]) # 处理带 zone index 的情况
|
||||
network_ips.append(ip)
|
||||
|
||||
return network_ips
|
||||
|
||||
|
||||
async def get_public_ip_address() -> list[IPv4Address | IPv6Address]:
|
||||
urls = [
|
||||
"https://api64.ipify.org",
|
||||
"https://ident.me",
|
||||
"https://ifconfig.me",
|
||||
"https://icanhazip.com",
|
||||
]
|
||||
found_ips: dict[int, IPv4Address | IPv6Address] = {}
|
||||
|
||||
async def fetch(session: aiohttp.ClientSession, url: str):
|
||||
try:
|
||||
async with session.get(url, timeout=3) as resp:
|
||||
if resp.status == 200:
|
||||
raw_ip = (await resp.text()).strip()
|
||||
ip = ip_address(raw_ip)
|
||||
if ip.version not in found_ips:
|
||||
found_ips[ip.version] = ip
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
tasks = [fetch(session, url) for url in urls]
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
# 返回找到的所有 IP 对象列表
|
||||
return list(found_ips.values())
|
||||
|
||||
|
||||
async def get_dashboard_version():
|
||||
dist_dir = os.path.join(get_astrbot_data_path(), "dist")
|
||||
if os.path.exists(dist_dir):
|
||||
|
||||
Reference in New Issue
Block a user