修改接口

This commit is contained in:
wh_zcy 2022-12-12 11:20:37 +08:00
parent 60d10b3a11
commit 7784cf176a
10 changed files with 77 additions and 31 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.log

30
busi/friend.go Normal file
View File

@ -0,0 +1,30 @@
package busi
import (
"legu.airobot/lib"
"legu.airobot/pb"
)
//好友场景
var _ lib.IScene = (*FriendScene)(nil)
type FriendScene struct {
lib.Action
}
func (f *FriendScene) Info() lib.SceneInfo {
return lib.SceneInfo{
Name: "好友申请",
Desc: "aaa",
}
}
func (f *FriendScene) Run(robot lib.IRobot) error {
head := &pb.UserMessage{MainType: "", SubType: ""}
req := &pb.FriendRandlistReq{}
rsp := &pb.FriendRandlistResp{}
robot.SendMsg(head, req, rsp)
return nil
}

View File

@ -14,9 +14,9 @@ type FriendApply struct {
lib.Action
}
func (a *FriendApply) ShowInfo() lib.CallerInfo {
return lib.CallerInfo{
Key: "friend.apply",
func (a *FriendApply) Info() lib.SceneInfo {
return lib.SceneInfo{
Name: "friend.apply",
Desc: "好友申请",
}
}
@ -26,6 +26,7 @@ func (a *FriendApply) BuildReq(store lib.IStore, head *pb.UserMessage) lib.RawRe
var req []byte
b := store.Get("friend.apply")
rsp := &pb.FriendRandlistResp{}
if err := proto.Unmarshal(b, rsp); err != nil {
panic(err)

View File

@ -15,9 +15,9 @@ type FriendRecommend struct {
lib.Action
}
func (a *FriendRecommend) ShowInfo() lib.CallerInfo {
return lib.CallerInfo{
Key: "friend.randlist",
func (a *FriendRecommend) Info() lib.SceneInfo {
return lib.SceneInfo{
Name: "friend.randlist",
Desc: "好友推荐",
}
}

View File

@ -1,12 +1,12 @@
package lib
type IAction interface {
ShowInfo() CallerInfo
Info() SceneInfo
}
type Action struct {
// scene *scene
Key string
Name string
Desc string
}

View File

@ -14,8 +14,8 @@ type RawResp struct {
Elapse time.Duration
}
type CallerInfo struct {
Key string
type SceneInfo struct {
Name string
Desc string
}

View File

@ -16,11 +16,20 @@ import (
type IRobot interface {
// 启动机器人
Start() bool
// Start() bool
// 选择场景
SelScene(scene *scene)
// SelScene(scene *scene)
// 当前场景
GetCurrentScene() *scene
// GetCurrentScene() *scene
// 发送消息
SendMsg(head *pb.UserMessage, req proto.Message, rsp proto.Message) error
// 存储数据
Store(key string, data []byte)
// 获取数据
Get(key string) []byte
// 停止运行
Stop() bool
}
type Robot struct {

View File

@ -1,15 +1,22 @@
package lib
import "sync"
import (
"sync"
)
type IScene interface {
Run(robot IRobot) error
Info() SceneInfo
}
type scene struct {
ai *myAI
Name string
Desc string
callerQueue *Queue[ICaller] //确定运行的caller队列
status uint32 //场景状态
lock sync.Mutex
callerQueue *Queue[ICaller] //确定运行的caller队列
status uint32 //场景状态
lock sync.Mutex
}
// 创建场景
@ -19,7 +26,6 @@ func NewScene(ai *myAI, param SceneParam) *scene {
Name: param.Name,
Desc: param.Desc,
callerQueue: NewQueue[ICaller](),
}
ai.scenes = append(ai.scenes, s)
@ -50,7 +56,7 @@ func (s *scene) Enable(name string) {
for _, v := range s.ai.scenes {
if v.Name == name {
v.status = STATUS_ENABLE
}else{
} else {
v.status = STATUS_DISENABLE
}
}

View File

@ -1 +0,0 @@
{"level":"debug","msg":"配置","time":"2022-12-12 00:39:12","场景":[{"id":"551993000","name":"场景1","desc":"2132","callers":[{"id":"551993000_1670771588149928000","name":"232","key":"1"},{"id":"551993000_1670776426358376000","name":"好友推荐","key":"friend.randlist"}],"status":1},{"id":"376159000","name":"场景2"},{"id":"42611000","name":"场景3"}]}

View File

@ -216,9 +216,9 @@ func (mw *MainWindow) sceneContainer() {
sceneItemList.Reset()
logrus.WithField("场景", mw.config.Scenes).Debug("配置")
for _, v := range mw.config.Scenes {
txt := fmt.Sprintf("%v", v.Name)
txt := fmt.Sprintf("%v %s", v.Name, v.Desc)
if v.Status == lib.STATUS_ENABLE {
txt = fmt.Sprintf("%s *", v.Name)
txt = fmt.Sprintf("* %s %s", v.Name, v.Desc)
}
item := lib.Item{
Id: cast.ToString(v.ID),
@ -434,7 +434,7 @@ func (mw *MainWindow) sceneContainer() {
ShowTip(fmt.Sprintf("错误:%v", err.Error()))
return
}
sceneItemList.Reset()
contentRender()
}
//添加用例事件
@ -474,21 +474,21 @@ func (mw *MainWindow) sceneContainer() {
registerCallerList := *lib.NewItemList()
registerCallerList.OnSelFunc = func(id widget.ListItemID) {
data := registerCallerList.CachedList.Items[id].Data
info, ok := data.(lib.CallerInfo)
info, ok := data.(lib.SceneInfo)
if !ok {
return
}
callerNameEntry.Text = info.Desc
callerKeyEntry.Text = info.Key
callerKeyEntry.Text = info.Name
callerForm.Refresh()
}
registerCallerList.ListWidget = registerCallerList.CreateList()
registerCallerReload := func() {
for _, v := range mw.UIImpl.callers {
info := v.ShowInfo()
info := v.Info()
item := lib.Item{
Id: info.Key,
Text: fmt.Sprintf("%s (%s)", info.Desc, info.Key),
Id: info.Name,
Text: fmt.Sprintf("%s (%s)", info.Desc, info.Name),
Data: info,
}
registerCallerList.AddItem(item)
@ -589,7 +589,7 @@ func (mw *MainWindow) ExportConfigWindow() {
return
}
}, mw.w)
exportWin.Resize(fyne.NewSize(300, 80))
exportWin.Resize(fyne.NewSize(500, 80))
exportWin.Show()
}
@ -622,7 +622,7 @@ func (mw *MainWindow) ImportConfigWindow() {
return
}
}, mw.w)
importWin.Resize(fyne.NewSize(300, 80))
importWin.Resize(fyne.NewSize(500, 80))
importWin.Show()
}