chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package qqbot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"academy/internal/im"
|
||||
"academy/internal/logger"
|
||||
)
|
||||
|
||||
func NewFactory() im.AdapterFactory {
|
||||
return func(factoryCtx context.Context, channel *im.IMChannel, msgHandler func(context.Context, *im.IncomingMessage) error) (im.Adapter, context.CancelFunc, error) {
|
||||
creds, err := im.ParseCredentials(channel.Credentials)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("parse qqbot credentials: %w", err)
|
||||
}
|
||||
|
||||
mode := im.ResolveMode(channel, "websocket")
|
||||
if mode != "websocket" {
|
||||
return nil, nil, fmt.Errorf("unsupported qqbot mode: %s (only websocket is supported)", mode)
|
||||
}
|
||||
|
||||
client, err := NewClient(
|
||||
im.GetString(creds, "app_id"),
|
||||
im.GetString(creds, "client_secret"),
|
||||
im.GetString(creds, "api_base_url"),
|
||||
im.GetString(creds, "gateway_url"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
longConn := NewLongConnClient(client, msgHandler)
|
||||
wsCtx, wsCancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
if err := longConn.Start(wsCtx); err != nil && wsCtx.Err() == nil {
|
||||
logger.Errorf(context.Background(), "[IM] QQBot long connection stopped for channel %s: %v", channel.ID, err)
|
||||
}
|
||||
}()
|
||||
|
||||
adapter := NewAdapter(client)
|
||||
return adapter, func() {
|
||||
wsCancel()
|
||||
longConn.Stop()
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user