Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions abineundo/console_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func setConsoleTitle(title string) (err error) {
if err != nil {
return
}
r1, _, e1 := syscall.Syscall(procSetConsoleTitle.Addr(), 1, uintptr(unsafe.Pointer(p0)), 0, 0)
r1, _, e1 := syscall.SyscallN(procSetConsoleTitle.Addr(), uintptr(unsafe.Pointer(p0)))
if r1 == 0 {
err = errnoErr(e1)
}
Expand All @@ -46,9 +46,8 @@ func init() {
if debugMode {
logrus.Warnf("调试模式下忽略控制台模式获取失败: %v", err)
return // 调试模式下直接返回,跳过后续配置
} else {
panic(err) // 非调试模式下 panic
}
panic(err) // 非调试模式下 panic
}

mode &^= windows.ENABLE_QUICK_EDIT_MODE // 禁用快速编辑模式
Expand Down
63 changes: 60 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"math/rand"
"os"
"runtime"
Expand Down Expand Up @@ -43,7 +44,8 @@ import (

_ "github.com/FloatTech/ZeroBot-Plugin/plugin/atri" // ATRI词库

_ "github.com/FloatTech/ZeroBot-Plugin/plugin/manager" // 群管
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/manager" // 群管
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/servicemenu" // 服务菜单(列表/用法/主题/重载)

_ "github.com/FloatTech/zbputils/job" // 定时指令触发器

Expand Down Expand Up @@ -236,9 +238,9 @@ func init() {
// 直接写死 AccessToken 时,请更改下面第二个参数
token := flag.String("t", "", "Set AccessToken of WSClient.")
// 直接写死 URL 时,请更改下面第二个参数
url := flag.String("u", "ws://127.0.0.1:6700", "Set Url of WSClient.")
url := flag.String("u", "ws://192.168.1.244:6700", "Set Url of WSClient.")
// 默认昵称
adana := flag.String("n", "椛椛", "Set default nickname.")
adana := flag.String("n", "亚托莉", "Set default nickname.")
prefix := flag.String("p", "/", "Set command prefix.")
runcfg := flag.String("c", "", "Run from config file.")
save := flag.String("s", "", "Save default config to file and exit.")
Expand Down Expand Up @@ -275,6 +277,22 @@ func init() {
// sus = append(sus, 12345678)
// sus = append(sus, 87654321)

// 从 data/superusers.txt 读取超级用户 QQ,每行一个,支持 # 注释
if f, err := os.Open("data/superusers.txt"); err == nil {
data, err := io.ReadAll(f)
f.Close()
if err == nil {
for _, line := range strings.Split(string(data), "\n") {
line = strings.TrimSpace(strings.TrimPrefix(line, "#"))
if i, err := strconv.ParseInt(line, 10, 64); err == nil {
sus = append(sus, i)
}
}
}
} else {
logrus.Infoln("[main] 未找到 data/superusers.txt, 请创建并写入你的QQ号以启用管理命令")
}

// 启用 webui
// go webctrl.RunGui(*g)

Expand Down Expand Up @@ -332,6 +350,45 @@ func main() {
rand.Seed(time.Now().UnixNano()) //nolint: staticcheck
}
message.SetForceBase64File(config.ForceBase64File)

// 跳过 github 原始资源站, 直接用镜像, 避免启动时每个文件等 1 分钟超时
file.SkipOriginal = true

// 修复 ZeroBot CommandRule 在 @机器人 + 命令 场景下的匹配 bug:
// CommandRule 只检查 Message[0].Type == "text",
// 但 @机器人 时 Message[0] 是 "at" 段,Message[1] 才是 text,
// 导致所有 /全局沉默 /启用 等命令永远匹配不上。
// 在 FirstPriority(0) 把 text 段提到最前面,让 CommandRule 正常工作。
zero.OnMessage(func(ctx *zero.Ctx) bool {
if len(ctx.Event.Message) < 2 {
return false
}
if ctx.Event.Message[0].Type == "text" {
return false
}
textIdx := -1
for i, seg := range ctx.Event.Message {
if seg.Type == "text" {
textIdx = i
break
}
}
if textIdx <= 0 {
return false
}
text := strings.TrimLeft(ctx.Event.Message[textIdx].Data["text"], " ")
if !strings.HasPrefix(text, zero.BotConfig.CommandPrefix) {
return false
}
// 把第一个 text 段移到最前面
segs := make(message.Message, 0, len(ctx.Event.Message))
segs = append(segs, ctx.Event.Message[textIdx])
segs = append(segs, ctx.Event.Message[:textIdx]...)
segs = append(segs, ctx.Event.Message[textIdx+1:]...)
ctx.Event.Message = segs
return false // 不拦截,让后续 matcher 继续匹配
}).FirstPriority().Handle(func(_ *zero.Ctx) {})

// 帮助
zero.OnFullMatchGroup([]string{"help", "/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
Expand Down
9 changes: 6 additions & 3 deletions plugin/aichat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ var (
)

func init() {
en.OnMessage(chat.EnsureConfig, func(ctx *zero.Ctx) bool {
// 优先级设为 10,低于控制命令(SecondPriority=1),
// 避免 /全局禁用、/启用 等管理命令被 AI 聊天抢先拦截
aim := en.OnMessage(chat.EnsureConfig, func(ctx *zero.Ctx) bool {
stor, ok := ctx.State[zero.StateKeyPrefixKeep+"aichatcfg_stor__"].(chat.Storage)
if !ok {
logrus.Warnln("ERROR: cannot get stor")
return false
}
mp := ctx.State[control.StateKeySyncxState].(*syncx.Map[string, any])
Expand All @@ -70,7 +71,9 @@ func init() {
ctx.Block()
}
return true
}).SetBlock(false).Handle(func(ctx *zero.Ctx) {
}).SetBlock(false)
(*zero.Matcher)(aim).SetPriority(10)
aim.Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
if gid == 0 {
gid = -ctx.Event.UserID
Expand Down
76 changes: 76 additions & 0 deletions plugin/aifalse/hardware_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//go:build !windows

package aifalse

import (
"context"
"os/exec"
"regexp"
"strings"
"time"

"github.com/sirupsen/logrus"
)

func init() {
wmiGPUInfo = func() []gpuInfo {
// Linux/macOS: 用 lspci 列出 VGA/3D 设备
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

out, err := exec.CommandContext(ctx, "lspci").CombinedOutput()
if err != nil {
logrus.Debugf("[aifalse] lspci 失败: %v", err)
return nil
}

vgaRe := regexp.MustCompile(`VGA compatible controller:\s*(.*)`)
displayRe := regexp.MustCompile(`Display controller:\s*(.*)`)

var result []gpuInfo
for _, line := range strings.Split(string(out), "\n") {
var name string
if m := vgaRe.FindStringSubmatch(line); len(m) > 1 {
name = m[1]
} else if m := displayRe.FindStringSubmatch(line); len(m) > 1 {
name = m[1]
}
if name == "" {
continue
}
name = strings.TrimSpace(name)
result = append(result, gpuInfo{
Name: name,
Vendor: detectVendor(name),
})
}
if len(result) > 0 {
logrus.Debugf("[aifalse] lspci 识别到 %d 个 GPU", len(result))
}
return result
}
}

// queryHWiNFO 非 Windows 平台无 HWiNFO。
func queryHWiNFO() (temps, fans, powers []*status) { return nil, nil, nil }

// lhmSensor 非 Windows 平台不采集(LibreHardwareMonitor 仅支持 Windows),
// 但字段需与 hardware_windows.go 保持一致,供跨平台代码(tempstate)编译通过。
type lhmSensor struct {
Name string
SensorType string // Temperature / Fan / Power / Load / Clock / Voltage / Control
Parent string
Value float64
}

// queryLibreHardwareMonitor 非 Windows 平台永远返回 nil。
func queryLibreHardwareMonitor() []lhmSensor { return nil }

// queryLibreHardwareMonitorHTTP 非 Windows 平台永远返回 nil。
func queryLibreHardwareMonitorHTTP() []lhmSensor { return nil }

// mergeLHMSensors 非 Windows 平台占位。
func mergeLHMSensors(_, _ []lhmSensor) []lhmSensor { return nil }

// lhmSensorDisplayName 非 Windows 平台占位。
func lhmSensorDisplayName(_ lhmSensor) string { return "" }
Loading
Loading