Documentation
¶
Overview ¶
Package watcher provides functionality to monitor Telegram for new messages.
Index ¶
- Constants
- Variables
- func BotAdminOnlyMiddleware(adminUserIDs map[int64]struct{}) func(next bot.HandlerFunc) bot.HandlerFunc
- func BotAuthMiddleware(adminUserIDs map[int64]struct{}, db *databaser.DB) func(next bot.HandlerFunc) bot.HandlerFunc
- func BotLoggingMiddleware(next bot.HandlerFunc) bot.HandlerFunc
- type BotAPI
- type BotHandler
- func (h *BotHandler) DefaultHandler(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleApprove(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleDay(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleHalfDay(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleID(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleReject(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleStart(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleStop(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleUsers(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) HandleWeek(ctx context.Context, b BotAPI, update *models.Update)
- func (h *BotHandler) WrapDefaultHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleApprove(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleDay(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleHalfDay(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleID(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleReject(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleStart(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleStop(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleUsers(ctx context.Context, b *bot.Bot, update *models.Update)
- func (h *BotHandler) WrapHandleWeek(ctx context.Context, b *bot.Bot, update *models.Update)
Constants ¶
const ( CmdUsers = "users" CmdApprove = "approve" CmdReject = "reject" )
Admin bot command constants.
const ( CmdStart = "start" CmdStop = "stop" CmdID = "id" CmdWeek = "week" CmdDay = "day" CmdHalfDay = "halfday" )
Telegram bot command constants.
Variables ¶
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 ¶
DefaultHandler handles all other messages, allowing admin users to request custom duration graphs.
func (*BotHandler) HandleApprove ¶ added in v0.1.0
HandleApprove approves a user by its ID.
func (*BotHandler) HandleHalfDay ¶ added in v0.0.23
HandleHalfDay handles half-day period load graph requests.
func (*BotHandler) HandleID ¶ added in v0.1.0
HandleID handles the /id command and returns the user's Telegram ID.
func (*BotHandler) HandleReject ¶ added in v0.1.0
HandleReject rejects a user by its ID.
func (*BotHandler) HandleStart ¶
HandleStart handles the /start command and shows the main keyboard.
func (*BotHandler) HandleStop ¶ added in v0.1.0
HandleStop handles the /stop command and removes the main keyboard.
func (*BotHandler) HandleUsers ¶ added in v0.1.0
HandleUsers returns users information.
func (*BotHandler) HandleWeek ¶ added in v0.0.23
HandleWeek handles week-period load graph requests.
func (*BotHandler) WrapDefaultHandler ¶ added in v0.0.23
WrapDefaultHandler wraps DefaultHandler for bot.HandlerFunc compatibility.
func (*BotHandler) WrapHandleApprove ¶ added in v0.1.0
WrapHandleApprove wraps HandleApprove to match bot.HandlerFunc signature.
func (*BotHandler) WrapHandleDay ¶ added in v0.0.23
WrapHandleDay wraps HandleDay for bot.HandlerFunc compatibility.
func (*BotHandler) WrapHandleHalfDay ¶ added in v0.0.23
WrapHandleHalfDay wraps HandleHalfDay for bot.HandlerFunc compatibility.
func (*BotHandler) WrapHandleID ¶ added in v0.1.0
WrapHandleID wraps HandleID for bot.HandlerFunc compatibility.
func (*BotHandler) WrapHandleReject ¶ added in v0.1.0
WrapHandleReject wraps HandleReject to match bot.HandlerFunc signature.
func (*BotHandler) WrapHandleStart ¶ added in v0.0.23
WrapHandleStart wraps HandleStart for bot.HandlerFunc compatibility.
func (*BotHandler) WrapHandleStop ¶ added in v0.1.0
WrapHandleStop wraps HandleStop for bot.HandlerFunc compatibility.
func (*BotHandler) WrapHandleUsers ¶ added in v0.1.0
WrapHandleUsers wraps HandleUsers to match bot.HandlerFunc signature.
func (*BotHandler) WrapHandleWeek ¶ added in v0.0.23
WrapHandleWeek wraps HandleWeek for bot.HandlerFunc compatibility.