common

package
v0.0.0-...-7d43480 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreasReplyKeyboard

func AreasReplyKeyboard(db *gorm.DB) ([][]tb.ReplyButton, error)

AreasReplyKeyboard returns a reply keyboard with all visible areas

func Recover

func Recover(rec interface{}, hasSentry bool) error

Recover checks if there was a panic, logs the error to stdout and sentry (if enabled) it returns the error that caused the pani (nil if there was no panic)

func SingleInlineKeyboardFactory

func SingleInlineKeyboardFactory(btn tb.InlineButton) *tb.ReplyMarkup

SingleInlineKeyboardFactory returns a ReplyMarkup with a single button containing the provided button (inline version)

func SingleKeyboardFactory

func SingleKeyboardFactory(s string) *tb.ReplyMarkup

SingleKeyboardFactory returns a ReplyMarkup with a single button containing the provided text

Types

type Configuration

type Configuration struct {
	Token        string `env:"TOKEN"`
	Username     string `env:"USERNAME"`
	DbDriver     string `env:"DB_DRIVER" env-default:"sqlite3" env-description:"sqlite3 or mysql"`
	DbDSN        string `env:"DB_DSN" env-default:"ugr.db"`
	LogChannelID string `env:"LOG_CHANNEL_ID"`
	SentryDSN    string `env:"SENTRY_DSN"`
	Debug        bool   `env:"DEBUG" env-default:"false"`
	Timezone     string `env:"TIMEZONE" env-default:"UTC" env-description:"Timezone for input/output. UTC is used internally."`
}

Configuration holds the bot configuration

type Ctx

type Ctx struct {
	Message     *tb.Message
	Callback    *tb.Callback
	InlineQuery *tb.Query
	B           *tb.Bot
	Db          *gorm.DB
	HasSentry   bool
	DbUser      *models.User
	NoMenu      bool

	LogChannelID string
	BotUsername  string
}

Ctx ...

func (*Ctx) AnswerNoCache

func (c *Ctx) AnswerNoCache(r *tb.QueryResponse) error

AnswerNoCache answers to an inline query, with no cache

func (*Ctx) ClearStateData

func (c *Ctx) ClearStateData()

func (*Ctx) HandleErr

func (c *Ctx) HandleErr(err error)

HandleErr reports an error to sentry

func (*Ctx) LogToChan

func (c *Ctx) LogToChan(what interface{}, options ...interface{}) error

LogToChan sends a message to the log channel

func (*Ctx) Reply

func (c *Ctx) Reply(what interface{}, options ...interface{}) (*tb.Message, error)

Reply replies to the message held by the current Ctx. This works both with callbacks and normal messages. TODO: make this private and replace all calls to

it with c.HandleErr(common.ReportableError{T:...})

func (*Ctx) Report

func (c *Ctx) Report(txt string)

Report reports a message to the user, in the most appropriate form based on the current ctx. - If the ctx holds a callback query, it sends a callback response - If the ctx holds an inline query, it sends a query result - If the ctx holds a message, it sends a message

func (*Ctx) Respond

func (c *Ctx) Respond(r ...*tb.CallbackResponse) error

Respond responds to the callback query held by the current ctx

func (*Ctx) SetState

func (c *Ctx) SetState(newState string)

SetState updates the state of the user held by the current Ctx

func (*Ctx) SetStateData

func (c *Ctx) SetStateData(data interface{})

func (*Ctx) Sign

func (c *Ctx) Sign(msg string) string

Sign takes msg and appends c.Signature() to it

func (*Ctx) Signature

func (c *Ctx) Signature() string

Signature returns a string that contains the name and username of the user held by the current ctx

func (*Ctx) TelegramUser

func (c *Ctx) TelegramUser() *tb.User

TelegramUser returns the user user who send the callback, or the user who sent the message

func (*Ctx) UpdateMenu

func (c *Ctx) UpdateMenu(what interface{}, options ...interface{}) (*tb.Message, error)

UpdateMenu updates a callback-based menu by deleting the message the callback originated from and sending a new one

type ReportableError

type ReportableError struct {
	T string
}

ReportableError represents an error that will be reported to the user as a callback response or as a message, depending on the ctx

var (
	IllegalPayloadReportableError ReportableError = ReportableError{T: "Illegal payload"}
)

Some std errors

func (ReportableError) Error

func (e ReportableError) Error() string

func (ReportableError) Report

func (e ReportableError) Report(c *Ctx)

Report reports the error to the user

Jump to

Keyboard shortcuts

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