github.com/fumiama/NanoBot@v0.0.0-20231122134259-c22d8183efca/openapi_user.go (about)

     1  package nano
     2  
     3  // User 用户对象
     4  //
     5  // https://bot.q.qq.com/wiki/develop/api/openapi/user/model.html
     6  type User struct {
     7  	ID               string `json:"id"`
     8  	Username         string `json:"username"`
     9  	Avatar           string `json:"avatar"`
    10  	Bot              bool   `json:"bot"`
    11  	UnionOpenid      string `json:"union_openid"`
    12  	UnionUserAccount string `json:"union_user_account"`
    13  	UserOpenID       string `json:"user_openid"`
    14  	MemberOpenID     string `json:"member_openid"`
    15  }
    16  
    17  // At 返回 <@!u.ID>
    18  func (u *User) At() string {
    19  	return "<@!" + u.ID + ">"
    20  }
    21  
    22  // AtMe 返回 <@!bot.ready.User.ID>
    23  func (bot *Bot) AtMe() string {
    24  	return "<@!" + bot.ready.User.ID + ">"
    25  }
    26  
    27  // GetMyInfo 获取当前用户(机器人)详情
    28  //
    29  // https://bot.q.qq.com/wiki/develop/api/openapi/user/me.html
    30  func (bot *Bot) GetMyInfo() (*User, error) {
    31  	return bot.getOpenAPIofUser("/users/@me")
    32  }
    33  
    34  // GetMyGuilds 获取当前用户(机器人)频道列表,支持分页
    35  //
    36  // https://bot.q.qq.com/wiki/develop/api/openapi/user/guilds.html
    37  func (bot *Bot) GetMyGuilds(before, after string, limit int) (guilds []Guild, err error) {
    38  	err = bot.GetOpenAPI(WriteHTTPQueryIfNotNil("/users/@me/guilds",
    39  		"before", before,
    40  		"after", after,
    41  		"limit", limit,
    42  	), "", &guilds)
    43  	return
    44  }