utils

package
v1.6.1-0...-105477e Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DaysScanLimit = 7

DaysScanLimit - limit of days to scan for the start of the next lesson in /left command

Variables

This section is empty.

Functions

func CleanHTML

func CleanHTML(text string) string

CleanHTML removes all unsupported HTML tags from given text.

func CleanText

func CleanText(text string) string

CleanText removes unnecessary characters from given text:

  • Too many newlines
  • Spaces and newlines from the beginning and end of the string

func EscapeMarkdownV2

func EscapeMarkdownV2(text string) string

EscapeMarkdownV2 takes an input text and escape Telegram MarkdownV2 markup symbols.

TODO: Remove this when merged: https://github.com/go-telegram/bot/pull/44

func FormatDuration

func FormatDuration(duration time.Duration, depth int, lang i18n.Language) string

FormatDuration formats time.Duration into a readable format

Example: FormatDuration(duration, depth=2) // "2d. 9h."

func GetLang

func GetLang(code string, langs map[string]i18n.Language) (i18n.Language, error)

GetLang returns the language of the chat.

func GetLessonIcon

func GetLessonIcon(lessonType int) string

GetLessonIcon returns the icon for the lesson type.

Examples (*colored emoji):

  • Lecture: 🔸
  • Practice: 🔹
  • Exam: 🔺

func GetSettingIcon

func GetSettingIcon(enabled bool) string

GetSettingIcon returns the icon for the setting: ✅ or ❌

func SetLocation

func SetLocation(time2 time.Time, location *time.Location) time.Time

SetLocation sets the location of the time without changing the time itself.

func SplitRows

func SplitRows[T any](slice []T, rowSize int) [][]T

SplitRows splits the given slice into rows of given size.

slice is the slice to split rowSize is the size of each row

Example:

slice := []int{1, 2, 3, 4, 5, 6, 7, 8}
rows := SplitRows(slice, 3)
// rows = [[1, 2, 3], [4, 5, 6], [7, 8]]

Types

type ButtonData

type ButtonData struct {
	Action string
	Params map[string]string
}

func ParseButtonData

func ParseButtonData(buttonData string) *ButtonData

ParseButtonData parses the telegram button callback Action string.

Params example: "open.schedule.day#date=2023-10-04&day=1"

Returns ButtonData: Action = "open.schedule.day", Params = {"date": "2023-10-04", "day": "1"}

type CallStatusType

type CallStatusType int8
const (
	// CallStatusBeforeStart - before the first lesson
	CallStatusBeforeStart CallStatusType = iota
	// CallStatusBefore - before the next lesson (time when break ends)
	CallStatusBefore
	// CallStatusDuring - during the lesson
	CallStatusDuring
)

type CallsStatus

type CallsStatus struct {
	Status CallStatusType
	Time   time.Time
}

func GetCallsStatus

func GetCallsStatus(groupId int, time2 time.Time, api2 api.Api) (*CallsStatus, error)

GetCallsStatus returns the time relative to the current lesson

Jump to

Keyboard shortcuts

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