Skip to content

Commit

Permalink
feat: ocr,获取at次数,群打卡,设置群头像
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 26, 2024
1 parent e7ea3f0 commit c70e33e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 46 deletions.
97 changes: 54 additions & 43 deletions coolq/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package coolq

import (
"bytes"
"crypto/md5"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -789,16 +790,16 @@ func (bot *CQBot) CQSetGroupLeave(groupID int64) global.MSG {
//
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4-%E5%85%A8%E4%BD%93%E6%88%90%E5%91%98-%E5%89%A9%E4%BD%99%E6%AC%A1%E6%95%B0
// @route(get_group_at_all_remain)
//func (bot *CQBot) CQGetAtAllRemain(groupID int64) global.MSG {
// if g := bot.Client.FindGroup(groupID); g != nil {
// i, err := bot.Client.GetAtAllRemain(groupID)
// if err != nil {
// return Failed(100, "GROUP_REMAIN_API_ERROR", err.Error())
// }
// return OK(i)
// }
// return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
//}
func (bot *CQBot) CQGetAtAllRemain(groupID int64) global.MSG {
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
i, err := bot.Client.GetAtAllRemain(bot.Client.Uin, uint32(groupID))
if err != nil {
return Failed(100, "GROUP_REMAIN_API_ERROR", err.Error())
}
return OK(i)
}
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
}

// CQProcessFriendRequest 处理加好友请求
//
Expand Down Expand Up @@ -1379,40 +1380,47 @@ func (bot *CQBot) CQCanSendRecord() global.MSG {
// https://docs.go-cqhttp.org/api/#%E5%9B%BE%E7%89%87-ocr
// @route(ocr_image,".ocr_image")
// @rename(image_id->image)
//func (bot *CQBot) CQOcrImage(imageID string) global.MSG {
// // TODO: fix this
// var elem msg.Element
// elem.Type = "image"
// elem.Data = []msg.Pair{{K: "file", V: imageID}}
// img, err := bot.makeImageOrVideoElem(elem, false, message.SourceGroup)
// if err != nil {
// log.Warnf("load image error: %v", err)
// return Failed(100, "LOAD_FILE_ERROR", err.Error())
// }
// rsp, err := bot.Client.ImageOcr(img)
// if err != nil {
// log.Warnf("ocr image error: %v", err)
// return Failed(100, "OCR_API_ERROR", err.Error())
// }
// return OK(rsp)
//}
func (bot *CQBot) CQOcrImage(imageID string) global.MSG {
// TODO: fix this
var elem msg.Element
elem.Type = "image"
elem.Data = []msg.Pair{{K: "file", V: imageID}}
img, err := bot.makeImageOrVideoElem(elem, false, message.SourceGroup)
if err != nil {
log.Warnf("load image error: %v", err)
return Failed(100, "LOAD_FILE_ERROR", err.Error())
}
image, ok := img.(*msg.LocalImage)
if !ok {
return Failed(100, "IMAGE_ERROR", "图片数据错误")
}
rsp, err := bot.Client.ImageOcr(image.URL)
if err != nil {
log.Warnf("ocr image error: %v", err)
return Failed(100, "OCR_API_ERROR", err.Error())
}
return OK(rsp)
}

// CQSetGroupPortrait 扩展API-设置群头像
//
// https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F
// @route(set_group_portrait)
//func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) global.MSG {
// if g := bot.Client.FindGroup(groupID); g != nil {
// img, err := global.FindFile(file, cache, global.ImagePath)
// if err != nil {
// log.Warnf("set group portrait error: %v", err)
// return Failed(100, "LOAD_FILE_ERROR", err.Error())
// }
// g.UpdateGroupHeadPortrait(img)
// return OK(nil)
// }
// return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
//}
func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) global.MSG {
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
img, err := global.FindFile(file, cache, global.ImagePath)
if err != nil {
log.Warnf("set group portrait error: %v", err)
return Failed(100, "LOAD_FILE_ERROR", err.Error())
}
if bot.Client.SetGroupAvatar(g.GroupUin, bytes.NewReader(img)) == nil {
return OK(nil)
}
Failed(100, "PERMISSION_DENIED", "机器人权限不足")

}
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
}

// CQSetGroupAnonymousBan 群组匿名用户禁言
//
Expand Down Expand Up @@ -1585,10 +1593,13 @@ func (bot *CQBot) CQGetVersionInfo() global.MSG {
//
// https://club.vip.qq.com/onlinestatus/set
// @route(send_group_sign)
//func (bot *CQBot) CQSendGroupSign(groupID int64) global.MSG {
// bot.Client.SendGroupSign(groupID)
// return OK(nil)
//}
func (bot *CQBot) CQSendGroupSign(groupID int64) global.MSG {
_, err := bot.Client.SendGroupSign(uint32(groupID))
if err == nil {
return OK(nil)
}
return Failed(100, "SEND_GROUP_SIGN_ERROR", err.Error())
}

// CQSetModelShow 设置在线机型
//
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/FloatTech/sqlite v1.6.3
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241114153145-593cc9695c20
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241123020035-566cbd22ddb7
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4
github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY=
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1 h1:g4pTnDJUW4VbJ9NvoRfUvdjDrHz/6QhfN/LoIIpICbo=
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241114153145-593cc9695c20 h1:3vE7lW4qieoxzyIM0FZG100uZDt3GAFdsfYFR9lsb2g=
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241114153145-593cc9695c20/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241123020035-566cbd22ddb7 h1:x/2DdNx7l6A2Neu/juc7hkk6fZ4eGR6z/D0Hz76AM1w=
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241123020035-566cbd22ddb7/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a h1:aU1703IHxupjzipvhu16qYKLMR03e+8WuNR+JMsKfGU=
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a/go.mod h1:OZqLNXdYJHmx7aqq/T6wAdFEdoGm5nmIfC4kU7M8P8o=
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
Expand Down
14 changes: 14 additions & 0 deletions modules/api/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/onebot/supported.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c70e33e

Please sign in to comment.