mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
Some checks failed
自动更新 nix 依赖 / gomod2nix update (push) Has been cancelled
打包最新版为 Docker Image / build docker (push) Has been cancelled
最新版 / Build binary CI (386, linux) (push) Has been cancelled
最新版 / Build binary CI (386, windows) (push) Has been cancelled
最新版 / Build binary CI (amd64, linux) (push) Has been cancelled
最新版 / Build binary CI (amd64, windows) (push) Has been cancelled
最新版 / Build binary CI (arm, linux) (push) Has been cancelled
最新版 / Build binary CI (arm64, linux) (push) Has been cancelled
PushLint / lint (push) Has been cancelled
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
// Package aiimage 提供AI画图功能配置
|
|
package aiimage
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"sync"
|
|
|
|
sql "github.com/FloatTech/sqlite"
|
|
)
|
|
|
|
// storage 管理画图配置存储
|
|
type storage struct {
|
|
sync.RWMutex
|
|
db sql.Sqlite
|
|
}
|
|
|
|
// imageConfig 存储AI画图配置信息
|
|
type imageConfig struct {
|
|
ID int64 `db:"id"` // 主键ID
|
|
APIKey string `db:"apiKey"` // API密钥
|
|
APIURL string `db:"apiUrl"` // API地址
|
|
ModelName string `db:"modelName"` // 画图模型名称
|
|
}
|
|
|
|
// getConfig 获取当前配置
|
|
func (sdb *storage) getConfig() imageConfig {
|
|
sdb.RLock()
|
|
defer sdb.RUnlock()
|
|
cfg := imageConfig{}
|
|
_ = sdb.db.Find("config", &cfg, "WHERE id = 1")
|
|
return cfg
|
|
}
|
|
|
|
// setConfig 设置AI画图配置
|
|
func (sdb *storage) setConfig(apiKey, apiURL, modelName string) error {
|
|
sdb.Lock()
|
|
defer sdb.Unlock()
|
|
return sdb.db.Insert("config", &imageConfig{
|
|
ID: 1,
|
|
APIKey: apiKey,
|
|
APIURL: apiURL,
|
|
ModelName: modelName,
|
|
})
|
|
}
|
|
|
|
// PrintConfig 返回格式化后的配置信息
|
|
func (sdb *storage) PrintConfig() string {
|
|
cfg := sdb.getConfig()
|
|
var builder strings.Builder
|
|
builder.WriteString("当前AI画图配置:\n")
|
|
builder.WriteString(fmt.Sprintf("• 密钥: %s\n", cfg.APIKey))
|
|
builder.WriteString(fmt.Sprintf("• 接口地址: %s\n", cfg.APIURL))
|
|
builder.WriteString(fmt.Sprintf("• 模型名: %s\n", cfg.ModelName))
|
|
return builder.String()
|
|
}
|