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

add workflow #503

Merged
merged 5 commits into from
Jun 10, 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
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master"]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21.0

- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3

- name: Lint
run: golangci-lint run ./...
24 changes: 17 additions & 7 deletions bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,32 @@ func TestLogout(t *testing.T) {
}
bot.MessageHandler = func(msg *Message) {
if msg.IsText() && msg.Content == "logout" {
bot.Logout()
if err := bot.Logout(); err != nil {
t.Error(err)
}
}
}
if err := bot.Login(); err != nil {
t.Error(err)
return
}
bot.Block()
_ = bot.Block()
}

func TestMessageHandle(t *testing.T) {
bot := DefaultBot(Desktop)
bot.MessageHandler = func(msg *Message) {
if msg.IsText() && msg.Content == "ping" {
msg.ReplyText("pong")
if _, err := msg.ReplyText("pong"); err != nil {
t.Error(err)
}
}
}
if err := bot.Login(); err != nil {
t.Error(err)
return
}
bot.Block()
_ = bot.Block()
}

func TestFriends(t *testing.T) {
Expand Down Expand Up @@ -106,9 +110,15 @@ func TestPinUser(t *testing.T) {
}
if friends.Count() > 0 {
f := friends.First()
f.Pin()
if err = f.Pin(); err != nil {
t.Error(err)
return
}
time.Sleep(time.Second * 5)
f.UnPin()
if err = f.UnPin(); err != nil {
t.Error(err)
return
}
}
}

Expand All @@ -125,7 +135,7 @@ func TestSender(t *testing.T) {
t.Error(err)
return
}
bot.Block()
_ = bot.Block()
}

// TestGetUUID
Expand Down
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (c *Client) WebWxUploadMediaByChunk(ctx context.Context, file *os.File, opt
if err != nil {
return nil, err
}
if _, err = file.Seek(io.SeekStart, 0); err != nil {
if _, err = file.Seek(0, io.SeekStart); err != nil {
return nil, err
}

Expand Down Expand Up @@ -980,6 +980,7 @@ func (c *Client) WebWxRevokeMsg(ctx context.Context, msg *SentMessage, request *
}

// 校验上传文件
// nolint:unused
func (c *Client) webWxCheckUpload(stat os.FileInfo, request *BaseRequest, fileMd5, fromUserName, toUserName string) (*http.Response, error) {
path, err := url.Parse(c.Domain.BaseHost() + webwxcheckupload)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cookiejar.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type entry struct {
// seqNum is a sequence number so that Jar returns cookies in a
// deterministic order, even for cookies that have equal Path length and
// equal Creation time. This simplifies testing.
seqNum uint64
seqNum uint64 // nolint:unused
}

// CookieGroup is a group of cookies
Expand Down
6 changes: 3 additions & 3 deletions global.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ const (
// 分块上传时每次上传的文件的大小
chunkSize int64 = (1 << 20) / 2 // 0.5m
// 需要检测的文件大小
needCheckSize int64 = 25 << 20 // 20m
needCheckSize int64 = 25 << 20 // nolint:unused
// 最大文件上传大小
maxFileUploadSize int64 = 50 << 20 // 50m
maxFileUploadSize int64 = 50 << 20 // nolint:unused
// 最大图片上传大小
maxImageUploadSize int64 = 20 << 20 // 20m
maxImageUploadSize int64 = 20 << 20 // nolint:unused
)

const TimeFormat = "Mon Jan 02 2006 15:04:05 GMT+0800 (中国标准时间)"
Expand Down
8 changes: 4 additions & 4 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (m *Message) Card() (*Card, error) {
return nil, errors.New("card message required")
}
var card Card
err := xml.Unmarshal(stringToByte(m.Content), &card)
err := xml.Unmarshal([]byte(m.Content), &card)
return &card, err
}

Expand All @@ -406,7 +406,7 @@ func (m *Message) FriendAddMessageContent() (*FriendAddMessage, error) {
return nil, errors.New("friend add message required")
}
var f FriendAddMessage
err := xml.Unmarshal(stringToByte(m.Content), &f)
err := xml.Unmarshal([]byte(m.Content), &f)
return &f, err
}

Expand All @@ -416,7 +416,7 @@ func (m *Message) RevokeMsg() (*RevokeMsg, error) {
return nil, errors.New("recalled message required")
}
var r RevokeMsg
err := xml.Unmarshal(stringToByte(m.Content), &r)
err := xml.Unmarshal([]byte(m.Content), &r)
return &r, err
}

Expand Down Expand Up @@ -463,7 +463,7 @@ func (m *Message) MediaData() (*AppMessageData, error) {
return nil, errors.New("media message required")
}
var data AppMessageData
if err := xml.Unmarshal(stringToByte(m.Content), &data); err != nil {
if err := xml.Unmarshal([]byte(m.Content), &data); err != nil {
return nil, err
}
return &data, nil
Expand Down
10 changes: 2 additions & 8 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
"math/rand"
"net/http"
"path/filepath"
"reflect"
"strconv"
"strings"
"time"
"unsafe"
)

func jsonEncode(v interface{}) (io.Reader, error) {
Expand All @@ -27,12 +25,12 @@ func jsonEncode(v interface{}) (io.Reader, error) {

// GetRandomDeviceId 获取随机设备id
func GetRandomDeviceId() string {
rand.Seed(time.Now().Unix())
rng := rand.New(rand.NewSource(time.Now().Unix()))
var builder strings.Builder
builder.Grow(16)
builder.WriteString("e")
for i := 0; i < 15; i++ {
r := rand.Intn(9)
r := rng.Intn(9)
builder.WriteString(strconv.Itoa(r))
}
return builder.String()
Expand Down Expand Up @@ -72,7 +70,3 @@ func getMessageType(filename string) string {
}
return doc
}

func stringToByte(s string) []byte {
return *(*[]byte)(unsafe.Pointer(&*(*reflect.StringHeader)(unsafe.Pointer(&s))))
}
6 changes: 3 additions & 3 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (u *User) OrderSymbol() string {
}
symbol = html.UnescapeString(symbol)
symbol = strings.ToUpper(symbol)
symbol = regexp.MustCompile("/\\W/ig").ReplaceAllString(symbol, "")
symbol = regexp.MustCompile(`/\W/ig`).ReplaceAllString(symbol, "")
if len(symbol) > 0 && symbol[0] < 'A' {
return "~"
}
Expand Down Expand Up @@ -386,8 +386,8 @@ func (s *Self) sendTextToUser(username, text string) (*SentMessage, error) {

func (s *Self) sendEmoticonToUser(username, md5 string, file io.Reader) (*SentMessage, error) {
opt := &CallerWebWxSendAppMsgOptions{
LoginInfo: s.bot.Storage.LoginInfo,
BaseRequest: s.bot.Storage.Request,
LoginInfo: s.bot.Storage.LoginInfo,
BaseRequest: s.bot.Storage.Request,
FromUserName: s.UserName,
ToUserName: username,
}
Expand Down
Loading