Documentation ¶
Index ¶
- Variables
- func AddSpendHandler(c tele.Context) error
- func AskToDeleteUserData(c tele.Context) error
- func CallbackHandler(c tele.Context) error
- func DaySpendsHandler(c tele.Context) error
- func DelSpendHandler(c tele.Context) error
- func ExportHandler(c tele.Context) error
- func InitLocales()
- func InitLoggers()
- func LangAskHandler(c tele.Context) error
- func LocationHandler(c tele.Context) error
- func OnTextHandler(c tele.Context) error
- func PassData(data map[string]interface{}) func(tele.HandlerFunc) tele.HandlerFunc
- func SetLang() func(tele.HandlerFunc) tele.HandlerFunc
- func SetLocation() func(tele.HandlerFunc) tele.HandlerFunc
- func SettingsHandler(c tele.Context) error
- func SpendsToCSV(spends []Spend) (*bytes.Buffer, error)
- func SpendsToExcel(spends []Spend, printer *message.Printer) (*bytes.Buffer, error)
- func StartHandler(c tele.Context) error
- func TimeZoneAskHandler(c tele.Context) error
- func YearSpendsHandler(c tele.Context) error
- type Spend
- type User
Constants ¶
This section is empty.
Variables ¶
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"} )
var ( InfoLogger *log.Logger ErrorLogger *log.Logger )
Functions ¶
func AddSpendHandler ¶
AddSpendHandler is a handler that adds users spend.
Language required for work.
func AskToDeleteUserData ¶
AskToDeleteUserData is a handler for asking for all user data deletion.
Language required for work.
func CallbackHandler ¶
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 ¶
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 ¶
DelSpendHandler is a handler for spend deleting.
Language and location required for work.
func ExportHandler ¶
ExportHandler is a handler for export year spends to excel or csv.
Language and location required for work.
func LangAskHandler ¶
LangAskHandler is a handler for language asking. Returned on "/set_lang" and on first use of bot.
func LocationHandler ¶
LocationHandler is a handler for location messages. Used for calculating user time zone.
func OnTextHandler ¶
OnTextHandler is a handler for:
- Spends add msg: <cost> <spend_name>
- /delN command
- /excelYEAR command
- /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 SpendsToCSV ¶
SpendsToCSV - converting spends slice to buffer with content represented in CSV format.
func SpendsToExcel ¶
SpendsToExcel - converting spends slice to buffer with content represented in Excel format.
func StartHandler ¶
StartHandler is a handler that sends menu and help message.
Language required for work.
func TimeZoneAskHandler ¶
TimeZoneAskHandler is a handler for time zone asking.
Language required for work.
func YearSpendsHandler ¶
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 ¶
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 ¶
GetSpendsByMonthYear - returning slice of month spends ordered from older to newer dates.