Skip to content

Commit

Permalink
refactor: 优化代码结构和功能&&重构插件功能模块
Browse files Browse the repository at this point in the history
  • Loading branch information
Clov614 committed Jan 22, 2025
1 parent 6c878ae commit b2da394
Show file tree
Hide file tree
Showing 15 changed files with 368 additions and 572 deletions.
2 changes: 1 addition & 1 deletion rikkabot/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (a *Adapter) covert(msg *wcf.Message) *message.Message {
infos, err := msg.RoomData.GetMembersByNickName(match[1])
if err != nil {
logging.WarnWithErr(err, "RoomData.GetMembersByNickName fail")
} else {
} else if infos[0] != nil || infos[0].Wxid != "" {
AtWxidList[i] = infos[0].Wxid
}

Expand Down
67 changes: 65 additions & 2 deletions rikkabot/common/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package common

import (
"context"
"errors"
"github.com/Clov614/logging"
wcf "github.com/Clov614/wcf-rpc-sdk"
)

Expand All @@ -16,8 +18,9 @@ type Self struct {
var self *Self

var (
// ErrFriendNotFound = errors.New("friend not found")
// ErrGroupNotFound = errors.New("group not found")
// ErrFriendNotFound = errors.New("friend not found")
// ErrGroupNotFound = errors.New("group not found")
ErrNotFound = errors.New("not found")
)

func GetSelf() *Self {
Expand All @@ -32,6 +35,66 @@ func (s *Self) GetNickName() string {
return s.cli.GetSelfName()
}

func (s *Self) GetMemberByNickName(roomName string) {

}

func (s *Self) GetFriendIdByNickname(nickname string) (string, error) {
friendList, err := s.cli.GetAllFriend()
if err != nil {
logging.ErrorWithErr(err, "GetFriendList")
return "", ErrNotFound
}
for _, friend := range []*wcf.Friend(*friendList) {
if friend.Name == nickname {
return friend.Wxid, nil
}
}
return "", ErrNotFound
}

func (s *Self) GetFriendNicknameById(wxid string) (string, error) {
friendList, err := s.cli.GetAllFriend()
if err != nil {
logging.ErrorWithErr(err, "GetFriendList")
return "", ErrNotFound
}
for _, friend := range []*wcf.Friend(*friendList) {
if friend.Wxid == wxid {
return friend.Name, nil
}
}
return "", ErrNotFound
}

func (s *Self) GetGroupIdByNickname(nickname string) (string, error) {
roomList, err := s.cli.GetAllChatRoom()
if err != nil {
logging.ErrorWithErr(err, "GetFriendList")
return "", ErrNotFound
}
for _, room := range []*wcf.ChatRoom(*roomList) {
if room.Name == nickname {
return room.RoomID, nil
}
}
return "", ErrNotFound
}

func (s *Self) GetGroupNicknameById(roomId string) (string, error) {
roomList, err := s.cli.GetAllChatRoom()
if err != nil {
logging.ErrorWithErr(err, "GetFriendList")
return "", ErrNotFound
}
for _, room := range []*wcf.ChatRoom(*roomList) {
if room.RoomID == roomId {
return room.Name, nil
}
}
return "", ErrNotFound
}

func (s *Self) SendText(receiver string, content string, ats ...string) error {
return s.cli.SendText(receiver, content, ats...)
}
Loading

0 comments on commit b2da394

Please sign in to comment.