mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-06 19:20:24 +08:00
finish half of role
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//go:generate go run codegen/getopenapiof/main.go ShardWSSGateway User Guild Channel Member RoleMembers
|
||||
//go:generate go run codegen/getopenapiof/main.go ShardWSSGateway User Guild Channel Member RoleMembers GuildRoleList
|
||||
|
||||
// GetOpenAPI 从 ep 获取 json 结构化数据写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase
|
||||
func (bot *Bot) GetOpenAPI(ep string, ptr any) error {
|
||||
@@ -67,7 +67,7 @@ func (bot *Bot) DeleteOpenAPI(ep string, body io.Reader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//go:generate go run codegen/postopenapiof/main.go Channel
|
||||
//go:generate go run codegen/postopenapiof/main.go Channel GuildRoleCreate
|
||||
|
||||
// PostOpenAPI 从 ep 得到 json 结构化数据返回值写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase
|
||||
func (bot *Bot) PostOpenAPI(ep string, ptr any, body io.Reader) error {
|
||||
@@ -103,7 +103,7 @@ func (bot *Bot) PostOpenAPI(ep string, ptr any, body io.Reader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//go:generate go run codegen/patchopenapiof/main.go Channel
|
||||
//go:generate go run codegen/patchopenapiof/main.go Channel GuildRolePatch
|
||||
|
||||
// PatchOpenAPI 从 ep 得到 json 结构化数据返回值写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase
|
||||
func (bot *Bot) PatchOpenAPI(ep string, ptr any, body io.Reader) error {
|
||||
|
||||
@@ -85,3 +85,16 @@ func (bot *Bot) getOpenAPIofRoleMembers(ep string) (*RoleMembers, error) {
|
||||
}
|
||||
return (*RoleMembers)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||
}
|
||||
|
||||
func (bot *Bot) getOpenAPIofGuildRoleList(ep string) (*GuildRoleList, error) {
|
||||
resp := &struct {
|
||||
CodeMessageBase
|
||||
GuildRoleList
|
||||
}{}
|
||||
err := bot.GetOpenAPI(ep, resp)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, getCallerFuncName())
|
||||
return nil, err
|
||||
}
|
||||
return (*GuildRoleList)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||
}
|
||||
|
||||
@@ -21,3 +21,16 @@ func (bot *Bot) patchOpenAPIofChannel(ep string, body io.Reader) (*Channel, erro
|
||||
}
|
||||
return (*Channel)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||
}
|
||||
|
||||
func (bot *Bot) patchOpenAPIofGuildRolePatch(ep string, body io.Reader) (*GuildRolePatch, error) {
|
||||
resp := &struct {
|
||||
CodeMessageBase
|
||||
GuildRolePatch
|
||||
}{}
|
||||
err := bot.PatchOpenAPI(ep, resp, body)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, getCallerFuncName())
|
||||
return nil, err
|
||||
}
|
||||
return (*GuildRolePatch)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||
}
|
||||
|
||||
@@ -21,3 +21,16 @@ func (bot *Bot) postOpenAPIofChannel(ep string, body io.Reader) (*Channel, error
|
||||
}
|
||||
return (*Channel)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||
}
|
||||
|
||||
func (bot *Bot) postOpenAPIofGuildRoleCreate(ep string, body io.Reader) (*GuildRoleCreate, error) {
|
||||
resp := &struct {
|
||||
CodeMessageBase
|
||||
GuildRoleCreate
|
||||
}{}
|
||||
err := bot.PostOpenAPI(ep, resp, body)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, getCallerFuncName())
|
||||
return nil, err
|
||||
}
|
||||
return (*GuildRoleCreate)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ type Member struct {
|
||||
// GetGuildMembers 获取 guild_id 指定的频道中所有成员的详情列表,支持分页
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_members.html
|
||||
func (bot *Bot) GetGuildMembers(id, after string, limit int) (members []Member, err error) {
|
||||
func (bot *Bot) GetGuildMembers(id, after string, limit uint32) (members []Member, err error) {
|
||||
err = bot.GetOpenAPI(WriteHTTPQueryIfNotNil("/guilds/"+id+"/members",
|
||||
"after", after,
|
||||
"limit", limit,
|
||||
@@ -38,7 +38,7 @@ type RoleMembers struct {
|
||||
// GetRoleMembers 获取 guild_id 频道中指定role_id身份组下所有成员的详情列表,支持分页
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html
|
||||
func (bot *Bot) GetRoleMembers(guildid, roleid, startindex string, limit int) (*RoleMembers, error) {
|
||||
func (bot *Bot) GetRoleMembers(guildid, roleid, startindex string, limit uint32) (*RoleMembers, error) {
|
||||
return bot.getOpenAPIofRoleMembers(WriteHTTPQueryIfNotNil("/guilds/"+guildid+"/roles/"+roleid+"/members",
|
||||
"start_index", startindex,
|
||||
"limit", limit,
|
||||
|
||||
74
openapi_role.go
Normal file
74
openapi_role.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package nano
|
||||
|
||||
// Role 频道身份组对象
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/role_model.html
|
||||
type Role struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color uint32 `json:"color"`
|
||||
Hoist uint32 `json:"hoist"`
|
||||
Number uint32 `json:"number"`
|
||||
MemberLimit uint32 `json:"member_limit"`
|
||||
}
|
||||
|
||||
// GuildRoleList 频道身份组列表
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild_roles.html#%E8%BF%94%E5%9B%9E
|
||||
type GuildRoleList struct {
|
||||
GuildID string `json:"guild_id"`
|
||||
Roles []Role `json:"roles"`
|
||||
RoleNumLimit string `json:"role_num_limit"`
|
||||
}
|
||||
|
||||
// GetGuildRoleList 获取 guild_id指定的频道下的身份组列表
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild_roles.html
|
||||
func (bot *Bot) GetGuildRoleList(id string) (*GuildRoleList, error) {
|
||||
return bot.getOpenAPIofGuildRoleList("/guilds/" + id + "/roles")
|
||||
}
|
||||
|
||||
// GuildRoleCreate 创建频道身份组响应
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/post_guild_role.html#%E8%BF%94%E5%9B%9E
|
||||
type GuildRoleCreate struct {
|
||||
RoleID string `json:"role_id"`
|
||||
Role Role `json:"role"`
|
||||
}
|
||||
|
||||
// CreateGuildRole 创建频道身份组
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/post_guild_role.html
|
||||
//
|
||||
// 参数为非必填,但至少需要传其中之一,默认为空或 0
|
||||
func (bot *Bot) CreateGuildRole(id string, name string, color uint32, hoist int32) (*GuildRoleCreate, error) {
|
||||
return bot.postOpenAPIofGuildRoleCreate("/guilds/"+id+"/roles", WriteBodyFromJSON(&struct {
|
||||
N string `json:"name,omitempty"`
|
||||
C uint32 `json:"color,omitempty"`
|
||||
H int32 `json:"hoist,omitempty"`
|
||||
}{name, color, hoist}))
|
||||
}
|
||||
|
||||
// GuildRolePatch 修改频道身份组
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_role.html#%E8%BF%94%E5%9B%9E
|
||||
type GuildRolePatch struct {
|
||||
GuildID string `json:"guild_id"`
|
||||
RoleID string `json:"role_id"`
|
||||
Role Role `json:"role"`
|
||||
}
|
||||
|
||||
// PatchGuildRole 修改频道 guild_id 下 role_id 指定的身份组
|
||||
//
|
||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_role.html
|
||||
func (bot *Bot) PatchGuildRole(guildid, roleid string, name string, color uint32, hoist int32) (*GuildRolePatch, error) {
|
||||
return bot.patchOpenAPIofGuildRolePatch("/guilds/"+guildid+"/roles/"+roleid, WriteBodyFromJSON(&struct {
|
||||
N string `json:"name,omitempty"`
|
||||
C uint32 `json:"color,omitempty"`
|
||||
H int32 `json:"hoist,omitempty"`
|
||||
}{name, color, hoist}))
|
||||
}
|
||||
|
||||
func (bot *Bot) DeleteGuildRole(guildid, roleid string) error {
|
||||
return bot.DeleteOpenAPI("/guilds/"+guildid+"/roles/"+roleid, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user