feat: Add bot analysis and command services, bot settings, and a frontend account center with subscription and EVM wallet integration.

This commit is contained in:
2569718930@qq.com
2026-03-13 12:45:39 +08:00
parent c3958c29c7
commit 50a2202930
5 changed files with 45 additions and 10 deletions
@@ -633,6 +633,17 @@ export function AccountCenter() {
const address = String(accounts?.[0] || "").toLowerCase();
if (!address) throw new Error("钱包账户为空");
const existingWallet = boundWallets.find(
(w) => String(w.address || "").toLowerCase() === address,
);
if (existingWallet) {
setWalletAddress(address);
setSelectedWallet(address);
setPaymentInfo(`${walletLabel} 已绑定: ${shortAddress(address)}`);
setPaymentBusy(false);
return;
}
setWalletAddress(address);
const challengeRes = await fetch("/api/payments/wallets/challenge", {
method: "POST",
@@ -82,8 +82,16 @@ export function UnlockProOverlay({
const finalPayLabel =
payLabel || (isEn ? "Subscribe & Activate" : "立即订阅并激活服务");
const maxDiscountUsdInt = Math.max(1, Math.floor(billing.maxDiscountUsd || 0));
const maxPointsForFullDiscount = Math.max(
billing.pointsPerUsd,
billing.pointsPerUsd * maxDiscountUsdInt,
);
const redeemableUsdNow = billing.pointsEnabled
? Math.min(maxDiscountUsdInt, Math.floor(points / Math.max(1, billing.pointsPerUsd)))
: 0;
const progressPct = billing.pointsEnabled
? Math.min(100, Math.round((points / billing.pointsPerUsd) * 100))
? Math.min(100, Math.round((points / maxPointsForFullDiscount) * 100))
: 0;
return (
@@ -202,6 +210,11 @@ export function UnlockProOverlay({
? `Toggle to save up to $${billing.maxDiscountUsd.toFixed(2)}`
: `开启可最多抵扣 $${billing.maxDiscountUsd.toFixed(2)}`}
</p>
<p className={s.pointsNote}>
{isEn
? `Now redeemable: $${redeemableUsdNow.toFixed(0)} / $${maxDiscountUsdInt.toFixed(0)}`
: `当前可抵:${redeemableUsdNow.toFixed(0)}U / ${maxDiscountUsdInt.toFixed(0)}U`}
</p>
<div className={s.pointsBalance}>
<Sparkles size={11} />
@@ -242,17 +255,21 @@ export function UnlockProOverlay({
? "Points redemption is unavailable for this plan."
: "当前套餐暂不支持积分抵扣。"
: isEn
? `Need ${billing.pointsPerUsd} pts minimum. You have: ${points}`
: `至少需要 ${billing.pointsPerUsd} 积分,当前仅有 ${points}`}
? `Starts at ${billing.pointsPerUsd} pts, ${billing.pointsPerUsd} pts per $1, up to $${maxDiscountUsdInt}. You have: ${points}`
: ` ${billing.pointsPerUsd} 分起兑,每 ${billing.pointsPerUsd} 分抵 1U,最多抵 ${maxDiscountUsdInt}U。当前 ${points}`}
</p>
{billing.pointsEnabled && (
<div className={s.progressWrap}>
<div className={s.progressHeader}>
<span>
{points} / {billing.pointsPerUsd}
{points} / {maxPointsForFullDiscount}
</span>
<span>
{isEn
? `$${redeemableUsdNow.toFixed(0)} / $${maxDiscountUsdInt.toFixed(0)}`
: `${redeemableUsdNow.toFixed(0)}U / ${maxDiscountUsdInt.toFixed(0)}U`}
</span>
<span>{progressPct}%</span>
</div>
<div className={s.progressTrack}>
<div
+8 -1
View File
@@ -33,6 +33,10 @@ class DebAnalysisService:
city_input_norm = city_input.strip().lower()
return aliases.get(city_input_norm, city_input_norm)
# Backward-compatible alias used by older service wrappers.
def resolve_deb_city(self, city_input: str) -> str:
return self.resolve_city(city_input)
def has_history(self, city_name: str) -> bool:
_is_excluded_model_name, load_history, reconcile_recent_actual_highs = (
self._load_deb_module_api()
@@ -42,6 +46,10 @@ class DebAnalysisService:
city_data = data.get(city_name)
return isinstance(city_data, dict) and bool(city_data)
# Backward-compatible alias used by older service wrappers.
def has_deb_history(self, city_name: str) -> bool:
return self.has_history(city_name)
def build_deb_accuracy_report(self, city_name: str, deb_query_cost: int) -> str:
_is_excluded_model_name, load_history, reconcile_recent_actual_highs = (
self._load_deb_module_api()
@@ -217,4 +225,3 @@ class DebAnalysisService:
lines.append("")
lines.append(f"💸 本次消耗 <code>{deb_query_cost}</code> 积分。")
return "\n".join(lines)
+2 -2
View File
@@ -18,10 +18,10 @@ class DebCommandService:
self.analysis = analysis
def resolve_city(self, city_input: str) -> str:
return self.analysis.resolve_deb_city(city_input)
return self.analysis.resolve_city(city_input)
def has_history(self, city_name: str) -> bool:
return self.analysis.has_deb_history(city_name)
return self.analysis.has_history(city_name)
def build_report(self, city_name: str, deb_query_cost: int) -> DebReportResult:
try:
+2 -2
View File
@@ -18,5 +18,5 @@ MESSAGE_POINTS = _env_int("POLYWEATHER_BOT_MESSAGE_POINTS", 4, min_value=1)
MESSAGE_DAILY_CAP = _env_int("POLYWEATHER_BOT_MESSAGE_DAILY_CAP", 40, min_value=1)
MESSAGE_MIN_LENGTH = _env_int("POLYWEATHER_BOT_MESSAGE_MIN_LENGTH", 3, min_value=1)
MESSAGE_COOLDOWN_SEC = _env_int("POLYWEATHER_BOT_MESSAGE_COOLDOWN_SEC", 30, min_value=0)
CITY_QUERY_COST = _env_int("POLYWEATHER_BOT_CITY_QUERY_COST", 1, min_value=0)
DEB_QUERY_COST = _env_int("POLYWEATHER_BOT_DEB_QUERY_COST", 1, min_value=0)
CITY_QUERY_COST = _env_int("POLYWEATHER_BOT_CITY_QUERY_COST", 2, min_value=0)
DEB_QUERY_COST = _env_int("POLYWEATHER_BOT_DEB_QUERY_COST", 2, min_value=0)