components

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	INT2MONTHS = [12]string{
		"January",
		"February",
		"March",
		"April",
		"May",
		"June",
		"July",
		"August",
		"September",
		"October",
		"November",
		"December",
	}

	CSVPrefix   = "/csv"
	ExcelPrefix = "/excel"

	XLSXFullBorder = []excelize.Border{
		{Type: "left", Color: "000000", Style: 1},
		{Type: "top", Color: "000000", Style: 1},
		{Type: "bottom", Color: "000000", Style: 1},
		{Type: "right", Color: "000000", Style: 1},
	}
	XLSXGrayFill1 = excelize.Fill{Type: "pattern", Color: []string{"#404040"}, Pattern: 1}
	XLSXGrayFill2 = excelize.Fill{Type: "pattern", Color: []string{"#D9D9D9"}, Pattern: 1}
	XLSXGrayFill3 = excelize.Fill{Type: "pattern", Color: []string{"#F2F2F2"}, Pattern: 1}
	XLSXWhiteFont = excelize.Font{Color: "#FFFFFF"}
)
View Source
var (
	InfoLogger  *log.Logger
	ErrorLogger *log.Logger
)

Functions

func AddSpendHandler

func AddSpendHandler(c tele.Context) error

AddSpendHandler is a handler that adds users spend.

Language required for work.

func AskToDeleteUserData

func AskToDeleteUserData(c tele.Context) error

AskToDeleteUserData is a handler for asking for all user data deletion.

Language required for work.

func CallbackHandler

func CallbackHandler(c tele.Context) error

CallbackHandler is a handler for callbacks. Have shortcuts for export csv/excel (/csvYEAR and /excelYEAR).

Switches depending on args[1]:

args[1] == "setLang" - trying to set user lang to args[2]
args[1] == "getDay" - passing context to DaySpendsHandler with "date" setted to parsed from args[2] day.
args[1] == "getYear" - passing context to YearSpendsHandler with "year" setted to parsed from args[2] year.
args[1] == "delete_all_my_data" - deleting all user data from database.
args[1] == "cancel" - deletes the message from which the callback came.

Language required for work.

func DaySpendsHandler

func DaySpendsHandler(c tele.Context) error

DaySpendsHandler is a handler for day spends stats. Have selector for scrolling between days. If key "date" in context not set, returning current date stats, else "date" stats.

Location and language required for work.

func DelSpendHandler

func DelSpendHandler(c tele.Context) error

DelSpendHandler is a handler for spend deleting.

Language and location required for work.

func ExportHandler

func ExportHandler(c tele.Context) error

ExportHandler is a handler for export year spends to excel or csv.

Language and location required for work.

func InitLocales

func InitLocales()

InitLocales - initializing locales for supported languages.

func InitLoggers

func InitLoggers()

InitLoggers - initializing bot loggers.

func LangAskHandler

func LangAskHandler(c tele.Context) error

LangAskHandler is a handler for language asking. Returned on "/set_lang" and on first use of bot.

func LocationHandler

func LocationHandler(c tele.Context) error

LocationHandler is a handler for location messages. Used for calculating user time zone.

func OnTextHandler

func OnTextHandler(c tele.Context) error

OnTextHandler is a handler for:

  1. Spends add msg: <cost> <spend_name>
  2. /delN command
  3. /excelYEAR command
  4. /csvYEAR command

func PassData

func PassData(data map[string]interface{}) func(tele.HandlerFunc) tele.HandlerFunc

PassData - passing all (key, val) from data map to context by c.Set(k, v).

func SetLang

func SetLang() func(tele.HandlerFunc) tele.HandlerFunc

SetLang - Checks if user language is set:

If context have 'setLang' in args, passing context to LangAskHandler.
If user.Lang not set sends context to LangAskHandler.
If user.Lang is set, execute c.Set("lang", &lang), where &lang is ptr to language.Tag.

func SetLocation

func SetLocation() func(tele.HandlerFunc) tele.HandlerFunc

SetLocation - checks if user TimeZone is set:

If context have 'setLang' in args, passing context to 'next'.
If user.TimeZone not set, sends context to TimeZoneAskHandler.
If user.TimeZone is set, execute c.Set("loc", loc), where loc is ptr to time.Location.

func SettingsHandler

func SettingsHandler(c tele.Context) error

SettignsHandler is a handler for user settings.

Language required for work.

func SpendsToCSV

func SpendsToCSV(spends []Spend) (*bytes.Buffer, error)

SpendsToCSV - converting spends slice to buffer with content represented in CSV format.

func SpendsToExcel

func SpendsToExcel(spends []Spend, printer *message.Printer) (*bytes.Buffer, error)

SpendsToExcel - converting spends slice to buffer with content represented in Excel format.

func StartHandler

func StartHandler(c tele.Context) error

StartHandler is a handler that sends menu and help message.

Language required for work.

func TimeZoneAskHandler

func TimeZoneAskHandler(c tele.Context) error

TimeZoneAskHandler is a handler for time zone asking.

Language required for work.

func YearSpendsHandler

func YearSpendsHandler(c tele.Context) error

YearSpendsHandler is a handler for year spends stats. Have selector for scrolling between years. Have shortcuts for export csv and excel (/csvYEAR and /excelYEAR).

Location and language required for work.

Types

type Spend

type Spend struct {
	Date   time.Time
	Name   string
	ID     int64
	UserID int64
	Value  float32
}

Spend stores values of spend from db. Used by gorm.DB to save and receive values.

func GetSpendsByDayMonthYear

func GetSpendsByDayMonthYear(uid int64, db *gorm.DB, day int, month int, year int, loc *time.Location) []Spend

GetSpendsByDayMonthYear - returning slice of day spends ordered from older to newer dates.

func GetSpendsByMonthYear

func GetSpendsByMonthYear(uid int64, db *gorm.DB, month int, year int, loc *time.Location) []Spend

GetSpendsByMonthYear - returning slice of month spends ordered from older to newer dates.

func GetSpendsByYear

func GetSpendsByYear(uid int64, db *gorm.DB, year int, loc *time.Location) []Spend

GetSpendsByYear - returning slice of year spends ordered from older to newer dates.

type User

type User struct {
	TimeZone string
	Lang     string
	ID       int64
}

User stores values of user from db. Used by gorm.DB to save and receive values.

Jump to

Keyboard shortcuts

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