lib

package
v0.0.0-...-6de9b76 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StandardLogger = Logger{
	Format: "2006-01-02 15:04:05 — ",
	Output: os.Stdout,
	Levels: map[string]Level{
		"debug":   {"💾", color.New(color.FgWhite)},
		"info":    {"▶", color.New(color.FgCyan)},
		"success": {"✅", color.New(color.FgHiGreen)},
		"error":   {"‼", color.New(color.FgRed)},
	},
}

StandardLogger is the default logger for the app, with predetermined parameters and levels

View Source
var TempDir string
View Source
var WorkDir string

Functions

func Contains

func Contains(slice []string, text string) bool

Contains check if a specific slice contains a string

func EncodeURL

func EncodeURL(input string, params map[string]string) string

EncodeURL parses an URL with its query parameters

func Fatal

func Fatal(format string, a ...interface{})

Fatal prints an error log using the StandardLogger and exists the program

func LoadEnv

func LoadEnv(path string)

LoadEnv loads all the environment variables stored in a .env file

func LogDebug

func LogDebug(format string, a ...interface{})

LogDebug prints a debug log using the StandardLogger (if debug mode is enabled)

func LogError

func LogError(format string, a ...interface{})

LogError prints an error log using the StandardLogger (if debug mode is enabled)

func LogInfo

func LogInfo(format string, a ...interface{})

LogInfo prints an information log using the StandardLogger

func LogSuccess

func LogSuccess(format string, a ...interface{})

LogSuccess prints a success log using the StandardLogger

func OpenCache

func OpenCache() (cache *redis.Client)

OpenCache creates the Redis client and connects to the cache

func OpenDirs

func OpenDirs()

OpenDirs loads current and temporary directories

func ParseTelegramMessage

func ParseTelegramMessage(input string) (output string)

ParseTelegramMessage escapes all the characters required to print MarkdownV2 content

Types

type Bot

type Bot struct {
	// The Telegram API that is merged into our structure
	*telegram.BotAPI

	// A list of the slash commands available to the user
	Commands map[string]Command
	// The Redis client the bot will connect to
	Cache *redis.Client
}

Bot is a structure that holds the Telegram API and other assets and is unique

func (*Bot) Error

func (bot *Bot) Error(chatID int64, message string) (err error)

Error sends a formatted error message in the Telegram chat

func (*Bot) Help

func (bot *Bot) Help(chatID int64, command string) (err error)

Help sends a formatted help message in the Telegram chat

type Command

type Command struct {
	// Name of the command as shown in Telegram UI
	Name string
	// A complete description of the command to show in the help message
	Description string
	// The list of flags that can be passed by the user
	Flags map[string]Flag
	// The command actions
	Execute func(bot *Bot, update *telegram.Update, chatID int64, args []string, flags map[string]interface{}) error
}

Command describes a Telegram commands with all its information

func (Command) Help

func (c Command) Help() (content string)

Help generates the help string for the command

type Flag

type Flag struct {
	// A complete description of the flag to show in the help message
	Description string
	// Default value of the flag. Currently supported types: string, integer, float
	Value interface{}
	// A list of accepted strings for this flag
	Enum *[]string
}

Flag holds the data of a command flag, that's to say an optional parameter passed at the beginning

type Level

type Level struct {
	Emoji string
	Color *color.Color
}

Level describes a log level with an emoji and color for console display

type Logger

type Logger struct {
	// Format used for the date, uses `time` package
	Format string
	// Print all debug and error messages or not
	Debug bool
	// Where to print the logs
	Output io.Writer
	// List of the log levels (debug, info, success and error)
	Levels map[string]Level
}

Logger is an instance that displays logs with a defined style in the console

Jump to

Keyboard shortcuts

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