mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-11 05:30:24 +08:00
finish message
This commit is contained in:
@@ -1,4 +1,92 @@
|
|||||||
package nano
|
package nano
|
||||||
|
|
||||||
|
// MessageMarkdown https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagemarkdown
|
||||||
type MessageMarkdown struct {
|
type MessageMarkdown struct {
|
||||||
|
TemplateID int `json:"template_id,omitempty"`
|
||||||
|
CustomTemplateID string `json:"custom_template_id,omitempty"`
|
||||||
|
Params []MessageMarkdownParams `json:"params,omitempty"`
|
||||||
|
Content string `json:"content,omitempty"` // 原生 markdown 内容,与上面三个参数互斥,参数都传值将报错
|
||||||
|
}
|
||||||
|
|
||||||
|
// MessageMarkdownParams https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagemarkdownparams
|
||||||
|
type MessageMarkdownParams struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Values []string `json:"values"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MessageKeyboard https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagekeyboard
|
||||||
|
type MessageKeyboard struct {
|
||||||
|
ID string `json:"id,omitempty"`
|
||||||
|
Content *InlineKeyboard `json:"content,omitempty"` // 自定义 keyboard 内容,与 id 参数互斥,参数都传值将报错
|
||||||
|
}
|
||||||
|
|
||||||
|
// InlineKeyboard 消息按钮对象
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html
|
||||||
|
type InlineKeyboard struct {
|
||||||
|
Rows []InlineKeyboardRow `json:"rows"`
|
||||||
|
BotAppID int `json:"bot_appid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InlineKeyboardRow https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#inlinekeyboardrow
|
||||||
|
type InlineKeyboardRow struct {
|
||||||
|
Buttons []InlineKeyboardButton `json:"buttons"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InlineKeyboardButton https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#button
|
||||||
|
type InlineKeyboardButton struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
RenderData InlineKeyboardButtonRenderData `json:"render_data"`
|
||||||
|
Action InlineKeyboardButtonAction `json:"action"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InlineKeyboardButtonRenderDataStyle https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#renderstyle
|
||||||
|
type InlineKeyboardButtonRenderDataStyle int
|
||||||
|
|
||||||
|
const (
|
||||||
|
InlineKeyboardButtonRenderDataStyleGray InlineKeyboardButtonRenderDataStyle = iota
|
||||||
|
InlineKeyboardButtonRenderDataStyleBlue
|
||||||
|
)
|
||||||
|
|
||||||
|
// InlineKeyboardButtonRenderData https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#renderdata
|
||||||
|
type InlineKeyboardButtonRenderData struct {
|
||||||
|
Label string `json:"label"`
|
||||||
|
VisitedLabel string `json:"visited_label"`
|
||||||
|
Style InlineKeyboardButtonRenderDataStyle `json:"style"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InlineKeyboardButtonActionType https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#actiontype
|
||||||
|
type InlineKeyboardButtonActionType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
InlineKeyboardButtonActionTypeHTTP InlineKeyboardButtonActionType = iota
|
||||||
|
InlineKeyboardButtonActionTypeCallback
|
||||||
|
InlineKeyboardButtonActionTypeAtBot
|
||||||
|
)
|
||||||
|
|
||||||
|
// InlineKeyboardButtonAction https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#action
|
||||||
|
type InlineKeyboardButtonAction struct {
|
||||||
|
Type InlineKeyboardButtonActionType `json:"type"`
|
||||||
|
Permission InlineKeyboardButtonActionPermission `json:"permission"`
|
||||||
|
ClickLimit int `json:"click_limit"`
|
||||||
|
UnsupportTips string `json:"unsupport_tips"`
|
||||||
|
Data string `json:"data"`
|
||||||
|
AtBotShowChannelList bool `json:"at_bot_show_channel_list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InlineKeyboardButtonActionPermissionType https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#permissiontype
|
||||||
|
type InlineKeyboardButtonActionPermissionType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
InlineKeyboardButtonActionPermissionTypeShimeiUser InlineKeyboardButtonActionPermissionType = iota
|
||||||
|
InlineKeyboardButtonActionPermissionTypeAdmin
|
||||||
|
InlineKeyboardButtonActionPermissionTypeAll
|
||||||
|
InlineKeyboardButtonActionPermissionTypeShimeiRole
|
||||||
|
)
|
||||||
|
|
||||||
|
// InlineKeyboardButtonActionPermission https://bot.q.qq.com/wiki/develop/api/openapi/message/message_keyboard.html#permission
|
||||||
|
type InlineKeyboardButtonActionPermission struct {
|
||||||
|
Type InlineKeyboardButtonActionPermissionType `json:"type"`
|
||||||
|
SpecifyRoleIDs []string `json:"specify_role_ids"`
|
||||||
|
SpecifyUserIDs []string `json:"specify_user_ids"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import "time"
|
|||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/member/model.html
|
// https://bot.q.qq.com/wiki/develop/api/openapi/member/model.html
|
||||||
type Member struct {
|
type Member struct {
|
||||||
GuildID string `json:"guild_id"` // MemberWithGuildID only
|
GuildID string `json:"guild_id"` // MemberWithGuildID only
|
||||||
User User `json:"user"`
|
User *User `json:"user"`
|
||||||
Nick string `json:"nick"`
|
Nick string `json:"nick"`
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
JoinedAt time.Time `json:"joined_at"`
|
JoinedAt time.Time `json:"joined_at"`
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package nano
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -23,13 +24,13 @@ type Message struct {
|
|||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
EditedTimestamp time.Time `json:"edited_timestamp"`
|
EditedTimestamp time.Time `json:"edited_timestamp"`
|
||||||
MentionEveryone bool `json:"mention_everyone"`
|
MentionEveryone bool `json:"mention_everyone"`
|
||||||
Author User `json:"author"`
|
Author *User `json:"author"`
|
||||||
Attachments []MessageAttachment `json:"attachments"`
|
Attachments []MessageAttachment `json:"attachments"`
|
||||||
Embeds []MessageEmbed `json:"embeds"`
|
Embeds []MessageEmbed `json:"embeds"`
|
||||||
Member Member `json:"member"`
|
Member *Member `json:"member"`
|
||||||
Ark MessageArk `json:"ark"`
|
Ark *MessageArk `json:"ark"`
|
||||||
SeqInChannel string `json:"seq_in_channel"`
|
SeqInChannel string `json:"seq_in_channel"`
|
||||||
MessageReference MessageReference `json:"message_reference"`
|
MessageReference *MessageReference `json:"message_reference"`
|
||||||
SrcGuildID string `json:"src_guild_id"`
|
SrcGuildID string `json:"src_guild_id"`
|
||||||
Data *struct {
|
Data *struct {
|
||||||
MessageAudit *MessageAudited `json:"message_audit,omitempty"`
|
MessageAudit *MessageAudited `json:"message_audit,omitempty"`
|
||||||
@@ -38,10 +39,10 @@ type Message struct {
|
|||||||
|
|
||||||
// MessageEmbed https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembed
|
// MessageEmbed https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembed
|
||||||
type MessageEmbed struct {
|
type MessageEmbed struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Prompt string `json:"prompt"`
|
Prompt string `json:"prompt"`
|
||||||
Thumbnail MessageEmbedThumbnail `json:"thumbnail"`
|
Thumbnail *MessageEmbedThumbnail `json:"thumbnail"`
|
||||||
Fields []MessageEmbedField `json:"fields"`
|
Fields []MessageEmbedField `json:"fields"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageEmbedThumbnail https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembedthumbnail
|
// MessageEmbedThumbnail https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messageembedthumbnail
|
||||||
@@ -89,6 +90,12 @@ type MessageReference struct {
|
|||||||
IgnoreGetMessageError bool `json:"ignore_get_message_error"`
|
IgnoreGetMessageError bool `json:"ignore_get_message_error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MessageDelete https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#messagedelete
|
||||||
|
type MessageDelete struct {
|
||||||
|
Message *Message `json:"message"`
|
||||||
|
OpUser *User `json:"op_user"`
|
||||||
|
}
|
||||||
|
|
||||||
// MessageAudited 消息审核对象
|
// MessageAudited 消息审核对象
|
||||||
//
|
//
|
||||||
// https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#%E6%B6%88%E6%81%AF%E5%AE%A1%E6%A0%B8%E5%AF%B9%E8%B1%A1-messageaudited
|
// https://bot.q.qq.com/wiki/develop/api/openapi/message/model.html#%E6%B6%88%E6%81%AF%E5%AE%A1%E6%A0%B8%E5%AF%B9%E8%B1%A1-messageaudited
|
||||||
@@ -116,6 +123,27 @@ type MessagePost struct {
|
|||||||
ReplyMessageID string `json:"msg_id,omitempty"`
|
ReplyMessageID string `json:"msg_id,omitempty"`
|
||||||
ReplyEventID string `json:"event_id,omitempty"`
|
ReplyEventID string `json:"event_id,omitempty"`
|
||||||
Markdown *MessageMarkdown `json:"markdown,omitempty"`
|
Markdown *MessageMarkdown `json:"markdown,omitempty"`
|
||||||
|
KeyBoard *MessageKeyboard `json:"keyboard,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MessageEscape 消息转义
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html
|
||||||
|
func MessageEscape(text string) string {
|
||||||
|
text = strings.ReplaceAll(text, "&", "&")
|
||||||
|
text = strings.ReplaceAll(text, "<", "<")
|
||||||
|
text = strings.ReplaceAll(text, ">", ">")
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
// MessageUnescape 消息解转义
|
||||||
|
//
|
||||||
|
// https://bot.q.qq.com/wiki/develop/api/openapi/message/message_format.html
|
||||||
|
func MessageUnescape(text string) string {
|
||||||
|
text = strings.ReplaceAll(text, "&", "&")
|
||||||
|
text = strings.ReplaceAll(text, "<", "<")
|
||||||
|
text = strings.ReplaceAll(text, ">", ">")
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostMessageToChannel 向 channel_id 指定的子频道发送消息
|
// PostMessageToChannel 向 channel_id 指定的子频道发送消息
|
||||||
|
|||||||
Reference in New Issue
Block a user