db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin struct {
	Id int64
}

All thinsgs Downthere will store in ram until program kill

type Adminchat

type Adminchat struct {
	Id       int64 `gorm:"primaryKey"`
	Name     string
	Type     string
	UserName string
}

type Config

type Config struct {
	Id         int64 `gorm:"primaryKey"`
	Name       string
	UUID       string `gorm:"not null;uniqueIndex"`
	Type       string
	Password   string
	Active     bool
	UserID     int64 `gorm:"not null;column:user_id"`
	InboundID  int16 `gorm:"not null"`
	OutboundID int16 `gorm:"not null"`

	Inbound  Inbound  `gorm:"foreignKey:ID"`
	Outbound Outbound `gorm:"foreignKey:ID"`

	Usage    C.Bwidth // total usage for this month as byte
	Download C.Bwidth // total download for this month as byte
	Upload   C.Bwidth // total uploads for this month as byte
	Quota    C.Bwidth // changes every day when according to groups user

	LoginLimit int16
}

func (*Config) GetUUID

func (c *Config) GetUUID() uuid.UUID

func (*Config) UpdateUsages

func (c *Config) UpdateUsages(status sbox.Sboxstatus)

type Database

type Database struct {
	*gorm.DB

	Inilized bool
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, logger *zap.Logger, path string) *Database

func (*Database) AddUser

func (d *Database) AddUser(user *User) (*User, error)

func (*Database) Close

func (d *Database) Close() error

func (*Database) DatabasePath

func (d *Database) DatabasePath() string

func (*Database) GetUser

func (d *Database) GetUser(user *tgbotapi.User) (*User, error)

Get userfrom db

func (*Database) Getadminchat

func (d *Database) Getadminchat() (map[int64]string, error)

func (*Database) InitDb

func (d *Database) InitDb() error

func (*Database) QuaryAdmin

func (d *Database) QuaryAdmin(UserID int64) *Admin

func (*Database) RemoveUser

func (d *Database) RemoveUser(user *tgbotapi.User) (*User, error)

return removed user

func (*Database) UpdateUser

func (d *Database) UpdateUser(newuser *tgbotapi.User, Id string) (*User, error)

return old user

type Event

type Event struct {
	ID     int64 `gorm:"primaryKey"`
	Name   string
	UserId int64
}

type Gift

type Gift struct {
	ID      int64 `gorm:"primaryKey"`
	Sender  int64
	Reciver int64

	SendValid   bool // used by watchman
	ReciveValid bool //used by watchman when prosessing batch records in preprosess
	Bandwidth   C.Bwidth
	Date        time.Time
	Valid       bool // used by watchman

	ComQuota C.Bwidth //Maincommon quota which was exist when gift was created

}

func (*Gift) Isgifttimeover

func (u *Gift) Isgifttimeover() bool

type GiftLog

type GiftLog struct {
	ID        int64 `gorm:"primaryKey"`
	SendID    int64
	RecivedID int64
	Bandwidth C.Bwidth
	Date      time.Time
}

type Inbound

type Inbound struct {
	ID   int16  `gorm:"primaryKey"`
	Tag  string `gorm:"type:varchar(100)"`
	Name string
	Type string
	Info string
}

type Metadata

type Metadata struct {
	Id                int32
	CommonQuota       C.Bwidth //common quota for all use which is changing over many condition like verified user count capped user count capped total addtional, how ever actual user quota calculated based on this quota
	Maxconfigcount    int16
	ChannelId         int64
	GroupID           int64
	Channelusercount  int64
	Groupusercount    int64
	VerifiedUserCount int64

	Dbusercount       int64
	LoginLimit        int32
	BandwidthAvelable C.Bwidth

	CheckCount  int32 // current check count
	ResetCount  int32 //neded ChecCounts for reset db
	RefreshRate int32 //rate of refreshing in hours

	PublicDomain string
	PublicIp     string
}

type Outbound

