database

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 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 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 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
)

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"`
	Public   bool   `gorm:"default:false" json:"public"`

	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 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