database

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMemberToIndexChat added in v0.15.0

func AddMemberToIndexChat(ctx context.Context, chatID int64, userInfo *UserInfo) error

func AllChatIDs added in v0.8.0

func AllChatIDs() []int64

func DeleteApiKey added in v0.16.0

func DeleteApiKey(ctx context.Context, id uint) error

func DeleteIndexChat

func DeleteIndexChat(ctx context.Context, chatID int64) error

func DeleteSubBot

func DeleteSubBot(ctx context.Context, botID int64) error

func Indexed added in v1.1.0

func Indexed(chatID int64) bool

func InitDatabase

func InitDatabase(ctx context.Context) error

func IsMemberInIndexChat added in v0.15.0

func IsMemberInIndexChat(ctx context.Context, chatID int64, userChatID int64) (bool, error)

func RemoveMemberFromIndexChat added in v0.15.0

func RemoveMemberFromIndexChat(ctx context.Context, chatID int64, userInfo *UserInfo) error

func UpdateChannelPts added in v1.1.0

func UpdateChannelPts(ctx context.Context, chatID int64, pts int) error

func UpdateUpdatesState added in v1.1.0

func UpdateUpdatesState(ctx context.Context, state *UpdatesState) error

UpdateUpdatesState 更新 updates state

func UpsertApiKey added in v0.16.0

func UpsertApiKey(ctx context.Context, apiKey *ApiKey) error

func UpsertIndexChat

func UpsertIndexChat(ctx context.Context, IndexChat *IndexChat) error

func UpsertSubBot

func UpsertSubBot(ctx context.Context, subBot *SubBot) error

func UpsertUserInfo

func UpsertUserInfo(ctx context.Context, userInfo *UserInfo) error

func Watching

func Watching(chatID int64) bool

Types

type ApiKey added in v0.16.0

type ApiKey struct {
	ID      uint        `gorm:"primaryKey"`
	Name    string      `json:"name"`
	KeyHash string      `gorm:"uniqueIndex;size:64" json:"-"`
	Chats   []IndexChat `gorm:"many2many:api_key_chats;constraint:OnDelete:CASCADE;joinForeignKey:ApiKeyID;joinReferences:IndexChatID" json:"chats"`
}

ApiKey 表示 Web API 的子 API Key KeyHash 使用 sha256 的十六进制字符串,Chats 通过关联表描述可访问聊天

func GetAllApiKeys added in v0.16.0

func GetAllApiKeys(ctx context.Context) ([]*ApiKey, error)

func GetApiKeyByHash added in v0.16.0

func GetApiKeyByHash(ctx context.Context, hash string) (*ApiKey, error)

func GetApiKeyByID added in v0.16.0

func GetApiKeyByID(ctx context.Context, id uint) (*ApiKey, error)

func (*ApiKey) ChatIDs added in v0.16.0

func (a *ApiKey) ChatIDs() []int64

ChatIDs 返回当前 ApiKey 可访问的聊天 ID 列表

type ChatType

type ChatType int
const (
	ChatTypePrivate ChatType = iota
	ChatTypeChannel          // 频道和超级群
	ChatTypeGroup            // 普通群组
)

type IndexChat

type IndexChat struct {
	ChatID   int64  `gorm:"primaryKey" json:"chat_id"`
	Title    string `json:"title"`
	Username string `json:"username"`
	Type     int    `json:"type"`
	Watching bool   `gorm:"default:true" json:"watching"`
	NoDelete bool   `json:"no_delete"`
	NoOcr    bool   `json:"no_ocr"`
	Public   bool   `gorm:"default:false" json:"public"`
	Pts      int    `gorm:"default:0" json:"pts"` // Channel message box sequence for updates

	Members []UserInfo `` /* 131-byte string literal not displayed */
}

func GetAllIndexChats

func GetAllIndexChats(ctx context.Context) ([]*IndexChat, error)

func GetAllPublicIndexChats

func GetAllPublicIndexChats(ctx context.Context) ([]*IndexChat, error)

func GetIndexChat

func GetIndexChat(ctx context.Context, chatID int64) (*IndexChat, error)

func (*IndexChat) AfterSave

func (ic *IndexChat) AfterSave(tx *gorm.DB) error

func (*IndexChat) BeforeDelete

func (ic *IndexChat) BeforeDelete(tx *gorm.DB) error

type SubBot

type SubBot struct {
	BotID int64 `gorm:"primaryKey"`
	Token string
	// which chats this bot can search
	ChatIDs []int64 `gorm:"serializer:json;type:json"`
}

func GetAllSubBots

func GetAllSubBots(ctx context.Context) ([]*SubBot, error)

func GetSubBot

func GetSubBot(ctx context.Context, botID int64) (*SubBot, error)

func (*SubBot) UserCanSearchChats added in v0.15.0

func (s *SubBot) UserCanSearchChats(ctx context.Context, userId int64) []int64

public + user joined chats

type UpdatesState added in v1.1.0

type UpdatesState struct {
	ID   uint `gorm:"primaryKey"`
	Pts  int  `json:"pts"`  // Common message box sequence (private chats, basic groups)
	Qts  int  `json:"qts"`  // Secondary event sequence (secret chats, certain bot events)
	Date int  `json:"date"` // Unix timestamp
	Seq  int  `json:"seq"`  // Updates sequence number
}

UpdatesState 存储 Telegram updates 的状态信息,用于断线重连时获取错过的消息

func GetUpdatesState added in v1.1.0

func GetUpdatesState(ctx context.Context) (*UpdatesState, error)

GetUpdatesState 获取 updates state,如果不存在则创建一个默认的

type UserInfo

type UserInfo struct {
	ChatID    int64 `gorm:"primaryKey"`
	Username  string
	FirstName string
	LastName  string

	IndexChats []IndexChat `` /* 135-byte string literal not displayed */
}

func GetUserInfo

func GetUserInfo(ctx context.Context, chatID int64) (*UserInfo, error)

func (*UserInfo) FullName added in v0.15.0

func (u *UserInfo) FullName() string

Jump to

Keyboard shortcuts

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