Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta363 #375

Merged
merged 27 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/cross_compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,24 @@ jobs:
CGO_ENABLED: 0
run: |
if [ "$GOOS" = "windows" ]; then
go build -o output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}.exe
go build -ldflags="-s -w" -o output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}.exe
else
go build -o output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}
go build -ldflags="-s -w" -o output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}
fi

- name: Compress executable files with UPX (except for gensokyo-android-arm64)
run: |
sudo apt-get update
sudo apt-get install -y upx
if [[ "${{ matrix.os }}" == *"windows"* ]]; then
FILENAME="output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}.exe"
else
FILENAME="output/gensokyo-${{ matrix.os }}-${{ matrix.goarch }}"
fi
if [[ "${{ matrix.os }}" == "android" && "${{ matrix.goarch }}" == "arm64" ]]; then
echo "Skipping UPX compression for $FILENAME"
else
upx --best --lzma "$FILENAME"
fi

- name: Upload artifacts
Expand Down
3 changes: 3 additions & 0 deletions Processor/ProcessGroupDelBot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package Processor

import (
"fmt"
"strconv"

"github.com/hoshinonyaruko/gensokyo/config"
Expand Down Expand Up @@ -50,6 +51,8 @@ func (p *Processors) ProcessGroupDelBot(data *dto.GroupAddBotEvent) error {
return nil
}
mylog.Printf("Bot被[%v]从群[%v]移出", userid64, GroupID64)
//从数据库删除群数据(仅删除类型缓存,再次加入会刷新)
idmap.DeleteConfigv2(fmt.Sprint(GroupID64), "type")
Notice = GroupNoticeEvent{
GroupID: GroupID64,
NoticeType: "group_decrease",
Expand Down
10 changes: 4 additions & 6 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
// 映射str的GroupID到int
GroupID64, err = idmap.StoreIDv2(data.GroupID)
if err != nil {
mylog.Errorf("failed to convert ChannelID to int: %v", err)
mylog.Errorf("failed to convert GroupID64 to int: %v", err)
return nil
}
// 映射str的userid到int
Expand Down Expand Up @@ -122,11 +122,9 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
groupMsg.RealMessageType = "group"
groupMsg.IsBindedUserId = IsBindedUserId
groupMsg.IsBindedGroupId = IsBindedGroupId
if IsBindedUserId {
groupMsg.Avatar, _ = GenerateAvatarURL(userid64)
} else {
groupMsg.Avatar, _ = GenerateAvatarURLV2(data.Author.ID)
}
groupMsg.RealGroupID = data.GroupID
groupMsg.RealUserID = data.Author.ID
groupMsg.Avatar, _ = GenerateAvatarURLV2(data.Author.ID)
}
//根据条件判断是否增加nick和card
var CaN = config.GetCardAndNick()
Expand Down
24 changes: 14 additions & 10 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type OnebotGroupMessage struct {
Font int `json:"font"`
UserID int64 `json:"user_id"`
RealMessageType string `json:"real_message_type,omitempty"` //当前信息的真实类型 group group_private guild guild_private
RealUserID string `json:"real_user_id,omitempty"` //当前真实uid
RealGroupID string `json:"real_group_id,omitempty"` //当前真实gid
IsBindedGroupId bool `json:"is_binded_group_id,omitempty"` //当前群号是否是binded后的
IsBindedUserId bool `json:"is_binded_user_id,omitempty"` //当前用户号号是否是binded后的
}
Expand Down Expand Up @@ -344,22 +346,24 @@ func (p *Processors) HandleFrameworkCommand(messageText string, data interface{}

// 获取MasterID数组
masterIDs := config.GetMasterID()
// 根据realid获取new(用户id)
now, new, err = idmap.RetrieveVirtualValuev2(realid)
if err != nil {
mylog.Printf("根据realid获取new(用户id) 错误:%v", err)
}
// 根据realid获取new(群id)
nowgroup, newgroup, err = idmap.RetrieveVirtualValuev2(realid2)
if err != nil {
mylog.Printf("根据realid获取new(群id)错误:%v", err)
}

// idmaps-pro获取群和用户id
if config.GetIdmapPro() {
newpro1, newpro2, err = idmap.RetrieveVirtualValuev2Pro(realid2, realid)
if err != nil {
mylog.Printf("idmaps-pro获取群和用户id 错误:%v", err)
}
} else {
// 根据realid获取new(用户id)
now, new, err = idmap.RetrieveVirtualValuev2(realid)
if err != nil {
mylog.Printf("根据realid获取new(用户id) 错误:%v", err)
}
// 根据realid获取new(群id)
nowgroup, newgroup, err = idmap.RetrieveVirtualValuev2(realid2)
if err != nil {
mylog.Printf("根据realid获取new(群id)错误:%v", err)
}
}
// 检查真实值或虚拟值是否在数组中
var realValueIncluded, virtualValueIncluded bool
Expand Down
68 changes: 68 additions & 0 deletions botgo/dto/message_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type RichMediaMessage struct {
EventID string `json:"event_id,omitempty"` // 要回复的事件id, 逻辑同MsgID
FileType uint64 `json:"file_type,omitempty"` // 业务类型,图片,文件,语音,视频 文件类型,取值:1图片,2视频,3语音(目前语音只支持silk格式)
URL string `json:"url,omitempty"`
FileData string `json:"file_data,omitempty"` //没有base64头的base64
SrvSendMsg bool `json:"srv_send_msg,omitempty"`
Content string `json:"content,omitempty"`
}
Expand Down Expand Up @@ -116,3 +117,70 @@ type SettingGuide struct {
// 频道ID, 当通过私信发送设置引导消息时,需要指定guild_id
GuildID string `json:"guild_id"`
}

// 仅供测试

type MessageSSE struct {
MsgType int `json:"msg_type,omitempty"`
Markdown *MarkdownSSE `json:"markdown,omitempty"`
MsgID string `json:"msg_id,omitempty"`
MsgSeq int `json:"msg_seq,omitempty"`
Stream *StreamSSE `json:"stream,omitempty"`
PromptKeyboard *KeyboardSSE `json:"prompt_keyboard,omitempty"`
ActionButton *ActionButtonSSE `json:"action_button,omitempty"`
}

// GetEventID 事件ID
func (msg MessageSSE) GetEventID() string {
return ""
}

// GetSendType 消息类型
func (msg MessageSSE) GetSendType() SendType {
return 1
}

type MarkdownSSE struct {
Content string `json:"content"`
}

type StreamSSE struct {
State int `json:"state"`
Index int `json:"index"`
ID string `json:"id,omitempty"`
}

type KeyboardSSE struct {
KeyboardContentSSE `json:"keyboard"`
}

type KeyboardContentSSE struct {
Content ContentSSE `json:"content"`
}

type ContentSSE struct {
Rows []RowSSE `json:"rows"`
}

type RowSSE struct {
Buttons []ButtonSSE `json:"buttons"`
}

type ButtonSSE struct {
RenderData RenderDataSSE `json:"render_data"`
Action ActionSSE `json:"action"`
}

type RenderDataSSE struct {
Label string `json:"label"`
Style int `json:"style"`
}

type ActionSSE struct {
Type int `json:"type"`
}

type ActionButtonSSE struct {
TemplateID int `json:"template_id"`
CallbackData string `json:"callback_data"`
}
4 changes: 4 additions & 0 deletions botgo/openapi/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ type MessageAPI interface {
PatchMessage(ctx context.Context,
channelID string, messageID string, msg *dto.MessageToCreate) (*dto.Message, error)
RetractMessage(ctx context.Context, channelID, msgID string, options ...RetractMessageOption) error
RetractGroupMessage(ctx context.Context, groupID, msgID string, options ...RetractMessageOption) error
RetractC2CMessage(ctx context.Context, userID, msgID string, options ...RetractMessageOption) error
// PostSettingGuide 发送设置引导
PostSettingGuide(ctx context.Context, channelID string, atUserIDs []string) (*dto.Message, error)

// PostGroupMessage 发送群消息
PostGroupMessage(ctx context.Context, groupID string, msg dto.APIMessage) (*dto.GroupMessageResponse, error)
// PostC2CMessage 发送C2C消息
PostC2CMessage(ctx context.Context, userID string, msg dto.APIMessage) (*dto.C2CMessageResponse, error)
// PostC2CMessage 发送C2CSSE消息
PostC2CMessageSSE(ctx context.Context, userID string, msg dto.APIMessage) (*dto.C2CMessageResponse, error)
}

// GuildAPI guild 相关接口
Expand Down
51 changes: 51 additions & 0 deletions botgo/openapi/v1/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,36 @@ func (o *openAPI) RetractMessage(ctx context.Context,
return err
}

// RetractMessage 撤回群消息
func (o *openAPI) RetractGroupMessage(ctx context.Context,
groupID, msgID string, options ...openapi.RetractMessageOption) error {
request := o.request(ctx).
SetPathParam("group_id", groupID).
SetPathParam("message_id", string(msgID))
for _, option := range options {
if option == openapi.RetractMessageOptionHidetip {
request = request.SetQueryParam("hidetip", "true")
}
}
_, err := request.Delete(o.getURL(groupMessagesURL))
return err
}

// RetractMessage 撤回私聊消息
func (o *openAPI) RetractC2CMessage(ctx context.Context,
UserID, msgID string, options ...openapi.RetractMessageOption) error {
request := o.request(ctx).
SetPathParam("user_id", UserID).
SetPathParam("message_id", string(msgID))
for _, option := range options {
if option == openapi.RetractMessageOptionHidetip {
request = request.SetQueryParam("hidetip", "true")
}
}
_, err := request.Delete(o.getURL(c2cMessageURI))
return err
}

// PostSettingGuide 发送设置引导消息, atUserID为要at的用户
func (o *openAPI) PostSettingGuide(ctx context.Context,
channelID string, atUserIDs []string) (*dto.Message, error) {
Expand Down Expand Up @@ -270,3 +300,24 @@ func (o *openAPI) PostC2CMessage(ctx context.Context, userID string, msg dto.API

return result, nil
}

// PostC2CMessage 回复C2CSSE消息
func (o *openAPI) PostC2CMessageSSE(ctx context.Context, userID string, msg dto.APIMessage) (*dto.C2CMessageResponse, error) {
var resp *resty.Response
var err error

resp, err = o.request(ctx).
SetResult(dto.Message{}). // 设置为消息类型
SetPathParam("user_id", userID).
SetBody(msg).
Post(o.getURL("/v2/users/{user_id}/messages"))

if err != nil {
return nil, err
}

result := &dto.C2CMessageResponse{}
result.Message = resp.Result().(*dto.Message)

return result, nil
}
4 changes: 3 additions & 1 deletion botgo/openapi/v1/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const (
c2cMessagesURI uri = "/v2/users/{user_id}/messages"
c2cRichMediaURI uri = "/v2/users/{user_id}/files"

messageURI uri = "/channels/{channel_id}/messages/{message_id}"
messageURI uri = "/channels/{channel_id}/messages/{message_id}"
groupMessagesURL uri = "/v2/groups/{group_id}/messages/{message_id}"

userMeURI uri = "/users/@me"
userMeGuildsURI uri = "/users/@me/guilds"
Expand All @@ -53,6 +54,7 @@ const (

dmsURI uri = "/dms/{guild_id}/messages"
dmsMessageURI uri = "/dms/{guild_id}/messages/{message_id}"
c2cMessageURI uri = "/v2/users/{user_id}/messages/{message_id}"

channelAnnouncesURI = "/channels/{channel_id}/announces"
channelAnnounceURI = "/channels/{channel_id}/announces/{message_id}"
Expand Down
51 changes: 51 additions & 0 deletions botgo/openapi/v2/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,36 @@ func (o *openAPIv2) RetractMessage(ctx context.Context,
return err
}

// RetractMessage 撤回群消息
func (o *openAPIv2) RetractGroupMessage(ctx context.Context,
groupID, msgID string, options ...openapi.RetractMessageOption) error {
request := o.request(ctx).
SetPathParam("group_id", groupID).
SetPathParam("message_id", string(msgID))
for _, option := range options {
if option == openapi.RetractMessageOptionHidetip {
request = request.SetQueryParam("hidetip", "true")
}
}
_, err := request.Delete(o.getURL(groupMessagesURL))
return err
}

// RetractMessage 撤回私聊消息
func (o *openAPIv2) RetractC2CMessage(ctx context.Context,
UserID, msgID string, options ...openapi.RetractMessageOption) error {
request := o.request(ctx).
SetPathParam("user_id", UserID).
SetPathParam("message_id", string(msgID))
for _, option := range options {
if option == openapi.RetractMessageOptionHidetip {
request = request.SetQueryParam("hidetip", "true")
}
}
_, err := request.Delete(o.getURL(c2cMessageURI))
return err
}

// PostSettingGuide 发送设置引导消息, atUserID为要at的用户
func (o *openAPIv2) PostSettingGuide(ctx context.Context,
channelID string, atUserIDs []string) (*dto.Message, error) {
Expand Down Expand Up @@ -285,3 +315,24 @@ func (o *openAPIv2) PostC2CMessage(ctx context.Context, userID string, msg dto.A

return result, nil
}

// PostC2CMessage 回复C2CSSE消息
func (o *openAPIv2) PostC2CMessageSSE(ctx context.Context, userID string, msg dto.APIMessage) (*dto.C2CMessageResponse, error) {
var resp *resty.Response
var err error

resp, err = o.request(ctx).
SetResult(dto.Message{}). // 设置为消息类型
SetPathParam("user_id", userID).
SetBody(msg).
Post(o.getURL("/v2/users/{user_id}/messages"))

if err != nil {
return nil, err
}

result := &dto.C2CMessageResponse{}
result.Message = resp.Result().(*dto.Message)

return result, nil
}
4 changes: 3 additions & 1 deletion botgo/openapi/v2/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const (
c2cMessagesURI uri = "/v2/users/{user_id}/messages"
c2cRichMediaURI uri = "/v2/users/{user_id}/files"

messageURI uri = "/channels/{channel_id}/messages/{message_id}"
messageURI uri = "/channels/{channel_id}/messages/{message_id}"
groupMessagesURL uri = "/v2/groups/{group_id}/messages/{message_id}"

userMeURI uri = "/users/@me"
userMeGuildsURI uri = "/users/@me/guilds"
Expand All @@ -53,6 +54,7 @@ const (

dmsURI uri = "/dms/{guild_id}/messages"
dmsMessageURI uri = "/dms/{guild_id}/messages/{message_id}"
c2cMessageURI uri = "/v2/users/{user_id}/messages/{message_id}"

channelAnnouncesURI = "/channels/{channel_id}/announces"
channelAnnounceURI = "/channels/{channel_id}/announces/{message_id}"
Expand Down
Loading
Loading