Documentation
¶
Index ¶
- func AreasReplyKeyboard(db *gorm.DB) ([][]tb.ReplyButton, error)
- func Recover(rec interface{}, hasSentry bool) error
- func SingleInlineKeyboardFactory(btn tb.InlineButton) *tb.ReplyMarkup
- func SingleKeyboardFactory(s string) *tb.ReplyMarkup
- type Configuration
- type Ctx
- func (c *Ctx) AnswerNoCache(r *tb.QueryResponse) error
- func (c *Ctx) ClearStateData()
- func (c *Ctx) HandleErr(err error)
- func (c *Ctx) LogToChan(what interface{}, options ...interface{}) error
- func (c *Ctx) Reply(what interface{}, options ...interface{}) (*tb.Message, error)
- func (c *Ctx) Report(txt string)
- func (c *Ctx) Respond(r ...*tb.CallbackResponse) error
- func (c *Ctx) SetState(newState string)
- func (c *Ctx) SetStateData(data interface{})
- func (c *Ctx) Sign(msg string) string
- func (c *Ctx) Signature() string
- func (c *Ctx) TelegramUser() *tb.User
- func (c *Ctx) UpdateMenu(what interface{}, options ...interface{}) (*tb.Message, error)
- type ReportableError
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 ¶
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) Reply ¶
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 ¶
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) SetStateData ¶
func (c *Ctx) SetStateData(data interface{})
func (*Ctx) Signature ¶
Signature returns a string that contains the name and username of the user held by the current ctx
func (*Ctx) TelegramUser ¶
TelegramUser returns the user user who send the callback, or the user who sent the message
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