feat: 深色模式圆形揭示动画 + B 站私信规则
主题切换: - 抽出 useTheme 全局单例,主题在挂载前初始化,登录页不再闪白底 - 用 View Transitions API 以点击点为圆心做圆形揭示;不支持的浏览器 加 .no-vt 类退化为整页淡变,两者互斥避免揭示区露出过渡中的颜色 - 尊重 prefers-reduced-motion;过渡被浏览器跳过时静默降级为直接切换 - 主题按钮图标旋转切换 新规则: - bilibili-private-message:向指定 UID 发送 B 站私信, 发送者 UID 自动从账号 Cookie 读取 视觉打磨: - 统计数字改为缓出计数动画,等宽数字避免跳动时抖动 - 补 :focus-visible 焦点环 说明:当前 SDK 未提供视频投稿接口,无法支持定时投稿视频, 详见 docs/bilibili-config.md。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@ const (
|
||||
AccountType = "bilibili"
|
||||
// RuleTypeDynamic 发送 B 站动态的规则类型标识
|
||||
RuleTypeDynamic = "bilibili-dynamic"
|
||||
// RuleTypePrivateMessage 发送 B 站私信的规则类型标识
|
||||
RuleTypePrivateMessage = "bilibili-private-message"
|
||||
)
|
||||
|
||||
type BiliAccount struct {
|
||||
@@ -14,3 +16,10 @@ type BiliAccount struct {
|
||||
type BiliDynamicConfig struct {
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
// BiliPrivateMessageConfig 私信规则配置
|
||||
type BiliPrivateMessageConfig struct {
|
||||
// 接收者的 UID 列表
|
||||
ReceiverUids []int64 `json:"receiver_uids"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package bilibili
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/CuteReimu/bilibili/v2"
|
||||
"github.com/ssdomei232/goodBaby/internal/retry"
|
||||
"github.com/ssdomei232/goodBaby/model"
|
||||
)
|
||||
|
||||
// 私信消息类型:1 为文字
|
||||
const privateMsgTypeText = 1
|
||||
|
||||
// SendBiliPrivateMessage 向配置中的每个 UID 发送一条 B 站私信
|
||||
func SendBiliPrivateMessage(ctx context.Context, rule *model.Rule) error {
|
||||
client, err := getBiliClient(rule)
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取B站客户端失败: %w", err)
|
||||
}
|
||||
|
||||
config, err := getPrivateMessageConfig(rule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 发私信需要带上自己的 UID,从账号信息里取
|
||||
account, err := client.GetAccountInformation()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取B站账号信息失败(cookie 可能已失效): %w", err)
|
||||
}
|
||||
if account == nil || account.Mid == 0 {
|
||||
return fmt.Errorf("B站 cookie 无效或已过期")
|
||||
}
|
||||
|
||||
var fails []string
|
||||
for _, uid := range config.ReceiverUids {
|
||||
err := retry.Do(ctx, func() error {
|
||||
_, err := client.SendPrivateMessage(bilibili.SendPrivateMessageParam{
|
||||
SenderUid: account.Mid,
|
||||
ReceiverId: int(uid),
|
||||
ReceiverType: 1,
|
||||
MsgType: privateMsgTypeText,
|
||||
Timestamp: int(time.Now().Unix()),
|
||||
Content: buildTextContent(config.Msg),
|
||||
})
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
fails = append(fails, fmt.Sprintf("UID %d: %v", uid, err))
|
||||
}
|
||||
}
|
||||
|
||||
if len(fails) > 0 {
|
||||
return fmt.Errorf("%d/%d 条私信发送失败: %s",
|
||||
len(fails), len(config.ReceiverUids), strings.Join(fails, "; "))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// buildTextContent 文字私信的 content 是一个 JSON 字符串 {"content":"..."}
|
||||
func buildTextContent(msg string) string {
|
||||
payload, err := json.Marshal(map[string]string{"content": msg})
|
||||
if err != nil {
|
||||
// msg 是普通字符串,序列化不会失败;兜底也返回合法 JSON
|
||||
return `{"content":""}`
|
||||
}
|
||||
return string(payload)
|
||||
}
|
||||
|
||||
func getPrivateMessageConfig(rule *model.Rule) (*BiliPrivateMessageConfig, error) {
|
||||
var config BiliPrivateMessageConfig
|
||||
if err := json.Unmarshal([]byte(rule.ConfigJson), &config); err != nil {
|
||||
return nil, fmt.Errorf("解析B站私信规则配置失败: %w", err)
|
||||
}
|
||||
return &config, nil
|
||||
}
|
||||
@@ -31,6 +31,57 @@ func (v *BilibiliDynamicRuleValidator) Validate(configJSON string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BilibiliPrivateMessageRuleValidator B站私信规则验证器
|
||||
type BilibiliPrivateMessageRuleValidator struct{}
|
||||
|
||||
func (v *BilibiliPrivateMessageRuleValidator) GetType() string {
|
||||
return RuleTypePrivateMessage
|
||||
}
|
||||
|
||||
func (v *BilibiliPrivateMessageRuleValidator) Validate(configJSON string) error {
|
||||
var config BiliPrivateMessageConfig
|
||||
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
|
||||
return fmt.Errorf("解析B站私信规则配置失败: %v", err)
|
||||
}
|
||||
|
||||
if config.Msg == "" {
|
||||
return fmt.Errorf("B站私信规则配置中 msg 不能为空")
|
||||
}
|
||||
|
||||
if len(config.ReceiverUids) == 0 {
|
||||
return fmt.Errorf("B站私信规则配置中 receiver_uids 不能为空")
|
||||
}
|
||||
|
||||
for _, uid := range config.ReceiverUids {
|
||||
if uid <= 0 {
|
||||
return fmt.Errorf("B站私信规则配置中存在非法的 UID: %d", uid)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *BilibiliPrivateMessageRuleValidator) Meta() meta.RuleMeta {
|
||||
return meta.RuleMeta{
|
||||
Type: RuleTypePrivateMessage,
|
||||
Label: "发送 B 站私信",
|
||||
Description: "触发时以关联的 B 站账号向指定用户发送私信。对方需要能接收你的私信。",
|
||||
Docs: "docs/bilibili-config.md",
|
||||
AccountType: AccountType,
|
||||
Fields: []meta.Field{
|
||||
{
|
||||
Key: "receiver_uids",
|
||||
Label: "接收者 UID",
|
||||
Type: meta.FieldNumberList,
|
||||
Required: true,
|
||||
Placeholder: "2",
|
||||
Help: "对方空间地址 space.bilibili.com/ 后面的那串数字",
|
||||
},
|
||||
{Key: "msg", Label: "私信内容", Type: meta.FieldTextarea, Required: true},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (v *BilibiliDynamicRuleValidator) Meta() meta.RuleMeta {
|
||||
return meta.RuleMeta{
|
||||
Type: RuleTypeDynamic,
|
||||
|
||||
@@ -19,3 +19,16 @@ func (e *BilibiliDynamicExecutor) Execute(ctx context.Context, rule *model.Rule)
|
||||
|
||||
return SendBiliDynamicMsg(ctx, rule)
|
||||
}
|
||||
|
||||
// BilibiliPrivateMessageExecutor B站私信执行器
|
||||
type BilibiliPrivateMessageExecutor struct{}
|
||||
|
||||
func (e *BilibiliPrivateMessageExecutor) GetType() string {
|
||||
return RuleTypePrivateMessage
|
||||
}
|
||||
|
||||
func (e *BilibiliPrivateMessageExecutor) Execute(ctx context.Context, rule *model.Rule) error {
|
||||
log.Printf("执行B站私信规则: %s (ID: %d)", rule.Name, rule.ID)
|
||||
|
||||
return SendBiliPrivateMessage(ctx, rule)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user