bot

package
v0.0.0-...-1cbc9ae Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotEnoughWords = errors.New("not enough words")

ErrNotEnoughWords is returned when there are not enough words in dictionary

Functions

func GetItemMessageText

func GetItemMessageText(item db.DictionaryItem) string

GetItemMessageText executes template with dictionary item data

func GetQuizMessageText

func GetQuizMessageText(quiz db.Quiz) (string, error)

GetQuizMessageText returns text for quiz message

Types

type Bot

type Bot interface {
	Send(tgbotapi.Chattable) (tgbotapi.Message, error)
	SendCallback(tgbotapi.CallbackConfig) (*tgbotapi.APIResponse, error)
	DB() db.Storage
}

Bot describes bot for handlers

type Handler

type Handler interface {
	Handle(ctx context.Context, b Bot, u tgbotapi.Update)
	Passthrough(tgbotapi.Update) bool
	Match(u tgbotapi.Update) bool
}

Handler describes a handler for a single update

type ListSettingsHandler

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

ListSettingsHandler handles /settings command

func (ListSettingsHandler) Handle

func (h ListSettingsHandler) Handle(ctx context.Context, b Bot, u tgbotapi.Update)

Handle sends settings list keyboard

func (ListSettingsHandler) Match

Match returns true if update is /settings command

func (ListSettingsHandler) Passthrough

func (h ListSettingsHandler) Passthrough(u tgbotapi.Update) bool

Passthrough always returns false

type QuizHandler

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

QuizHandler handles quiz command

func (QuizHandler) Handle

func (h QuizHandler) Handle(ctx context.Context, b Bot, u tgbotapi.Update)

Handle generates new quiz and sends it to user

func (QuizHandler) Match

func (h QuizHandler) Match(u tgbotapi.Update) bool

Match returns true if update is /quiz command

func (QuizHandler) Passthrough

func (h QuizHandler) Passthrough(u tgbotapi.Update) bool

Passthrough always returns false

type QuizReplyHandler

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

QuizReplyHandler handles quiz reply callback

func (QuizReplyHandler) Handle

func (h QuizReplyHandler) Handle(ctx context.Context, b Bot, u tgbotapi.Update)

Handle checks if response is correct and saves it to quiz

func (QuizReplyHandler) Match

func (h QuizReplyHandler) Match(u tgbotapi.Update) bool

Match returns true if update is quiz reply callback

func (QuizReplyHandler) Passthrough

func (h QuizReplyHandler) Passthrough(u tgbotapi.Update) bool

Passthrough always returns false

type SendQuizTypesHandler

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

SendQuizTypesHandler sends available quiz types

func (SendQuizTypesHandler) Handle

func (h SendQuizTypesHandler) Handle(ctx context.Context, b Bot, u tgbotapi.Update)

Handle sends settings quiz type lists keyboard

func (SendQuizTypesHandler) Match

Match returns true if update is quiz settings callback

func (SendQuizTypesHandler) Passthrough

func (h SendQuizTypesHandler) Passthrough(u tgbotapi.Update) bool

Passthrough always returns false

type SetQuizTypesHandler

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

SetQuizTypesHandler saves quiz type to user config

func (SetQuizTypesHandler) Handle

func (h SetQuizTypesHandler) Handle(ctx context.Context, b Bot, u tgbotapi.Update)

Handle saves quiz type to user config

func (SetQuizTypesHandler) Match

Match returns true if update is quiz settings callback with picked type

func (SetQuizTypesHandler) Passthrough

func (h SetQuizTypesHandler) Passthrough(u tgbotapi.Update) bool

Passthrough always returns false

type StartHandler

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

StartHandler is a handler for /start command

func (StartHandler) Handle

func (h StartHandler) Handle(ctx context.Context, b Bot, u tgbotapi.Update)

Handle sends start message

func (StartHandler) Match

func (h StartHandler) Match(u tgbotapi.Update) bool

Match returns true if update is /start command

func (StartHandler) Passthrough

func (h StartHandler) Passthrough(u tgbotapi.Update) bool

Passthrough always returns false

type TelegramBot

type TelegramBot struct {
	UserName string
	// contains filtered or unexported fields
}

TelegramBot handles Telegram API intragration and updates handling

func NewTelegramBot

func NewTelegramBot(token string, db db.Storage, handlers []Handler) (*TelegramBot, error)

NewTelegramBot creates a TelegramBot

func (*TelegramBot) DB

func (b *TelegramBot) DB() db.Storage

DB returns the bot's storage

func (*TelegramBot) Send

Send sends a message to a user

func (*TelegramBot) SendCallback

SendCallback sends a callback query response

func (*TelegramBot) Start

func (b *TelegramBot) Start()

Start updates handling

type WordHandler

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

WordHandler handles word requests

func NewWordHandler

func NewWordHandler(tranlationsToken string) WordHandler

NewWordHandler creates new word handler

func (WordHandler) Handle

func (h WordHandler) Handle(ctx context.Context, b Bot, u tgbotapi.Update)

Handle collects word data and sends it to user

func (WordHandler) Match

func (h WordHandler) Match(u tgbotapi.Update) bool

Match returns true if message is a text

func (WordHandler) Passthrough

func (h WordHandler) Passthrough(u tgbotapi.Update) bool

Passthrough always returns false

Jump to

Keyboard shortcuts

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