Skip to content

Commit

Permalink
feat: 添加image自动添加前缀和base64转化
Browse files Browse the repository at this point in the history
  • Loading branch information
huoxue1 committed Oct 9, 2021
1 parent a759a49 commit efdd041
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion message/cqcode.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package message

import (
"github.com/tidwall/gjson"
"reflect"
"unsafe"

"github.com/tidwall/gjson"
)

// Modified from https://github.com/catsworld/qq-bot-api
Expand Down
38 changes: 38 additions & 0 deletions message/message.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package message

import (
"encoding/base64"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -96,6 +97,43 @@ func Face(id int) MessageSegment {
}
}

// ImageC 普通图片
// https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E5%9B%BE%E7%89%87
func ImageC(file interface{}) MessageSegment {
switch file.(type) {
case string:
if strings.HasPrefix(file.(string), "http://") || strings.HasPrefix(file.(string), "https://") {
return MessageSegment{
Type: "image",
Data: map[string]string{
"file": file.(string),
},
}
} else {
return MessageSegment{
Type: "image",
Data: map[string]string{
"file": "file:///" + file.(string),
},
}
}
case []byte:
return MessageSegment{
Type: "image",
Data: map[string]string{
"file": base64.StdEncoding.EncodeToString(file.([]byte)),
},
}
default:
return MessageSegment{
Type: "image",
Data: map[string]string{
"file": file.(string),
},
}
}
}

// Image 普通图片
// https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E5%9B%BE%E7%89%87
func Image(file string) MessageSegment {
Expand Down

0 comments on commit efdd041

Please sign in to comment.