Documentation ¶
Index ¶
- Variables
- func MustMigrate(db *sqlx.DB) error
- type Dependency
- func (d *Dependency) GetHourlyDataFromDB(ctx context.Context) ([]HourlyMap, error)
- func (d *Dependency) GetUserDataFromDB(ctx context.Context) ([]GroupMember, error)
- func (d *Dependency) IncrementUserDB(ctx context.Context, member GroupMember) error
- func (d *Dependency) Migrate(ctx context.Context) error
- func (d *Dependency) NewMessage(m *tb.Message) error
- func (d *Dependency) NewUser(ctx context.Context, m *tb.Message, user *tb.User)
- func (d *Dependency) PurgeBots(ctx context.Context, m *tb.Message)
- func (d *Dependency) SwarmLog(user *tb.User, groupID int64, finishedCaptcha bool)
- func (d *Dependency) UpdateSwarm(user *tb.User, groupID int64, finishedCaptcha bool)
- type GroupMember
- type HourlyMap
- type NullInt64
Constants ¶
This section is empty.
Variables ¶
var HourMapper = []string{
"zero_hour", "one_hour", "two_hour", "three_hour", "four_hour", "five_hour",
"six_hour", "seven_hour", "eight_hour", "nine_hour", "ten_hour", "eleven_hour",
"twelve_hour", "thirteen_hour", "fourteen_hour", "fifteen_hour", "sixteen_hour",
"seventeen_hour", "eighteen_hour", "nineteen_hour", "twenty_hour", "twentyone_hour",
"twentytwo_hour", "twentythree_hour",
}
HourMapper is meant to use for mapping a time.Hour() to a string
Functions ¶
func MustMigrate ¶
MustMigrate is the same as Migrate, but you don't need to explicitly create a Dependency struct instance. Just supply the database, and you're good to go. It will not panic on error, instead it will just return an error.
Types ¶
type Dependency ¶
Dependency is the dependency injection struct for the analytics package.
func (*Dependency) GetHourlyDataFromDB ¶
func (d *Dependency) GetHourlyDataFromDB(ctx context.Context) ([]HourlyMap, error)
Return a slice of HourlyMap from the database.
func (*Dependency) GetUserDataFromDB ¶
func (d *Dependency) GetUserDataFromDB(ctx context.Context) ([]GroupMember, error)
Returns a slice of GroupMember from the database.
func (*Dependency) IncrementUserDB ¶
func (d *Dependency) IncrementUserDB(ctx context.Context, member GroupMember) error
IncrementUserDB literally increment a user's counter on the database.
func (*Dependency) Migrate ¶
func (d *Dependency) Migrate(ctx context.Context) error
Migrate creates a migration to the database. This can be called multiple times as it uses PostgreSQL syntax of `IF NOT EXISTS`.
func (*Dependency) NewMessage ¶
func (d *Dependency) NewMessage(m *tb.Message) error
NewMessage handles an incoming message from the group to be noted into the database.
func (*Dependency) NewUser ¶
NewUser adds a newly joined user on the group into the database.
If the user has joined before, meaning he left the group for some reason, their data should still be here. But, their joined date will be updated to their newest join date.
func (*Dependency) SwarmLog ¶
func (d *Dependency) SwarmLog(user *tb.User, groupID int64, finishedCaptcha bool)
func (*Dependency) UpdateSwarm ¶
func (d *Dependency) UpdateSwarm(user *tb.User, groupID int64, finishedCaptcha bool)
type GroupMember ¶
type GroupMember struct { GroupID NullInt64 `json:"group_id,omitempty" db:"group_id"` UserID int64 `json:"user_id" db:"user_id"` Username string `json:"username,omitempty" db:"username" redis:"username"` DisplayName string `json:"display_name,omitempty" db:"display_name" redis:"display_name"` Counter int `json:"counter" db:"counter" redis:"counter"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` JoinedAt time.Time `json:"joined_at" db:"joined_at"` }
GroupMember contains information about a user from a group.
func ParseGroupMember ¶
func ParseGroupMember(m *tb.Message) GroupMember
ParseGroupMember converts the tb.Message struct into a GroupMember struct.
type HourlyMap ¶
type HourlyMap struct { TodaysDate string `json:"todays_date" db:"todays_date"` ZeroHour int `json:"zero_hour" db:"zero_hour"` OneHour int `json:"one_hour" db:"one_hour"` TwoHour int `json:"two_hour" db:"two_hour"` ThreeHour int `json:"three_hour" db:"three_hour"` FourHour int `json:"four_hour" db:"four_hour"` FiveHour int `json:"five_hour" db:"five_hour"` SixHour int `json:"six_hour" db:"six_hour"` SevenHour int `json:"seven_hour" db:"seven_hour"` EightHour int `json:"eight_hour" db:"eight_hour"` NineHour int `json:"nine_hour" db:"nine_hour"` TenHour int `json:"ten_hour" db:"ten_hour"` ElevenHour int `json:"eleven_hour" db:"eleven_hour"` TwelveHour int `json:"twelve_hour" db:"twelve_hour"` ThirteenHour int `json:"thirteen_hour" db:"thirteen_hour"` FourteenHour int `json:"fourteen_hour" db:"fourteen_hour"` FifteenHour int `json:"fifteen_hour" db:"fifteen_hour"` SixteenHour int `json:"sixteen_hour" db:"sixteen_hour"` SeventeenHour int `json:"seventeen_hour" db:"seventeen_hour"` EighteenHour int `json:"eighteen_hour" db:"eighteen_hour"` NineteenHour int `json:"nineteen_hour" db:"nineteen_hour"` TwentyHour int `json:"twenty_hour" db:"twenty_hour"` TwentyOneHour int `json:"twentyone_hour" db:"twentyone_hour"` TwentyTwoHour int `json:"twentytwo_hour" db:"twentytwo_hour"` TwentyThreeHour int `json:"twentythree_hour" db:"twentythree_hour"` }
HourlyMap contains the struct surrounding the hourly analytics.