mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-07-03 21:03:25 +00:00
Compare commits
3 Commits
f9217aadb5
...
7fdb04c902
Author | SHA1 | Date | |
---|---|---|---|
7fdb04c902 | |||
acf77019e8 | |||
b2b98cc2d5 |
@ -3,7 +3,6 @@ linters-settings:
|
|||||||
exclude-functions:
|
exclude-functions:
|
||||||
- fmt:.*
|
- fmt:.*
|
||||||
- io/ioutil:^Read.*
|
- io/ioutil:^Read.*
|
||||||
ignoretests: true
|
|
||||||
|
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: github.com/Mrs4s/go-cqhttp
|
local-prefixes: github.com/Mrs4s/go-cqhttp
|
||||||
@ -53,13 +52,15 @@ linters:
|
|||||||
run:
|
run:
|
||||||
# default concurrency is a available CPU number.
|
# default concurrency is a available CPU number.
|
||||||
# concurrency: 4 # explicitly omit this value to fully utilize available resources.
|
# concurrency: 4 # explicitly omit this value to fully utilize available resources.
|
||||||
deadline: 5m
|
timeout: 5m
|
||||||
issues-exit-code: 1
|
issues-exit-code: 1
|
||||||
tests: true
|
tests: true
|
||||||
|
|
||||||
# output configuration options
|
# output configuration options
|
||||||
output:
|
output:
|
||||||
formats: "colored-line-number"
|
formats:
|
||||||
|
- format: colored-line-number
|
||||||
|
path: stdout
|
||||||
print-issued-lines: true
|
print-issued-lines: true
|
||||||
print-linter-name: true
|
print-linter-name: true
|
||||||
uniq-by-line: true
|
uniq-by-line: true
|
||||||
|
243
coolq/api.go
243
coolq/api.go
@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -64,64 +65,61 @@ func (bot *CQBot) CQGetFriendList(spec *onebot.Spec) global.MSG {
|
|||||||
return OK(fs)
|
return OK(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 不支持的api,扔了先
|
|
||||||
// CQGetUnidirectionalFriendList 获取单向好友列表
|
// CQGetUnidirectionalFriendList 获取单向好友列表
|
||||||
//
|
//
|
||||||
// @route(get_unidirectional_friend_list)
|
// @route(get_unidirectional_friend_list)
|
||||||
//func (bot *CQBot) CQGetUnidirectionalFriendList() global.MSG {
|
func (bot *CQBot) CQGetUnidirectionalFriendList() global.MSG {
|
||||||
// list, err := bot.Client.GetUnidirectionalFriendList()
|
list, err := bot.Client.GetUnidirectionalFriendList()
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// log.Warnf("获取单向好友列表时出现错误: %v", err)
|
log.Warnf("获取单向好友列表时出现错误: %v", err)
|
||||||
// return Failed(100, "API_ERROR", err.Error())
|
return Failed(100, "API_ERROR", err.Error())
|
||||||
// }
|
}
|
||||||
// fs := make([]global.MSG, 0, len(list))
|
fs := make([]global.MSG, 0, len(list))
|
||||||
// for _, f := range list {
|
for _, f := range list {
|
||||||
// fs = append(fs, global.MSG{
|
fs = append(fs, global.MSG{
|
||||||
// "nickname": f.Nickname,
|
"nickname": f.Nickname,
|
||||||
// "user_id": f.Uin,
|
"user_id": f.Uin,
|
||||||
// "source": f.Source,
|
"source": f.Source,
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
// return OK(fs)
|
return OK(fs)
|
||||||
//}
|
}
|
||||||
|
|
||||||
// TODO 不支持的api,扔了先
|
|
||||||
// CQDeleteUnidirectionalFriend 删除单向好友
|
// CQDeleteUnidirectionalFriend 删除单向好友
|
||||||
//
|
//
|
||||||
// @route(delete_unidirectional_friend)
|
// @route(delete_unidirectional_friend)
|
||||||
// @rename(uin->user_id)
|
// @rename(uin->user_id)
|
||||||
//func (bot *CQBot) CQDeleteUnidirectionalFriend(uin int64) global.MSG {
|
func (bot *CQBot) CQDeleteUnidirectionalFriend(uin int64) global.MSG {
|
||||||
// list, err := bot.Client.GetUnidirectionalFriendList()
|
list, err := bot.Client.GetUnidirectionalFriendList()
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// log.Warnf("获取单向好友列表时出现错误: %v", err)
|
log.Warnf("获取单向好友列表时出现错误: %v", err)
|
||||||
// return Failed(100, "API_ERROR", err.Error())
|
return Failed(100, "API_ERROR", err.Error())
|
||||||
// }
|
}
|
||||||
// for _, f := range list {
|
for _, f := range list {
|
||||||
// if f.Uin == uin {
|
if f.Uin == uint32(uin) {
|
||||||
// if err = bot.Client.DeleteUnidirectionalFriend(uin); err != nil {
|
if err = bot.Client.DeleteUnidirectionalFriend(uint32(uin)); err != nil {
|
||||||
// log.Warnf("删除单向好友时出现错误: %v", err)
|
log.Warnf("删除单向好友时出现错误: %v", err)
|
||||||
// return Failed(100, "API_ERROR", err.Error())
|
return Failed(100, "API_ERROR", err.Error())
|
||||||
// }
|
}
|
||||||
// return OK(nil)
|
return OK(nil)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// return Failed(100, "FRIEND_NOT_FOUND", "好友不存在")
|
return Failed(100, "FRIEND_NOT_FOUND", "好友不存在")
|
||||||
//}
|
}
|
||||||
|
|
||||||
// TODO 不支持的api,扔了先
|
|
||||||
// CQDeleteFriend 删除好友
|
// CQDeleteFriend 删除好友
|
||||||
// @route(delete_friend)
|
// @route(delete_friend)
|
||||||
// @rename(uin->"[user_id\x2Cid].0")
|
// @rename(uin->"[user_id\x2Cid].0")
|
||||||
//func (bot *CQBot) CQDeleteFriend(uin int64) global.MSG {
|
func (bot *CQBot) CQDeleteFriend(uin int64, block bool) global.MSG {
|
||||||
// if bot.Client.FindFriend(uin) == nil {
|
if bot.Client.GetCachedFriendInfo(uint32(uin)) == nil {
|
||||||
// return Failed(100, "FRIEND_NOT_FOUND", "好友不存在")
|
return Failed(100, "FRIEND_NOT_FOUND", "好友不存在")
|
||||||
// }
|
}
|
||||||
// if err := bot.Client.DeleteFriend(uin); err != nil {
|
if err := bot.Client.DeleteFriend(uint32(uin), block); err != nil {
|
||||||
// log.Warnf("删除好友时出现错误: %v", err)
|
log.Warnf("删除好友时出现错误: %v", err)
|
||||||
// return Failed(100, "DELETE_API_ERROR", err.Error())
|
return Failed(100, "DELETE_API_ERROR", err.Error())
|
||||||
// }
|
}
|
||||||
// return OK(nil)
|
return OK(nil)
|
||||||
//}
|
}
|
||||||
|
|
||||||
// CQGetGroupList 获取群列表
|
// CQGetGroupList 获取群列表
|
||||||
//
|
//
|
||||||
@ -278,7 +276,7 @@ func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) gl
|
|||||||
log.Warnf("上传群文件 %v 失败: 文件不存在", file)
|
log.Warnf("上传群文件 %v 失败: 文件不存在", file)
|
||||||
return Failed(100, "FILE_NOT_FOUND", "文件不存在")
|
return Failed(100, "FILE_NOT_FOUND", "文件不存在")
|
||||||
}
|
}
|
||||||
if err := bot.Client.UploadGroupFile(uint32(groupID), file, name, utils.Ternary(folder == "", "/", folder)); err != nil {
|
if err := bot.Client.SendGroupFile(uint32(groupID), file, name, utils.Ternary(folder == "", "/", folder)); err != nil {
|
||||||
log.Warnf("上传群 %v 文件 %v 失败: %v", groupID, file, err)
|
log.Warnf("上传群 %v 文件 %v 失败: %v", groupID, file, err)
|
||||||
return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error())
|
return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
@ -293,7 +291,7 @@ func (bot *CQBot) CQUploadPrivateFile(userID int64, file, name string) global.MS
|
|||||||
log.Warnf("上传群文件 %v 失败: 文件不存在", file)
|
log.Warnf("上传群文件 %v 失败: 文件不存在", file)
|
||||||
return Failed(100, "FILE_NOT_FOUND", "文件不存在")
|
return Failed(100, "FILE_NOT_FOUND", "文件不存在")
|
||||||
}
|
}
|
||||||
if err := bot.Client.UploadPrivateFile(uint32(userID), file, name); err != nil {
|
if err := bot.Client.SendPrivateFile(uint32(userID), file, name); err != nil {
|
||||||
log.Warnf("上传私聊 %v 文件 %v 失败: %+v", userID, file, err)
|
log.Warnf("上传私聊 %v 文件 %v 失败: %+v", userID, file, err)
|
||||||
return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error())
|
return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
@ -618,7 +616,7 @@ func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Resu
|
|||||||
func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) global.MSG {
|
func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) global.MSG {
|
||||||
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
||||||
if m := bot.Client.GetCachedMemberInfo(uint32(userID), uint32(groupID)); m != nil {
|
if m := bot.Client.GetCachedMemberInfo(uint32(userID), uint32(groupID)); m != nil {
|
||||||
if err := bot.Client.GroupRenameMember(uint32(groupID), uint32(userID), card); err != nil {
|
if err := bot.Client.SetGroupMemberName(uint32(groupID), uint32(userID), card); err != nil {
|
||||||
return Failed(100, "SET_CARD_FAILED", err.Error())
|
return Failed(100, "SET_CARD_FAILED", err.Error())
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -636,7 +634,7 @@ func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) global.MSG
|
|||||||
func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) global.MSG {
|
func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) global.MSG {
|
||||||
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
||||||
if m := bot.Client.GetCachedMemberInfo(uint32(userID), uint32(groupID)); m != nil {
|
if m := bot.Client.GetCachedMemberInfo(uint32(userID), uint32(groupID)); m != nil {
|
||||||
if err := bot.Client.GroupSetSpecialTitle(uint32(groupID), uint32(userID), title); err != nil {
|
if err := bot.Client.SetGroupMemberSpecialTitle(uint32(groupID), uint32(userID), title); err != nil {
|
||||||
return Failed(100, "SET_Title_FAILED", err.Error())
|
return Failed(100, "SET_Title_FAILED", err.Error())
|
||||||
}
|
}
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -652,7 +650,7 @@ func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) gl
|
|||||||
// @rename(name->group_name)
|
// @rename(name->group_name)
|
||||||
func (bot *CQBot) CQSetGroupName(groupID int64, name string) global.MSG {
|
func (bot *CQBot) CQSetGroupName(groupID int64, name string) global.MSG {
|
||||||
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
||||||
if err := bot.Client.GroupRename(uint32(groupID), name); err != nil {
|
if err := bot.Client.SetGroupName(uint32(groupID), name); err != nil {
|
||||||
return Failed(100, "SET_NAME_FAILED", err.Error())
|
return Failed(100, "SET_NAME_FAILED", err.Error())
|
||||||
}
|
}
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -729,7 +727,7 @@ func (bot *CQBot) CQSetGroupKick(groupID int64, userID int64, block bool) global
|
|||||||
if m == nil {
|
if m == nil {
|
||||||
return Failed(100, "MEMBER_NOT_FOUND", "人员不存在")
|
return Failed(100, "MEMBER_NOT_FOUND", "人员不存在")
|
||||||
}
|
}
|
||||||
if err := bot.Client.GroupKickMember(uint32(groupID), uint32(userID), block); err != nil {
|
if err := bot.Client.KickGroupMember(uint32(groupID), uint32(userID), block); err != nil {
|
||||||
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
||||||
}
|
}
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -748,7 +746,7 @@ func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) global.M
|
|||||||
if duration >= 2592000 {
|
if duration >= 2592000 {
|
||||||
return Failed(100, "DURATION_IS_NOT_IN_RANGE", "非法的禁言时长")
|
return Failed(100, "DURATION_IS_NOT_IN_RANGE", "非法的禁言时长")
|
||||||
}
|
}
|
||||||
if err := bot.Client.GroupMuteMember(uint32(groupID), uint32(userID), duration); err != nil {
|
if err := bot.Client.SetGroupMemberMute(uint32(groupID), uint32(userID), duration); err != nil {
|
||||||
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
||||||
}
|
}
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -764,7 +762,7 @@ func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) global.M
|
|||||||
// @default(enable=true)
|
// @default(enable=true)
|
||||||
func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) global.MSG {
|
func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) global.MSG {
|
||||||
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
||||||
if err := bot.Client.GroupMuteGlobal(uint32(groupID), enable); err != nil {
|
if err := bot.Client.SetGroupGlobalMute(uint32(groupID), enable); err != nil {
|
||||||
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
||||||
}
|
}
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -778,7 +776,7 @@ func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) global.MSG {
|
|||||||
// @route(set_group_leave)
|
// @route(set_group_leave)
|
||||||
func (bot *CQBot) CQSetGroupLeave(groupID int64) global.MSG {
|
func (bot *CQBot) CQSetGroupLeave(groupID int64) global.MSG {
|
||||||
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g != nil {
|
||||||
if err := bot.Client.GroupLeave(uint32(groupID)); err != nil {
|
if err := bot.Client.SetGroupLeave(uint32(groupID)); err != nil {
|
||||||
return Failed(100, "反正是失败了.png", err.Error())
|
return Failed(100, "反正是失败了.png", err.Error())
|
||||||
}
|
}
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -839,7 +837,7 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
|||||||
if subType == "add" {
|
if subType == "add" {
|
||||||
for _, req := range append(msgs.JoinRequests, filteredmsgs.JoinRequests...) {
|
for _, req := range append(msgs.JoinRequests, filteredmsgs.JoinRequests...) {
|
||||||
if strconv.FormatInt(int64(req.Sequence), 10) == flag {
|
if strconv.FormatInt(int64(req.Sequence), 10) == flag {
|
||||||
if req.Checked() {
|
if req.Checked {
|
||||||
log.Warnf("处理群系统消息失败: 无法操作已处理的消息.")
|
log.Warnf("处理群系统消息失败: 无法操作已处理的消息.")
|
||||||
return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理")
|
return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理")
|
||||||
}
|
}
|
||||||
@ -854,7 +852,7 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
|||||||
} else {
|
} else {
|
||||||
for _, req := range append(msgs.InvitedRequests, filteredmsgs.InvitedRequests...) {
|
for _, req := range append(msgs.InvitedRequests, filteredmsgs.InvitedRequests...) {
|
||||||
if strconv.FormatInt(int64(req.Sequence), 10) == flag {
|
if strconv.FormatInt(int64(req.Sequence), 10) == flag {
|
||||||
if req.Checked() {
|
if req.Checked {
|
||||||
log.Warnf("处理群系统消息失败: 无法操作已处理的消息.")
|
log.Warnf("处理群系统消息失败: 无法操作已处理的消息.")
|
||||||
return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理")
|
return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理")
|
||||||
}
|
}
|
||||||
@ -918,8 +916,8 @@ func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) global.MSG
|
|||||||
if m.Permission != entity.Owner {
|
if m.Permission != entity.Owner {
|
||||||
return Failed(100, "PERMISSION_DENIED", "或权限不足")
|
return Failed(100, "PERMISSION_DENIED", "或权限不足")
|
||||||
}
|
}
|
||||||
if err := bot.Client.GroupSetAdmin(uint32(groupID), uint32(userID), enable); err != nil {
|
if err := bot.Client.SetGroupAdmin(uint32(groupID), uint32(userID), enable); err != nil {
|
||||||
return Failed(100, "反正是失败了.png", err.Error())
|
return Failed(100, "UNKNOWN_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
@ -1284,56 +1282,53 @@ func (bot *CQBot) CQGetMessage(messageID int32) global.MSG {
|
|||||||
return OK(m)
|
return OK(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CQGetGroupSystemMessages 扩展API-获取群文件系统消息
|
// CQGetGroupSystemMessages 扩展API-获取群系统消息
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%B3%BB%E7%BB%9F%E6%B6%88%E6%81%AF
|
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%B3%BB%E7%BB%9F%E6%B6%88%E6%81%AF
|
||||||
// @route(get_group_system_msg)
|
// @route(get_group_system_msg)
|
||||||
//func (bot *CQBot) CQGetGroupSystemMessages() global.MSG {
|
func (bot *CQBot) CQGetGroupSystemMessages() global.MSG {
|
||||||
// msg, err := bot.Client.GetGroupSystemMessages()
|
msgs, err := bot.Client.GetGroupSystemMessages(false, 20)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// log.Warnf("获取群系统消息失败: %v", err)
|
log.Warnf("获取群系统消息失败: %v", err)
|
||||||
// return Failed(100, "SYSTEM_MSG_API_ERROR", err.Error())
|
return Failed(100, "SYSTEM_MSG_API_ERROR", err.Error())
|
||||||
// }
|
}
|
||||||
// return OK(msg)
|
return OK(msgs)
|
||||||
//}
|
}
|
||||||
|
|
||||||
// CQGetGroupMessageHistory 获取群消息历史记录
|
// CQGetGroupMessageHistory 获取群消息历史记录
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%B6%88%E6%81%AF%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95
|
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%B6%88%E6%81%AF%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95
|
||||||
// @route(get_group_msg_history)
|
// @route(get_group_msg_history)
|
||||||
// @rename(seq->message_seq)
|
// @rename(seq->message_seq)
|
||||||
//func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) global.MSG {
|
func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) global.MSG {
|
||||||
// if g, _ := bot.Client.GetCachedGroupInfo(uint32(groupID)); g == nil {
|
if g := bot.Client.GetCachedGroupInfo(uint32(groupID)); g == nil {
|
||||||
// return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
// }
|
}
|
||||||
// if seq == 0 {
|
if seq == 0 {
|
||||||
// g, err := bot.Client.GetCachedGroupInfo(uint32(groupID))
|
g := bot.Client.GetCachedGroupInfo(uint32(groupID))
|
||||||
// if err != nil {
|
seq = int64(g.LastMsgSeq)
|
||||||
// return Failed(100, "GROUP_INFO_API_ERROR", err.Error())
|
}
|
||||||
// }
|
msg, err := bot.Client.GetGroupMessages(uint32(groupID), uint32(math.Max(float64(seq-19), 1)), uint32(seq))
|
||||||
// seq = g.LastMsgSeq
|
if err != nil {
|
||||||
// }
|
log.Warnf("获取群历史消息失败: %v", err)
|
||||||
// msg, err := bot.Client.GetGroupMessages(groupID, int64(math.Max(float64(seq-19), 1)), seq)
|
return Failed(100, "MESSAGES_API_ERROR", err.Error())
|
||||||
// if err != nil {
|
}
|
||||||
// log.Warnf("获取群历史消息失败: %v", err)
|
source := message.Source{
|
||||||
// return Failed(100, "MESSAGES_API_ERROR", err.Error())
|
SourceType: message.SourcePrivate,
|
||||||
// }
|
PrimaryID: 0,
|
||||||
// source := message.Source{
|
}
|
||||||
// SourceType: message.SourcePrivate,
|
ms := make([]*event, 0, len(msg))
|
||||||
// PrimaryID: 0,
|
for _, m := range msg {
|
||||||
// }
|
bot.checkMedia(m.Elements, source)
|
||||||
// ms := make([]*event, 0, len(msg))
|
id := bot.InsertGroupMessage(m, source)
|
||||||
// for _, m := range msg {
|
t := bot.formatGroupMessage(m)
|
||||||
// bot.checkMedia(m.Elements, groupID)
|
t.Others["message_id"] = id
|
||||||
// id := bot.InsertGroupMessage(m, source)
|
ms = append(ms, t)
|
||||||
// t := bot.formatGroupMessage(m)
|
}
|
||||||
// t.Others["message_id"] = id
|
return OK(global.MSG{
|
||||||
// ms = append(ms, t)
|
"messages": ms,
|
||||||
// }
|
})
|
||||||
// return OK(global.MSG{
|
}
|
||||||
// "messages": ms,
|
|
||||||
// })
|
|
||||||
//}
|
|
||||||
|
|
||||||
// CQGetOnlineClients 扩展API-获取当前账号在线客户端列表
|
// CQGetOnlineClients 扩展API-获取当前账号在线客户端列表
|
||||||
//
|
//
|
||||||
@ -1458,14 +1453,13 @@ func (bot *CQBot) CQGetStatus(spec *onebot.Spec) global.MSG {
|
|||||||
"app_good": true,
|
"app_good": true,
|
||||||
"online": bot.Client.Online.Load(),
|
"online": bot.Client.Online.Load(),
|
||||||
"good": bot.Client.Online.Load(),
|
"good": bot.Client.Online.Load(),
|
||||||
// TODO 暂时没有
|
"stat": bot.Client.GetStatistics(),
|
||||||
//"stat": bot.Client.GetStatistics(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return OK(global.MSG{
|
return OK(global.MSG{
|
||||||
"online": bot.Client.Online.Load(),
|
"online": bot.Client.Online.Load(),
|
||||||
"good": bot.Client.Online.Load(),
|
"good": bot.Client.Online.Load(),
|
||||||
//"stat": bot.Client.GetStatistics(),
|
"stat": bot.Client.GetStatistics(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1537,11 +1531,12 @@ func (bot *CQBot) CQGetEssenceMessageList(groupID int64) global.MSG {
|
|||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E6%A3%80%E6%9F%A5%E9%93%BE%E6%8E%A5%E5%AE%89%E5%85%A8%E6%80%A7
|
// https://docs.go-cqhttp.org/api/#%E6%A3%80%E6%9F%A5%E9%93%BE%E6%8E%A5%E5%AE%89%E5%85%A8%E6%80%A7
|
||||||
// @route(check_url_safely)
|
// @route(check_url_safely)
|
||||||
//func (bot *CQBot) CQCheckURLSafely(url string) global.MSG {
|
func (bot *CQBot) CQCheckURLSafely(url string) global.MSG {
|
||||||
// return OK(global.MSG{
|
level, _ := bot.Client.CheckURLSafely(url)
|
||||||
// "level": bot.Client.CheckUrlSafely(url),
|
return OK(global.MSG{
|
||||||
// })
|
"level": level,
|
||||||
//}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// CQGetVersionInfo 获取版本信息
|
// CQGetVersionInfo 获取版本信息
|
||||||
//
|
//
|
||||||
@ -1613,24 +1608,26 @@ func (bot *CQBot) CQSendGroupSign(groupID int64) global.MSG {
|
|||||||
// return OK(nil)
|
// return OK(nil)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// TODO 计划实现的api
|
|
||||||
// CQMarkMessageAsRead 标记消息已读
|
// CQMarkMessageAsRead 标记消息已读
|
||||||
// @route(mark_msg_as_read)
|
// @route(mark_msg_as_read)
|
||||||
// @rename(msg_id->message_id)
|
// @rename(msg_id->message_id)
|
||||||
//func (bot *CQBot) CQMarkMessageAsRead(msgID int32) global.MSG {
|
func (bot *CQBot) CQMarkMessageAsRead(msgID int32) global.MSG {
|
||||||
// m, err := db.GetMessageByGlobalID(msgID)
|
m, err := db.GetMessageByGlobalID(msgID)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||||
// }
|
}
|
||||||
// switch o := m.(type) {
|
switch o := m.(type) {
|
||||||
// case *db.StoredGroupMessage:
|
case *db.StoredGroupMessage:
|
||||||
// bot.Client.MarkGroupMessageReaded(o.GroupCode, int64(o.Attribute.MessageSeq))
|
if bot.Client.MarkGroupMessageReaded(uint32(o.GroupCode), uint32(o.Attribute.MessageSeq)) != nil {
|
||||||
// return OK(nil)
|
return Failed(100, "ACTION_FAILED", "标记群消息已读失败")
|
||||||
// case *db.StoredPrivateMessage:
|
}
|
||||||
// bot.Client.MarkPrivateMessageReaded(o.SessionUin, o.Attribute.Timestamp)
|
case *db.StoredPrivateMessage:
|
||||||
// }
|
if bot.Client.MarkPrivateMessageReaded(uint32(o.SessionUin), uint32(o.Attribute.Timestamp), uint32(o.Attribute.MessageSeq)) != nil {
|
||||||
// return OK(nil)
|
return Failed(100, "ACTION_FAILED", "标记私聊消息已读失败")
|
||||||
//}
|
}
|
||||||
|
}
|
||||||
|
return OK(nil)
|
||||||
|
}
|
||||||
|
|
||||||
// CQSetQQProfile 设置 QQ 资料
|
// CQSetQQProfile 设置 QQ 资料
|
||||||
//
|
//
|
||||||
|
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.20
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/FloatTech/sqlite v1.6.3
|
github.com/FloatTech/sqlite v1.6.3
|
||||||
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241127060254-2b65455dd776
|
github.com/LagrangeDev/LagrangeGo v0.1.2
|
||||||
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a
|
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a
|
||||||
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
|
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
|
||||||
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
|
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
|
||||||
|
4
go.sum
4
go.sum
@ -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/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 h1:g4pTnDJUW4VbJ9NvoRfUvdjDrHz/6QhfN/LoIIpICbo=
|
||||||
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
||||||
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241127060254-2b65455dd776 h1:hLOMBo1yB9gXp9JuK2CmPzGPrdpO+l3FW4W8R2IEshE=
|
github.com/LagrangeDev/LagrangeGo v0.1.2 h1:owH3gSZRTmW1qRuLsdkZsaBjyijKQUaJnLoui5XaTq0=
|
||||||
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241127060254-2b65455dd776/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
|
github.com/LagrangeDev/LagrangeGo v0.1.2/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 h1:aU1703IHxupjzipvhu16qYKLMR03e+8WuNR+JMsKfGU=
|
||||||
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a/go.mod h1:OZqLNXdYJHmx7aqq/T6wAdFEdoGm5nmIfC4kU7M8P8o=
|
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=
|
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
|
||||||
|
@ -93,6 +93,9 @@ func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG {
|
|||||||
p1 := p.Get("content").String()
|
p1 := p.Get("content").String()
|
||||||
p2 := p.Get("image").String()
|
p2 := p.Get("image").String()
|
||||||
return c.bot.CQSetGroupMemo(p0, p1, p2)
|
return c.bot.CQSetGroupMemo(p0, p1, p2)
|
||||||
|
case "check_url_safely":
|
||||||
|
p0 := p.Get("url").String()
|
||||||
|
return c.bot.CQCheckURLSafely(p0)
|
||||||
case "create_group_file_folder":
|
case "create_group_file_folder":
|
||||||
p0 := p.Get("group_id").Int()
|
p0 := p.Get("group_id").Int()
|
||||||
p1 := p.Get("parent_id").String()
|
p1 := p.Get("parent_id").String()
|
||||||
@ -101,6 +104,10 @@ func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG {
|
|||||||
case "delete_essence_msg":
|
case "delete_essence_msg":
|
||||||
p0 := int32(p.Get("message_id").Int())
|
p0 := int32(p.Get("message_id").Int())
|
||||||
return c.bot.CQDeleteEssenceMessage(p0)
|
return c.bot.CQDeleteEssenceMessage(p0)
|
||||||
|
case "delete_friend":
|
||||||
|
p0 := p.Get("[user_id,id].0").Int()
|
||||||
|
p1 := p.Get("block").Bool()
|
||||||
|
return c.bot.CQDeleteFriend(p0, p1)
|
||||||
case "delete_group_file":
|
case "delete_group_file":
|
||||||
p0 := p.Get("group_id").Int()
|
p0 := p.Get("group_id").Int()
|
||||||
p1 := p.Get("id").String()
|
p1 := p.Get("id").String()
|
||||||
@ -112,6 +119,9 @@ func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG {
|
|||||||
case "delete_msg":
|
case "delete_msg":
|
||||||
p0 := int32(p.Get("message_id").Int())
|
p0 := int32(p.Get("message_id").Int())
|
||||||
return c.bot.CQDeleteMessage(p0)
|
return c.bot.CQDeleteMessage(p0)
|
||||||
|
case "delete_unidirectional_friend":
|
||||||
|
p0 := p.Get("user_id").Int()
|
||||||
|
return c.bot.CQDeleteUnidirectionalFriend(p0)
|
||||||
case "download_file":
|
case "download_file":
|
||||||
p0 := p.Get("url").String()
|
p0 := p.Get("url").String()
|
||||||
p1 := p.Get("headers")
|
p1 := p.Get("headers")
|
||||||
@ -159,9 +169,15 @@ func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG {
|
|||||||
p0 := p.Get("group_id").Int()
|
p0 := p.Get("group_id").Int()
|
||||||
p1 := p.Get("no_cache").Bool()
|
p1 := p.Get("no_cache").Bool()
|
||||||
return c.bot.CQGetGroupMemberList(p0, p1)
|
return c.bot.CQGetGroupMemberList(p0, p1)
|
||||||
|
case "get_group_msg_history":
|
||||||
|
p0 := p.Get("group_id").Int()
|
||||||
|
p1 := p.Get("message_seq").Int()
|
||||||
|
return c.bot.CQGetGroupMessageHistory(p0, p1)
|
||||||
case "get_group_root_files":
|
case "get_group_root_files":
|
||||||
p0 := p.Get("group_id").Int()
|
p0 := p.Get("group_id").Int()
|
||||||
return c.bot.CQGetGroupRootFiles(p0)
|
return c.bot.CQGetGroupRootFiles(p0)
|
||||||
|
case "get_group_system_msg":
|
||||||
|
return c.bot.CQGetGroupSystemMessages()
|
||||||
case "get_image":
|
case "get_image":
|
||||||
p0 := p.Get("file").String()
|
p0 := p.Get("file").String()
|
||||||
return c.bot.CQGetImage(p0)
|
return c.bot.CQGetImage(p0)
|
||||||
@ -172,6 +188,11 @@ func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG {
|
|||||||
return c.bot.CQGetStatus(spec)
|
return c.bot.CQGetStatus(spec)
|
||||||
case "get_supported_actions":
|
case "get_supported_actions":
|
||||||
return c.bot.CQGetSupportedActions(spec)
|
return c.bot.CQGetSupportedActions(spec)
|
||||||
|
case "get_unidirectional_friend_list":
|
||||||
|
return c.bot.CQGetUnidirectionalFriendList()
|
||||||
|
case "mark_msg_as_read":
|
||||||
|
p0 := int32(p.Get("message_id").Int())
|
||||||
|
return c.bot.CQMarkMessageAsRead(p0)
|
||||||
case "reload_event_filter":
|
case "reload_event_filter":
|
||||||
p0 := p.Get("file").String()
|
p0 := p.Get("file").String()
|
||||||
return c.bot.CQReloadEventFilter(p0)
|
return c.bot.CQReloadEventFilter(p0)
|
||||||
|
@ -11,11 +11,14 @@ var supportedV11 = []string{
|
|||||||
"_send_group_notice",
|
"_send_group_notice",
|
||||||
"can_send_image",
|
"can_send_image",
|
||||||
"can_send_record",
|
"can_send_record",
|
||||||
|
"check_url_safely",
|
||||||
"create_group_file_folder",
|
"create_group_file_folder",
|
||||||
"delete_essence_msg",
|
"delete_essence_msg",
|
||||||
|
"delete_friend",
|
||||||
"delete_group_file",
|
"delete_group_file",
|
||||||
"delete_group_folder",
|
"delete_group_folder",
|
||||||
"delete_msg",
|
"delete_msg",
|
||||||
|
"delete_unidirectional_friend",
|
||||||
"download_file",
|
"download_file",
|
||||||
"get_essence_msg_list",
|
"get_essence_msg_list",
|
||||||
"get_forward_msg",
|
"get_forward_msg",
|
||||||
@ -29,14 +32,18 @@ var supportedV11 = []string{
|
|||||||
"get_group_list",
|
"get_group_list",
|
||||||
"get_group_member_info",
|
"get_group_member_info",
|
||||||
"get_group_member_list",
|
"get_group_member_list",
|
||||||
|
"get_group_msg_history",
|
||||||
"get_group_root_files",
|
"get_group_root_files",
|
||||||
|
"get_group_system_msg",
|
||||||
"get_image",
|
"get_image",
|
||||||
"get_login_info",
|
"get_login_info",
|
||||||
"get_msg",
|
"get_msg",
|
||||||
"get_status",
|
"get_status",
|
||||||
"get_stranger_info",
|
"get_stranger_info",
|
||||||
"get_supported_actions",
|
"get_supported_actions",
|
||||||
|
"get_unidirectional_friend_list",
|
||||||
"get_version_info",
|
"get_version_info",
|
||||||
|
"mark_msg_as_read",
|
||||||
"reload_event_filter",
|
"reload_event_filter",
|
||||||
"send_forward_msg",
|
"send_forward_msg",
|
||||||
"send_group_forward_msg",
|
"send_group_forward_msg",
|
||||||
@ -67,11 +74,14 @@ var supportedV12 = []string{
|
|||||||
"_del_group_notice",
|
"_del_group_notice",
|
||||||
"_get_group_notice",
|
"_get_group_notice",
|
||||||
"_send_group_notice",
|
"_send_group_notice",
|
||||||
|
"check_url_safely",
|
||||||
"create_group_file_folder",
|
"create_group_file_folder",
|
||||||
"delete_essence_msg",
|
"delete_essence_msg",
|
||||||
|
"delete_friend",
|
||||||
"delete_group_file",
|
"delete_group_file",
|
||||||
"delete_group_folder",
|
"delete_group_folder",
|
||||||
"delete_msg",
|
"delete_msg",
|
||||||
|
"delete_unidirectional_friend",
|
||||||
"download_file",
|
"download_file",
|
||||||
"get_essence_msg_list",
|
"get_essence_msg_list",
|
||||||
"get_forward_msg",
|
"get_forward_msg",
|
||||||
@ -85,13 +95,17 @@ var supportedV12 = []string{
|
|||||||
"get_group_list",
|
"get_group_list",
|
||||||
"get_group_member_info",
|
"get_group_member_info",
|
||||||
"get_group_member_list",
|
"get_group_member_list",
|
||||||
|
"get_group_msg_history",
|
||||||
"get_group_root_files",
|
"get_group_root_files",
|
||||||
|
"get_group_system_msg",
|
||||||
"get_image",
|
"get_image",
|
||||||
"get_self_info",
|
"get_self_info",
|
||||||
"get_msg",
|
"get_msg",
|
||||||
"get_status",
|
"get_status",
|
||||||
"get_user_info",
|
"get_user_info",
|
||||||
"get_supported_actions",
|
"get_supported_actions",
|
||||||
|
"get_unidirectional_friend_list",
|
||||||
|
"mark_msg_as_read",
|
||||||
"reload_event_filter",
|
"reload_event_filter",
|
||||||
"send_group_sign",
|
"send_group_sign",
|
||||||
"set_essence_msg",
|
"set_essence_msg",
|
||||||
|
Reference in New Issue
Block a user