watcher

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package watcher provides functionality to monitor Telegram for new messages.

Index

Constants

View Source
const (
	CmdUsers   = "users"
	CmdApprove = "approve"
	CmdReject  = "reject"
)

Admin bot command constants.

View Source
const (
	CmdStart   = "start"
	CmdStop    = "stop"
	CmdID      = "id"
	CmdWeek    = "week"
	CmdDay     = "day"
	CmdHalfDay = "halfday"
)

Telegram bot command constants.

Variables

View Source
var (
	// Commands defines the list of Telegram bot commands.
	Commands = []models.BotCommand{

		{
			Command:     CmdHalfDay,
			Description: "Показать график за полдня 🕒",
		},
		{
			Command:     CmdDay,
			Description: "Показать график за день 📅",
		},
		{
			Command:     CmdWeek,
			Description: "Показать график за неделю 📆",
		},
		{
			Command:     CmdStop,
			Description: "Остановить работу с ботом 🛑",
		},
	}
)

Functions

func BotAdminOnlyMiddleware added in v0.1.0

func BotAdminOnlyMiddleware(adminUserIDs map[int64]struct{}) func(next bot.HandlerFunc) bot.HandlerFunc

BotAdminOnlyMiddleware is a middleware that allows only admin users to proceed.

func BotAuthMiddleware added in v0.1.0

func BotAuthMiddleware(adminUserIDs map[int64]struct{}, db *databaser.DB) func(next bot.HandlerFunc) bot.HandlerFunc

BotAuthMiddleware is a middleware that checks if the user is authorized. It's not a clean middleware, but a wrapper to prepare it with admin and DB users.

func BotLoggingMiddleware added in v0.1.0

func BotLoggingMiddleware(next bot.HandlerFunc) bot.HandlerFunc

BotLoggingMiddleware is a middleware that logs the start and stop of each request.

Types

type BotAPI added in v0.0.23

type BotAPI interface {
	SendMessage(ctx context.Context, params *bot.SendMessageParams) (*models.Message, error)
	SendPhoto(ctx context.Context, params *bot.SendPhotoParams) (*models.Message, error)
}

BotAPI defines the methods needed from the Telegram bot.

type BotHandler

type BotHandler struct {
	// contains filtered or unexported fields
}

BotHandler handles Telegram bot interactions for displaying load graphs.

func NewBotHandler

func NewBotHandler(db *databaser.DB, cfg *config.Config, pc *predictor.Controller) *BotHandler

NewBotHandler creates a new BotHandler with the given dependencies.

func (*BotHandler) DefaultHandler

func (h *BotHandler) DefaultHandler(ctx context.Context, b BotAPI, update *models.Update)

DefaultHandler handles all other messages, allowing admin users to request custom duration graphs.

func (*BotHandler) HandleApprove added in v0.1.0

func (h *BotHandler) HandleApprove(ctx context.Context, b BotAPI, update *models.Update)

HandleApprove approves a user by its ID.

func (*BotHandler) HandleDay added in v0.0.23

func (h *BotHandler) HandleDay(ctx context.Context, b BotAPI, update *models.Update)

HandleDay handles day period load graph requests.

func (*BotHandler) HandleHalfDay added in v0.0.23

func (h *BotHandler) HandleHalfDay(ctx context.Context, b BotAPI, update *models.Update)

HandleHalfDay handles half-day period load graph requests.

func (*BotHandler) HandleID added in v0.1.0

func (h *BotHandler) HandleID(ctx context.Context, b BotAPI, update *models.Update)

HandleID handles the /id command and returns the user's Telegram ID.

func (*BotHandler) HandleReject added in v0.1.0

func (h *BotHandler) HandleReject(ctx context.Context, b BotAPI, update *models.Update)

HandleReject rejects a user by its ID.

func (*BotHandler) HandleStart

func (h *BotHandler) HandleStart(ctx context.Context, b BotAPI, update *models.Update)

HandleStart handles the /start command and shows the main keyboard.

func (*BotHandler) HandleStop added in v0.1.0

func (h *BotHandler) HandleStop(ctx context.Context, b BotAPI, update *models.Update)

HandleStop handles the /stop command and removes the main keyboard.

func (*BotHandler) HandleUsers added in v0.1.0

func (h *BotHandler) HandleUsers(ctx context.Context, b BotAPI, update *models.Update)

HandleUsers returns users information.

func (*BotHandler) HandleWeek added in v0.0.23

func (h *BotHandler) HandleWeek(ctx context.Context, b BotAPI, update *models.Update)

HandleWeek handles week-period load graph requests.

func (*BotHandler) WrapDefaultHandler added in v0.0.23

func (h *BotHandler) WrapDefaultHandler(ctx context.Context, b *bot.Bot, update *models.Update)

WrapDefaultHandler wraps DefaultHandler for bot.HandlerFunc compatibility.

func (*BotHandler) WrapHandleApprove added in v0.1.0

func (h *BotHandler) WrapHandleApprove(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleApprove wraps HandleApprove to match bot.HandlerFunc signature.

func (*BotHandler) WrapHandleDay added in v0.0.23

func (h *BotHandler) WrapHandleDay(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleDay wraps HandleDay for bot.HandlerFunc compatibility.

func (*BotHandler) WrapHandleHalfDay added in v0.0.23

func (h *BotHandler) WrapHandleHalfDay(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleHalfDay wraps HandleHalfDay for bot.HandlerFunc compatibility.

func (*BotHandler) WrapHandleID added in v0.1.0

func (h *BotHandler) WrapHandleID(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleID wraps HandleID for bot.HandlerFunc compatibility.

func (*BotHandler) WrapHandleReject added in v0.1.0

func (h *BotHandler) WrapHandleReject(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleReject wraps HandleReject to match bot.HandlerFunc signature.

func (*BotHandler) WrapHandleStart added in v0.0.23

func (h *BotHandler) WrapHandleStart(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleStart wraps HandleStart for bot.HandlerFunc compatibility.

func (*BotHandler) WrapHandleStop added in v0.1.0

func (h *BotHandler) WrapHandleStop(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleStop wraps HandleStop for bot.HandlerFunc compatibility.

func (*BotHandler) WrapHandleUsers added in v0.1.0

func (h *BotHandler) WrapHandleUsers(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleUsers wraps HandleUsers to match bot.HandlerFunc signature.

func (*BotHandler) WrapHandleWeek added in v0.0.23

func (h *BotHandler) WrapHandleWeek(ctx context.Context, b *bot.Bot, update *models.Update)

WrapHandleWeek wraps HandleWeek for bot.HandlerFunc compatibility.

Jump to

Keyboard shortcuts

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