db

package
v1.2.1-rc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DatabaseDisabledError = errors.New("database disabled")

DatabaseDisabledError 没有可用的db

Functions

func Init

func Init()

Init 加载所有后端配置文件

func InsertGroupMessage

func InsertGroupMessage(m *StoredGroupMessage) error

func InsertGuildChannelMessage

func InsertGuildChannelMessage(m *StoredGuildChannelMessage) error

func InsertPrivateMessage

func InsertPrivateMessage(m *StoredPrivateMessage) error

func Open

func Open() error

func Register

func Register(name string, init func(yaml.Node) Database)

Register 添加数据库后端

func ToGlobalID

func ToGlobalID(code int64, msgID int32) int32

ToGlobalID 构建`code`-`msgID`的字符串并返回其CRC32 Checksum的值

Types

type Database

type Database interface {
	// Open 初始化数据库
	Open() error

	// GetMessageByGlobalID 通过 GlobalID 来获取消息
	GetMessageByGlobalID(int32) (StoredMessage, error)
	// GetGroupMessageByGlobalID 通过 GlobalID 来获取群消息
	GetGroupMessageByGlobalID(int32) (*StoredGroupMessage, error)
	// GetPrivateMessageByGlobalID 通过 GlobalID 来获取私聊消息
	GetPrivateMessageByGlobalID(int32) (*StoredPrivateMessage, error)
	// GetGuildChannelMessageByID 通过 ID 来获取频道消息
	GetGuildChannelMessageByID(string) (*StoredGuildChannelMessage, error)

	// InsertGroupMessage 向数据库写入新的群消息
	InsertGroupMessage(*StoredGroupMessage) error
	// InsertPrivateMessage 向数据库写入新的私聊消息
	InsertPrivateMessage(*StoredPrivateMessage) error
	// InsertGuildChannelMessage 向数据库写入新的频道消息
	InsertGuildChannelMessage(*StoredGuildChannelMessage) error
}

Database 数据库操作接口定义

type QuotedInfo

type QuotedInfo struct {
	PrevID        string       `bson:"prevId" yaml:"-"`
	PrevGlobalID  int32        `bson:"prevGlobalId" yaml:"-"`
	QuotedContent []global.MSG `bson:"quotedContent" yaml:"quoted_content"`
}

QuotedInfo 引用回复

type StoredGroupMessage

type StoredGroupMessage struct {
	ID          string                  `bson:"_id" yaml:"-"`
	GlobalID    int32                   `bson:"globalId" yaml:"-"`
	Attribute   *StoredMessageAttribute `bson:"attribute" yaml:"-"`
	SubType     string                  `bson:"subType" yaml:"-"`
	QuotedInfo  *QuotedInfo             `bson:"quotedInfo" yaml:"-"`
	GroupCode   int64                   `bson:"groupCode" yaml:"-"`
	AnonymousID string                  `bson:"anonymousId" yaml:"-"`
	Content     []global.MSG            `bson:"content" yaml:"content"`
}

StoredGroupMessage 持久化群消息

func GetGroupMessageByGlobalID

func GetGroupMessageByGlobalID(id int32) (*StoredGroupMessage, error)

func (*StoredGroupMessage) GetAttribute

func (m *StoredGroupMessage) GetAttribute() *StoredMessageAttribute

func (*StoredGroupMessage) GetContent

func (m *StoredGroupMessage) GetContent() []global.MSG

func (*StoredGroupMessage) GetGlobalID

func (m *StoredGroupMessage) GetGlobalID() int32

func (*StoredGroupMessage) GetID

func (m *StoredGroupMessage) GetID() string

func (*StoredGroupMessage) GetType

func (m *StoredGroupMessage) GetType() string

type StoredGuildChannelMessage

type StoredGuildChannelMessage struct {
	ID         string                       `bson:"_id" yaml:"-"`
	Attribute  *StoredGuildMessageAttribute `bson:"attribute" yaml:"-"`
	GuildID    uint64                       `bson:"guildId" yaml:"-"`
	ChannelID  uint64                       `bson:"channelId" yaml:"-"`
	QuotedInfo *QuotedInfo                  `bson:"quotedInfo" yaml:"-"`
	Content    []global.MSG                 `bson:"content" yaml:"content"`
}

StoredGuildChannelMessage 持久化频道消息

func GetGuildChannelMessageByID

func GetGuildChannelMessageByID(id string) (*StoredGuildChannelMessage, error)

type StoredGuildMessageAttribute

type StoredGuildMessageAttribute struct {
	MessageSeq   uint64 `bson:"messageSeq" yaml:"-"`
	InternalID   uint64 `bson:"internalId" yaml:"-"`
	SenderTinyID uint64 `bson:"senderTinyId" yaml:"-"`
	SenderName   string `bson:"senderName" yaml:"-"`
	Timestamp    int64  `bson:"timestamp" yaml:"-"`
}

StoredGuildMessageAttribute 持久化频道消息属性

type StoredMessage

type StoredMessage interface {
	GetID() string
	GetType() string
	GetGlobalID() int32
	GetAttribute() *StoredMessageAttribute
	GetContent() []global.MSG
}

func GetMessageByGlobalID

func GetMessageByGlobalID(id int32) (StoredMessage, error)

type StoredMessageAttribute

type StoredMessageAttribute struct {
	MessageSeq int32  `bson:"messageSeq" yaml:"-"`
	InternalID int32  `bson:"internalId" yaml:"-"`
	SenderUin  int64  `bson:"senderUin" yaml:"-"`
	SenderName string `bson:"senderName" yaml:"-"`
	Timestamp  int64  `bson:"timestamp" yaml:"-"`
}

StoredMessageAttribute 持久化消息属性

type StoredPrivateMessage

type StoredPrivateMessage struct {
	ID         string                  `bson:"_id" yaml:"-"`
	GlobalID   int32                   `bson:"globalId" yaml:"-"`
	Attribute  *StoredMessageAttribute `bson:"attribute" yaml:"-"`
	SubType    string                  `bson:"subType" yaml:"-"`
	QuotedInfo *QuotedInfo             `bson:"quotedInfo" yaml:"-"`
	SessionUin int64                   `bson:"sessionUin" yaml:"-"`
	TargetUin  int64                   `bson:"targetUin" yaml:"-"`
	Content    []global.MSG            `bson:"content" yaml:"content"`
}

StoredPrivateMessage 持久化私聊消息

func GetPrivateMessageByGlobalID

func GetPrivateMessageByGlobalID(id int32) (*StoredPrivateMessage, error)

func (*StoredPrivateMessage) GetAttribute

func (m *StoredPrivateMessage) GetAttribute() *StoredMessageAttribute

func (*StoredPrivateMessage) GetContent

func (m *StoredPrivateMessage) GetContent() []global.MSG

func (*StoredPrivateMessage) GetGlobalID

func (m *StoredPrivateMessage) GetGlobalID() int32

func (*StoredPrivateMessage) GetID

func (m *StoredPrivateMessage) GetID() string

func (*StoredPrivateMessage) GetType

func (m *StoredPrivateMessage) GetType() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL