bot

package
v0.0.0-...-49b728c Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Debug   bool
	Verbose bool

	Tgbot *tgbotapi.BotAPI
	// contains filtered or unexported fields
}

Bot - incapsula lo stack di Telegram

func NewBot

func NewBot(configFilename string, verbose bool, debug bool) *Bot

func (*Bot) DeleteMessage

func (bot *Bot) DeleteMessage(chatID int64, messageID int) error

func (*Bot) Do

func (bot *Bot) Do() error

Do - processa in modo bloccante le updates di Telegram.

func (*Bot) GetUserEmail

func (bot *Bot) GetUserEmail(userID int) (email string, ok bool)

func (*Bot) Help

func (bot *Bot) Help() string

func (*Bot) LoadConfig

func (bot *Bot) LoadConfig() error

LoadConfig - carica le impostazioni. Se non viene invocata esternamente ci pensa comunque bot.Do()

func (*Bot) NewMessageResponseOpt

func (bot *Bot) NewMessageResponseOpt() MessageResponseOpt

NewMessageResponseOpt resituisce un MessageResponse con valori inizializzati

func (*Bot) ParseUserID

func (bot *Bot) ParseUserID(s string, mustExists bool) int

ParseUserID ritorna l'ID utente specificato dalla stringa in input. Se numerico lo ritorna tale e quale (mustExists verifica che l'utente esista nel DB interno). Se "username" o "@username" cerca l'utente corrispondente nel DB interno.

func (*Bot) ProcessCommand

func (bot *Bot) ProcessCommand(handler MessageHandler, command string, params []string) (bool, error)

func (*Bot) ProcessMessage

func (bot *Bot) ProcessMessage(handler MessageHandler, text string) (bool, error)

func (*Bot) ProcessUpdate

func (bot *Bot) ProcessUpdate(update tgbotapi.Update) (bool, error)

func (*Bot) RegisterConfig

func (bot *Bot) RegisterConfig(scope string, configData interface{})

func (*Bot) RegisterProcessor

func (bot *Bot) RegisterProcessor(name string, processor Processor, configData interface{})

RegisterProcessor aggiunge un processor al bot, estendendone le funzionalità

func (*Bot) SaveConfig

func (bot *Bot) SaveConfig()

SaveConfig - può essere invocata spesso dato che utilizza l'antibounce

func (*Bot) SaveConfigNow

func (bot *Bot) SaveConfigNow() error

SaveConfigNow - salva immediatamente le impostazioni

func (*Bot) SendMessageResponse

func (bot *Bot) SendMessageResponse(handler MessageHandler, text string, opt MessageResponseOpt)

SendMessageResponse invia un messaggio di risposta all'handler

func (*Bot) SendMessageResponseToPrivate

func (bot *Bot) SendMessageResponseToPrivate(handler MessageHandler, text string, opt MessageResponseOpt)

SendMessageResponseToPrivate invia un messaggio di risposta all'handler forzandolo in chat privata

func (*Bot) Version

func (bot *Bot) Version() string

Version - return bot version

type MessageHandler

type MessageHandler struct {
	UserID   int
	Username string
	Group    userGroup

	ChatID    int64
	IsPrivate bool

	MessageID     int // messaggio a cui appartiene il comando
	EditMessageID int // se > 0 messaggio da editare anzichè inviarne uno nuovo

	ReplyUserID   int // utente del messaggio a cui si è risposto
	ReplyUsername string
}

MessageHandler contiene i riferimenti utili all'invio messaggi dai metodi di processing

type MessageResponseOpt

type MessageResponseOpt struct {
	ForcePrivate         bool
	ReplyToSenderMessage bool
	ReplaceSenderMessage bool
	LinksPreview         bool
	HTMLformat           bool

	KeyboardInline *tgbotapi.InlineKeyboardMarkup
	KeyboardReply  *tgbotapi.ReplyKeyboardMarkup
}

MessageResponseOpt contiene i flag di modalità di risposta

type Processor

type Processor interface {
	Help() string
	Version() string

	// Restituiscono true quando il comando o messaggio è stato effettivamente processato
	ProcessUpdate(update tgbotapi.Update) (bool, error)
	ProcessCommand(handler MessageHandler, command string, params []string) (bool, error)
	ProcessMessage(handler MessageHandler, text string) (bool, error)
}

Processor implementa i metodi per processare comandi e messaggi semplici

type StubProcessor

type StubProcessor struct {
}

StubProcessor implementa tutti i metodi di Processor ma con funzioni vuote, pronte per l'override

func (*StubProcessor) Help

func (p *StubProcessor) Help() string

func (*StubProcessor) ProcessCommand

func (p *StubProcessor) ProcessCommand(handler MessageHandler, command string, params []string) (bool, error)

func (*StubProcessor) ProcessMessage

func (p *StubProcessor) ProcessMessage(handler MessageHandler, text string) (bool, error)

func (*StubProcessor) ProcessUpdate

func (p *StubProcessor) ProcessUpdate(update tgbotapi.Update) (bool, error)

func (*StubProcessor) Version

func (p *StubProcessor) Version() string

Jump to

Keyboard shortcuts

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