1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-05 02:30:23 +08:00

finish pins

This commit is contained in:
源文雨
2023-10-12 00:43:15 +09:00
parent 4e7eb32a0a
commit de27ba9f2a
5 changed files with 60 additions and 3 deletions

View File

@@ -19,7 +19,7 @@ func checkrespbaseunsafe(ptr any) error {
return nil
}
//go:generate go run codegen/getopenapiof/main.go ShardWSSGateway User Guild Channel Member RoleMembers GuildRoleList ChannelPermissions Message MessageSetting
//go:generate go run codegen/getopenapiof/main.go ShardWSSGateway User Guild Channel Member RoleMembers GuildRoleList ChannelPermissions Message MessageSetting PinsMessage
// GetOpenAPI 从 ep 获取 json 结构化数据写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase
func (bot *Bot) GetOpenAPI(ep, contenttype string, ptr any) error {
@@ -51,7 +51,7 @@ func (bot *Bot) GetOpenAPI(ep, contenttype string, ptr any) error {
return checkrespbaseunsafe(ptr)
}
//go:generate go run codegen/putopenapiof/main.go GuildRoleChannelID
//go:generate go run codegen/putopenapiof/main.go GuildRoleChannelID PinsMessage
// PutOpenAPI 向 ep 发送 PUT 并获取 json 结构化数据返回写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase
func (bot *Bot) PutOpenAPI(ep, contenttype string, ptr any, body io.Reader) error {

View File

@@ -86,7 +86,7 @@ type ChannelPost struct {
ParentID string `json:"parent_id"`
OwnerID string `json:"owner_id,omitempty"`
PrivateType PrivateType `json:"private_type"`
PrivateUserIds []string `json:"private_user_ids,omitempty"`
PrivateUserIDs []string `json:"private_user_ids,omitempty"`
SpeakPermission SpeakPermission `json:"speak_permission,omitempty"`
ApplicationID string `json:"application_id,omitempty"`
}

View File

@@ -125,3 +125,15 @@ func (bot *Bot) getOpenAPIofMessageSetting(ep string) (*MessageSetting, error) {
}
return &resp.MessageSetting, err
}
func (bot *Bot) getOpenAPIofPinsMessage(ep string) (*PinsMessage, error) {
resp := &struct {
CodeMessageBase
PinsMessage
}{}
err := bot.GetOpenAPI(ep, "", resp)
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return &resp.PinsMessage, err
}

View File

@@ -19,3 +19,15 @@ func (bot *Bot) putOpenAPIofGuildRoleChannelID(ep string, body io.Reader) (*Guil
}
return &resp.GuildRoleChannelID, err
}
func (bot *Bot) putOpenAPIofPinsMessage(ep string, body io.Reader) (*PinsMessage, error) {
resp := &struct {
CodeMessageBase
PinsMessage
}{}
err := bot.PutOpenAPI(ep, "", resp, body)
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return &resp.PinsMessage, err
}

33
openapi_pins.go Normal file
View File

@@ -0,0 +1,33 @@
package nano
// PinsMessage 精华消息对象
//
// https://bot.q.qq.com/wiki/develop/api/openapi/pins/model.html#pinsmessage
type PinsMessage struct {
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
MessageIDs []string `json:"message_ids"`
}
// PinMessageInChannel 添加子频道 channel_id 内的精华消息
//
// https://bot.q.qq.com/wiki/develop/api/openapi/pins/put_pins_message.html
func (bot *Bot) PinMessageInChannel(channelid, messageid string) (*PinsMessage, error) {
return bot.putOpenAPIofPinsMessage("/channels/"+channelid+"/pins/"+messageid, nil)
}
// UnpinMessageInChannel 子频道 channel_id 下指定 message_id 的精华消息
//
// https://bot.q.qq.com/wiki/develop/api/openapi/pins/delete_pins_message.html
//
// 删除子频道内全部精华消息,请将 message_id 设置为 all
func (bot *Bot) UnpinMessageInChannel(channelid, messageid string) error {
return bot.DeleteOpenAPI("/channels/"+channelid+"/pins/"+messageid, "", nil)
}
// GetPinMessagesOfChannel 获取子频道 channel_id 内的精华消息
//
// https://bot.q.qq.com/wiki/develop/api/openapi/pins/get_pins_message.html
func (bot *Bot) GetPinMessagesOfChannel(id string) (*PinsMessage, error) {
return bot.getOpenAPIofPinsMessage("/channels/" + id + "/pins")
}