github.com/fumiama/NanoBot@v0.0.0-20231122134259-c22d8183efca/openapi_dms.go (about) 1 package nano 2 3 import "github.com/sirupsen/logrus" 4 5 // DMS 私信会话对象 6 // 7 // https://bot.q.qq.com/wiki/develop/api/openapi/dms/model.html 8 type DMS struct { 9 GuildID string `json:"guild_id"` 10 ChannelID string `json:"channel_id"` 11 CreateTime string `json:"create_time"` // 创建私信会话时间戳 12 } 13 14 // CreatePrivateChat 机器人和在同一个频道内的成员创建私信会话 15 // 16 // https://bot.q.qq.com/wiki/develop/api/openapi/dms/post_dms.html 17 func (bot *Bot) CreatePrivateChat(guildid, userid string) (*DMS, error) { 18 return bot.postOpenAPIofDMS("/users/@me/dms", "", WriteBodyFromJSON(&struct { 19 R string `json:"recipient_id"` 20 S string `json:"source_guild_id"` 21 }{userid, guildid})) 22 } 23 24 // PostMessageToUser 发送私信消息,前提是已经创建了私信会话 25 // 26 // https://bot.q.qq.com/wiki/develop/api/openapi/dms/post_dms_messages.html 27 // 28 // - 私信的 guild_id 在创建私信会话时以及私信消息事件中获取 29 func (bot *Bot) PostMessageToUser(id string, content *MessagePost) (*Message, error) { 30 logrus.Infoln(getLogHeader(), "<= [私]频道:", id+",", content) 31 return bot.postMessageTo("/dms/"+id+"/messages", content) 32 } 33 34 // DeleteMessageOfUser 撤回私信频道 guild_id 中 message_id 指定的私信消息, 只能用于撤回机器人自己发送的私信 35 // 36 // https://bot.q.qq.com/wiki/develop/api/openapi/dms/delete_dms.html 37 func (bot *Bot) DeleteMessageOfUser(guildid, messageid string, hidetip bool) error { 38 return bot.DeleteOpenAPI(WriteHTTPQueryIfNotNil("/dms/"+guildid+"/messages/"+messageid, 39 "hidetip", hidetip, 40 ), "", nil) 41 }