mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-11 05:30:24 +08:00
finish channel permissions
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run codegen/getopenapiof/main.go ShardWSSGateway User Guild Channel Member RoleMembers GuildRoleList
|
//go:generate go run codegen/getopenapiof/main.go ShardWSSGateway User Guild Channel Member RoleMembers GuildRoleList ChannelPermissions
|
||||||
|
|
||||||
// GetOpenAPI 从 ep 获取 json 结构化数据写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase
|
// GetOpenAPI 从 ep 获取 json 结构化数据写到 ptr, ptr 除 Slice 外必须在开头继承 CodeMessageBase
|
||||||
func (bot *Bot) GetOpenAPI(ep string, ptr any) error {
|
func (bot *Bot) GetOpenAPI(ep string, ptr any) error {
|
||||||
|
|||||||
@@ -91,10 +91,10 @@ type ChannelPost struct {
|
|||||||
ApplicationID string `json:"application_id,omitempty"`
|
ApplicationID string `json:"application_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateChannel 用于在 guild_id 指定的频道下创建一个子频道
|
// CreateChannelInGuild 用于在 guild_id 指定的频道下创建一个子频道
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/channel/post_channels.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/channel/post_channels.html
|
||||||
func (bot *Bot) CreateChannel(id string, config *ChannelPost) (*Channel, error) {
|
func (bot *Bot) CreateChannelInGuild(id string, config *ChannelPost) (*Channel, error) {
|
||||||
return bot.postOpenAPIofChannel("/guilds/"+id+"/channels", WriteBodyFromJSON(config))
|
return bot.postOpenAPIofChannel("/guilds/"+id+"/channels", WriteBodyFromJSON(config))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,17 +109,17 @@ type ChannelPatch struct {
|
|||||||
SpeakPermission *SpeakPermission `json:"speak_permission,omitempty"`
|
SpeakPermission *SpeakPermission `json:"speak_permission,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PatchChannel 修改 channel_id 指定的子频道的信息
|
// PatchChannelOf 修改 channel_id 指定的子频道的信息
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/channel/patch_channel.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/channel/patch_channel.html
|
||||||
func (bot *Bot) PatchChannel(id string, config *ChannelPatch) (*Channel, error) {
|
func (bot *Bot) PatchChannelOf(id string, config *ChannelPatch) (*Channel, error) {
|
||||||
return bot.patchOpenAPIofChannel("/channels/"+id, WriteBodyFromJSON(config))
|
return bot.patchOpenAPIofChannel("/channels/"+id, WriteBodyFromJSON(config))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteChannel 删除 channel_id 指定的子频道
|
// DeleteChannelOf 删除 channel_id 指定的子频道
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/channel/delete_channel.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/channel/delete_channel.html
|
||||||
func (bot *Bot) DeleteChannel(id string) error {
|
func (bot *Bot) DeleteChannelOf(id string) error {
|
||||||
return bot.DeleteOpenAPI("/channels/"+id, nil)
|
return bot.DeleteOpenAPI("/channels/"+id, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,3 +134,47 @@ func (bot *Bot) GetOnlineNumsInChannel(id string) (int, error) {
|
|||||||
err := bot.GetOpenAPI("/channels/"+id+"/online_nums", &resp)
|
err := bot.GetOpenAPI("/channels/"+id+"/online_nums", &resp)
|
||||||
return resp.N, err
|
return resp.N, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChannelPermissions 子频道权限对象
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/model.html
|
||||||
|
type ChannelPermissions struct {
|
||||||
|
ChannelID string `json:"channel_id"`
|
||||||
|
UserID string `json:"user_id"` // UserID 不与 RoleID 同时出现
|
||||||
|
RoleID string `json:"role_id"` // RoleID 不与 UserID 同时出现
|
||||||
|
Permissions string `json:"permissions"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetChannelPermissionsOfUser 获取子频道 channel_id 下用户 user_id 的权限
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/get_channel_permissions.html
|
||||||
|
func (bot *Bot) GetChannelPermissionsOfUser(channelid, userid string) (*ChannelPermissions, error) {
|
||||||
|
return bot.getOpenAPIofChannelPermissions("/channels/" + channelid + "/members/" + userid + "/permissions")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelPermissionsOfUser 修改子频道 channel_id 下用户 user_id 的权限
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/put_channel_permissions.html
|
||||||
|
func (bot *Bot) SetChannelPermissionsOfUser(channelid, userid string, add, remove string) error {
|
||||||
|
return bot.PutOpenAPI("/channels/"+channelid+"/members/"+userid+"/permissions", nil, WriteBodyFromJSON(&struct {
|
||||||
|
A string `json:"add"`
|
||||||
|
R string `json:"remove"`
|
||||||
|
}{add, remove}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetChannelPermissionsOfRole 获取子频道 channel_id 下身份组 role_id 的权限
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/get_channel_roles_permissions.html
|
||||||
|
func (bot *Bot) GetChannelPermissionsOfRole(channelid, roleid string) (*ChannelPermissions, error) {
|
||||||
|
return bot.getOpenAPIofChannelPermissions("/channels/" + channelid + "/roles/" + roleid + "/permissions")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannelPermissionsOfRole 修改子频道 channel_id 下身份组 role_id 的权限
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/channel_permissions/put_channel_roles_permissions.html
|
||||||
|
func (bot *Bot) SetChannelPermissionsOfRole(channelid, roleid string, add, remove string) error {
|
||||||
|
return bot.PutOpenAPI("/channels/"+channelid+"/roles/"+roleid+"/permissions", nil, WriteBodyFromJSON(&struct {
|
||||||
|
A string `json:"add"`
|
||||||
|
R string `json:"remove"`
|
||||||
|
}{add, remove}))
|
||||||
|
}
|
||||||
|
|||||||
@@ -98,3 +98,16 @@ func (bot *Bot) getOpenAPIofGuildRoleList(ep string) (*GuildRoleList, error) {
|
|||||||
}
|
}
|
||||||
return (*GuildRoleList)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
return (*GuildRoleList)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *Bot) getOpenAPIofChannelPermissions(ep string) (*ChannelPermissions, error) {
|
||||||
|
resp := &struct {
|
||||||
|
CodeMessageBase
|
||||||
|
ChannelPermissions
|
||||||
|
}{}
|
||||||
|
err := bot.GetOpenAPI(ep, resp)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, getCallerFuncName())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return (*ChannelPermissions)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ type Member struct {
|
|||||||
Pending bool `json:"pending"`
|
Pending bool `json:"pending"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGuildMembers 获取 guild_id 指定的频道中所有成员的详情列表,支持分页
|
// GetGuildMembersIn 获取 guild_id 指定的频道中所有成员的详情列表,支持分页
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_members.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_members.html
|
||||||
func (bot *Bot) GetGuildMembers(id, after string, limit uint32) (members []Member, err error) {
|
func (bot *Bot) GetGuildMembersIn(id, after string, limit uint32) (members []Member, err error) {
|
||||||
err = bot.GetOpenAPI(WriteHTTPQueryIfNotNil("/guilds/"+id+"/members",
|
err = bot.GetOpenAPI(WriteHTTPQueryIfNotNil("/guilds/"+id+"/members",
|
||||||
"after", after,
|
"after", after,
|
||||||
"limit", limit,
|
"limit", limit,
|
||||||
@@ -35,29 +35,29 @@ type RoleMembers struct {
|
|||||||
Next string `json:"next"`
|
Next string `json:"next"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRoleMembers 获取 guild_id 频道中指定role_id身份组下所有成员的详情列表,支持分页
|
// GetRoleMembersOf 获取 guild_id 频道中指定role_id身份组下所有成员的详情列表,支持分页
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html
|
||||||
func (bot *Bot) GetRoleMembers(guildid, roleid, startindex string, limit uint32) (*RoleMembers, error) {
|
func (bot *Bot) GetRoleMembersOf(guildid, roleid, startindex string, limit uint32) (*RoleMembers, error) {
|
||||||
return bot.getOpenAPIofRoleMembers(WriteHTTPQueryIfNotNil("/guilds/"+guildid+"/roles/"+roleid+"/members",
|
return bot.getOpenAPIofRoleMembers(WriteHTTPQueryIfNotNil("/guilds/"+guildid+"/roles/"+roleid+"/members",
|
||||||
"start_index", startindex,
|
"start_index", startindex,
|
||||||
"limit", limit,
|
"limit", limit,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGuildMember 获取 guild_id 指定的频道中 user_id 对应成员的详细信息
|
// GetGuildMemberOf 获取 guild_id 指定的频道中 user_id 对应成员的详细信息
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_member.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_member.html
|
||||||
func (bot *Bot) GetGuildMember(guildid, userid string) (*Member, error) {
|
func (bot *Bot) GetGuildMemberOf(guildid, userid string) (*Member, error) {
|
||||||
return bot.getOpenAPIofMember("/guilds/" + guildid + "/members/" + userid)
|
return bot.getOpenAPIofMember("/guilds/" + guildid + "/members/" + userid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteGuildMember 删除 guild_id 指定的频道下的成员 user_id
|
// DeleteGuildMemberOf 删除 guild_id 指定的频道下的成员 user_id
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/member/delete_member.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/member/delete_member.html
|
||||||
//
|
//
|
||||||
// - delhistmsgdays: 消息撤回时间范围仅支持固定的天数:3,7,15,30。 特殊的时间范围:-1: 撤回全部消息。默认值为0不撤回任何消息。
|
// - delhistmsgdays: 消息撤回时间范围仅支持固定的天数:3,7,15,30。 特殊的时间范围:-1: 撤回全部消息。默认值为0不撤回任何消息。
|
||||||
func (bot *Bot) DeleteGuildMember(guildid, userid string, addblklst bool, delhistmsgdays int) error {
|
func (bot *Bot) DeleteGuildMemberOf(guildid, userid string, addblklst bool, delhistmsgdays int) error {
|
||||||
return bot.DeleteOpenAPI("/guilds/"+guildid+"/members/"+userid, WriteBodyFromJSON(&struct {
|
return bot.DeleteOpenAPI("/guilds/"+guildid+"/members/"+userid, WriteBodyFromJSON(&struct {
|
||||||
A bool `json:"add_blacklist"`
|
A bool `json:"add_blacklist"`
|
||||||
D int `json:"delete_history_msg_days"`
|
D int `json:"delete_history_msg_days"`
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ type GuildRoleList struct {
|
|||||||
RoleNumLimit string `json:"role_num_limit"`
|
RoleNumLimit string `json:"role_num_limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGuildRoleList 获取 guild_id指定的频道下的身份组列表
|
// GetGuildRoleListIn 获取 guild_id 指定的频道下的身份组列表
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild_roles.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/get_guild_roles.html
|
||||||
func (bot *Bot) GetGuildRoleList(id string) (*GuildRoleList, error) {
|
func (bot *Bot) GetGuildRoleListIn(id string) (*GuildRoleList, error) {
|
||||||
return bot.getOpenAPIofGuildRoleList("/guilds/" + id + "/roles")
|
return bot.getOpenAPIofGuildRoleList("/guilds/" + id + "/roles")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,12 +52,12 @@ type GuildRoleCreate struct {
|
|||||||
Role Role `json:"role"`
|
Role Role `json:"role"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGuildRole 创建频道身份组
|
// CreateGuildRoleOf 创建频道身份组
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/post_guild_role.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/post_guild_role.html
|
||||||
//
|
//
|
||||||
// 参数为非必填,但至少需要传其中之一,默认为空或 0
|
// 参数为非必填,但至少需要传其中之一,默认为空或 0
|
||||||
func (bot *Bot) CreateGuildRole(id string, name string, color uint32, hoist int32) (*GuildRoleCreate, error) {
|
func (bot *Bot) CreateGuildRoleOf(id string, name string, color uint32, hoist int32) (*GuildRoleCreate, error) {
|
||||||
return bot.postOpenAPIofGuildRoleCreate("/guilds/"+id+"/roles", WriteBodyFromJSON(&struct {
|
return bot.postOpenAPIofGuildRoleCreate("/guilds/"+id+"/roles", WriteBodyFromJSON(&struct {
|
||||||
N string `json:"name,omitempty"`
|
N string `json:"name,omitempty"`
|
||||||
C uint32 `json:"color,omitempty"`
|
C uint32 `json:"color,omitempty"`
|
||||||
@@ -74,10 +74,10 @@ type GuildRolePatch struct {
|
|||||||
Role Role `json:"role"`
|
Role Role `json:"role"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PatchGuildRole 修改频道 guild_id 下 role_id 指定的身份组
|
// PatchGuildRoleOf 修改频道 guild_id 下 role_id 指定的身份组
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/patch_guild_role.html
|
// 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) {
|
func (bot *Bot) PatchGuildRoleOf(guildid, roleid string, name string, color uint32, hoist int32) (*GuildRolePatch, error) {
|
||||||
return bot.patchOpenAPIofGuildRolePatch("/guilds/"+guildid+"/roles/"+roleid, WriteBodyFromJSON(&struct {
|
return bot.patchOpenAPIofGuildRolePatch("/guilds/"+guildid+"/roles/"+roleid, WriteBodyFromJSON(&struct {
|
||||||
N string `json:"name,omitempty"`
|
N string `json:"name,omitempty"`
|
||||||
C uint32 `json:"color,omitempty"`
|
C uint32 `json:"color,omitempty"`
|
||||||
@@ -85,7 +85,10 @@ func (bot *Bot) PatchGuildRole(guildid, roleid string, name string, color uint32
|
|||||||
}{name, color, hoist}))
|
}{name, color, hoist}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *Bot) DeleteGuildRole(guildid, roleid string) error {
|
// DeleteGuildRoleOf 删除频道 guild_id下 role_id 对应的身份组
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/delete_guild_role.html
|
||||||
|
func (bot *Bot) DeleteGuildRoleOf(guildid, roleid string) error {
|
||||||
return bot.DeleteOpenAPI("/guilds/"+guildid+"/roles/"+roleid, nil)
|
return bot.DeleteOpenAPI("/guilds/"+guildid+"/roles/"+roleid, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,12 +101,12 @@ type GuildRoleChannelID struct {
|
|||||||
} `json:"channel"`
|
} `json:"channel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRoleToMember 将频道guild_id下的用户 user_id 添加到身份组 role_id
|
// AddRoleToMemberOfGuild 将频道 guild_id 下的用户 user_id 添加到身份组 role_id
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/put_guild_member_role.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/put_guild_member_role.html
|
||||||
//
|
//
|
||||||
// 返回 channel_id
|
// 返回 channel_id
|
||||||
func (bot *Bot) AddRoleToMember(guildid, userid, roleid, channelid string) (string, error) {
|
func (bot *Bot) AddRoleToMemberOfGuild(guildid, userid, roleid, channelid string) (string, error) {
|
||||||
var body io.Reader
|
var body io.Reader
|
||||||
if roleid == RoleIDChannelAdmin {
|
if roleid == RoleIDChannelAdmin {
|
||||||
if channelid == "" {
|
if channelid == "" {
|
||||||
@@ -122,10 +125,10 @@ func (bot *Bot) AddRoleToMember(guildid, userid, roleid, channelid string) (stri
|
|||||||
return r.Channel.ID, nil
|
return r.Channel.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveRoleFromMember 将用户 user_id 从 频道 guild_id 的 role_id 身份组中移除
|
// RemoveRoleFromMemberOfGuild 将用户 user_id 从 频道 guild_id 的 role_id 身份组中移除
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/delete_guild_member_role.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/guild/delete_guild_member_role.html
|
||||||
func (bot *Bot) RemoveRoleFromMember(guildid, userid, roleid, channelid string) error {
|
func (bot *Bot) RemoveRoleFromMemberOfGuild(guildid, userid, roleid, channelid string) error {
|
||||||
var body io.Reader
|
var body io.Reader
|
||||||
if roleid == RoleIDChannelAdmin {
|
if roleid == RoleIDChannelAdmin {
|
||||||
if channelid == "" {
|
if channelid == "" {
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ type User struct {
|
|||||||
UnionUserAccount string `json:"union_user_account"`
|
UnionUserAccount string `json:"union_user_account"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMe 获取当前用户(机器人)详情
|
// GetMyInfo 获取当前用户(机器人)详情
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/user/me.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/user/me.html
|
||||||
func (bot *Bot) GetMe() (*User, error) {
|
func (bot *Bot) GetMyInfo() (*User, error) {
|
||||||
return bot.getOpenAPIofUser("/users/@me")
|
return bot.getOpenAPIofUser("/users/@me")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user