type Outbound struct {
	ID   int16  `gorm:"primaryKey"`
	Tag  string `gorm:"type:varchar(100)"`
	Id   int64
	Name string
	Type string
	Info string
}

type PointLog

type PointLog struct {
	ID          int64
	UserID      int64
	ElpsedPoint int64
	Resong      string
}

type Reffral

type Reffral struct {
	UserId    int64 `gorm:"primaryKey"`
	OwnerID   int64
	CreatedAt time.Time
	Expired   bool
}

type SboxConfigs

type SboxConfigs struct {
	ID       int64 `gorm:"primaryKey"`
	Name     string
	UserID   int64
	ConfPath string
}

type UsageHistory

type UsageHistory struct {
	ID       int64 `gorm:"primaryKey"`
	Name     string
	Download C.Bwidth
	Upload   C.Bwidth
	UserID   int64
	Usage    C.Bwidth
	Date     time.Time
	ConfigID int64
}

type User

type User struct {
	CheckID  uint
	TgID     int64          `gorm:"primaryKey;column:tg_id"`
	Name     string         `gorm:"type:varchar(100)"`
	Username sql.NullString `gorm:"type:varchar(100);column:username"`
	Lang     string         `gorm:"type:varchar(50);column:lang"`

	IsTgPremium   bool `gorm:"column:is_tg_premium"`
	IsInChannel   bool `gorm:"column:is_in_channel"`
	IsInGroup     bool `gorm:"column:is_in_group"`
	IsRemoved     bool `gorm:"column:is_removed"` //common for group and channel
	Restricted    bool `gorm:"column:restricted"` // admin can restrict users
	GroupBanned   bool `gorm:"column:group_banned"`
	ChannelBanned bool `gorm:"column:channel_banned"`
	IsVipUser     bool `gorm:"column:is_vip_user"`
	IsBotStarted  bool `gorm:"column:is_bot_started"`
	//IsAdmin           bool `gorm:"column:is_admin"`
	IsDistributedUser bool `gorm:"column:is_dis_user"`
	IsCapped          bool `gorm:"column:is_capped"`
	IsMonthLimited    bool `gorm:"column:is_month_limited"`
	RecheckVerificity bool `gorm:"column:recheck_verificity"`

	Points int64

	CalculatedQuota C.Bwidth // This value includes Main User quota which is calculated on watchman + Giftquota
	AdditionalQuota C.Bwidth `gorm:"column:additional_quota"` // this is static does not reset, value always in byte (this value does not use yet in codebase may be future)
	GiftQuota       C.Bwidth // this value can be +,-
	CappedQuota     C.Bwidth `gorm:"column:capped_quota"`
	UsedQuota       C.Bwidth // current total quota used by the user
	SavedQuota      C.Bwidth //this value used for when a user over use month usage this value store next months savings from him    (his quota - fake usage)

	MonthUsage       C.Bwidth `gorm:"column:month_usage"` //Usage of current Month will reset with end of month
	AlltimeUsage     C.Bwidth `gorm:"column:all_time_usage"`
	AddtionalConfig  int16    `gorm:"column:max_config_count"`
	ConfigCount      int16    `gorm:"column:config_count"`
	DeletedConfCount int16    `gorm:"column:deleted_conf_count"`

	WebToken sql.NullString `gorm:"type:varchar(200);column:web_token"`
	Configs  []Config       `gorm:"foreignKey:UserID"`

	Captime time.Time
	//Gifttime  time.Time
	Joined    time.Time
	LeaveTime time.Time `gorm:"column:leave_time"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*User) AddPoint

func (u *User) AddPoint(n int64)

func (*User) GenaralQuotSum

func (u *User) GenaralQuotSum() C.Bwidth

retuns sum of addtional + gift +

func (*User) GetCalculatedQuota

func (u *User) GetCalculatedQuota() C.Bwidth

returns

func (*User) Iscaptimeover

func (u *User) Iscaptimeover() bool

func (User) String

func (u User) String() string

Jump to

Keyboard shortcuts

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