Skip to content

Commit

Permalink
Beta51 (#161)
Browse files Browse the repository at this point in the history
* bugfix

* add a lot

* add a lot

* add webui sysinfo

* add webui sysinfo

* beta51
  • Loading branch information
Hoshinonyaruko authored Nov 22, 2023
1 parent f874228 commit 5c3a1a1
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 302 deletions.
14 changes: 14 additions & 0 deletions botgo/dto/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ type Message struct {
SrcGuildID string `json:"src_guild_id"`
}

type MediaResponse struct {
//UUID
FileUUID string `json:"file_uuid"`
//file_info
FileInfo string `json:"file_info"`
TTL int `json:"ttl"`
}

//新增
type GroupMessageResponse struct {
MediaResponse *MediaResponse
Message *Message
}

// Embed 结构
type Embed struct {
Title string `json:"title,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions botgo/dto/message_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ type RichMediaMessage struct {
Content string `json:"content,omitempty"`
}

// Meida message内的富媒体消息
type Media struct {
FileInfo string `json:"file_info"`
}

// GetEventID 事件ID
func (msg RichMediaMessage) GetEventID() string {
return msg.EventID
Expand All @@ -42,6 +47,7 @@ type MessageToCreate struct {
Embed *Embed `json:"embed,omitempty"`
Ark *Ark `json:"ark,omitempty"`
Image string `json:"image,omitempty"`
Media Media `json:"media,omitempty"`
// 要回复的消息id,为空是主动消息,公域机器人会异步审核,不为空是被动消息,公域机器人会校验语料
MsgID string `json:"msg_id,omitempty"`
MessageReference *MessageReference `json:"message_reference,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion botgo/openapi/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type MessageAPI interface {
PostSettingGuide(ctx context.Context, channelID string, atUserIDs []string) (*dto.Message, error)

// PostGroupMessage 发送群消息
PostGroupMessage(ctx context.Context, groupID string, msg dto.APIMessage) (*dto.Message, error)
PostGroupMessage(ctx context.Context, groupID string, msg dto.APIMessage) (*dto.GroupMessageResponse, error)
// PostC2CMessage 发送C2C消息
PostC2CMessage(ctx context.Context, userID string, msg dto.APIMessage) (*dto.Message, error)
}
Expand Down
12 changes: 10 additions & 2 deletions botgo/openapi/v1/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func getGroupURLBySendType(msgType dto.SendType) uri {
}

// PostGroupMessage 回复群消息
func (o *openAPI) PostGroupMessage(ctx context.Context, groupID string, msg dto.APIMessage) (*dto.Message, error) {
func (o *openAPI) PostGroupMessage(ctx context.Context, groupID string, msg dto.APIMessage) (*dto.GroupMessageResponse, error) {
resp, err := o.request(ctx).
SetResult(dto.Message{}).
SetPathParam("group_id", groupID).
Expand All @@ -200,7 +200,15 @@ func (o *openAPI) PostGroupMessage(ctx context.Context, groupID string, msg dto.
if err != nil {
return nil, err
}
return resp.Result().(*dto.Message), nil
msgType := msg.GetSendType()
result := &dto.GroupMessageResponse{}
switch msgType {
case dto.RichMedia:
result.MediaResponse = resp.Result().(*dto.MediaResponse)
default:
result.Message = resp.Result().(*dto.Message)
}
return result, nil
}

func getC2CURLBySendType(msgType dto.SendType) uri {
Expand Down
38 changes: 31 additions & 7 deletions botgo/openapi/v2/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strconv"

"github.com/go-resty/resty/v2"
"github.com/tidwall/gjson"

"github.com/tencent-connect/botgo/dto"
Expand Down Expand Up @@ -191,16 +192,39 @@ func getGroupURLBySendType(msgType dto.SendType) uri {
}

// PostGroupMessage 回复群消息
func (o *openAPIv2) PostGroupMessage(ctx context.Context, groupID string, msg dto.APIMessage) (*dto.Message, error) {
resp, err := o.request(ctx).
SetResult(dto.Message{}).
SetPathParam("group_id", groupID).
SetBody(msg).
Post(o.getURL(getGroupURLBySendType(msg.GetSendType())))
func (o *openAPIv2) PostGroupMessage(ctx context.Context, groupID string, msg dto.APIMessage) (*dto.GroupMessageResponse, error) {
var resp *resty.Response
var err error

msgType := msg.GetSendType()
switch msgType {
case dto.RichMedia:
resp, err = o.request(ctx).
SetResult(dto.MediaResponse{}). // 设置为媒体响应类型
SetPathParam("group_id", groupID).
SetBody(msg).
Post(o.getURL(getGroupURLBySendType(msgType)))
default:
resp, err = o.request(ctx).
SetResult(dto.Message{}). // 设置为消息类型
SetPathParam("group_id", groupID).
SetBody(msg).
Post(o.getURL(getGroupURLBySendType(msgType)))
}

if err != nil {
return nil, err
}
return resp.Result().(*dto.Message), nil

result := &dto.GroupMessageResponse{}
switch msgType {
case dto.RichMedia:
result.MediaResponse = resp.Result().(*dto.MediaResponse)
default:
result.Message = resp.Result().(*dto.Message)
}

return result, nil
}

func getC2CURLBySendType(msgType dto.SendType) uri {
Expand Down
13 changes: 0 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ type Settings struct {
NoWhiteResponse string `yaml:"No_White_Response"`
SendError bool `yaml:"send_error"`
AddAtGroup bool `yaml:"add_at_group"`
SendErrorPicAsUrl bool `yaml:"send_error_pic_as_url"`
UrlPicTransfer bool `yaml:"url_pic_transfer"`
}

Expand Down Expand Up @@ -940,18 +939,6 @@ func GetAddAtGroup() bool {
return instance.Settings.AddAtGroup
}

// 获取GetSendErrorPicAsUrl的值
func GetSendErrorPicAsUrl() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to GetErrorPicAsUrl value.")
return true
}
return instance.Settings.SendErrorPicAsUrl
}

// 获取GetUrlPicTransfer的值
func GetUrlPicTransfer() bool {
mu.Lock()
Expand Down
Loading

0 comments on commit 5c3a1a1

Please sign in to comment.