telegram

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageOrderedByReplyToFrom = "message.reply_to_message.from.id"
	TipTooltipKeyPattern        = "tip-tool-tip:*"
)

Variables

This section is empty.

Functions

func AutoMigration

func AutoMigration() (db *gorm.DB, txLogger *gorm.DB)

func ColumnMigrationTasks

func ColumnMigrationTasks(db *gorm.DB) error

func GetLnbitsUser

func GetLnbitsUser(u *tb.User, bot TipBot) (*lnbits.User, error)

GetLnbitsUser will not update the user in Database. this is required, because fetching lnbits.User from a incomplete tb.User will update the incomplete (partial) user in storage. this function will accept users like this: &tb.User{ID: toId, Username: username} without updating the user in storage.

func GetMemoFromCommand

func GetMemoFromCommand(command string, fromWord int) string

func GetUser

func GetUser(u *tb.User, bot TipBot) (*lnbits.User, error)

GetUser from Telegram user. Update the user if user information changed.

func GetUserByTelegramUsername

func GetUserByTelegramUsername(toUserStrWithoutAt string, bot TipBot) (*lnbits.User, error)

func GetUserStr

func GetUserStr(user *tb.User) string

func GetUserStrMd

func GetUserStrMd(user *tb.User) string

func LoadPublicLocalizer

func LoadPublicLocalizer(ctx context.Context) *i18n2.Localizer

LoadUser from context

func LoadReplyToUser

func LoadReplyToUser(ctx context.Context) *lnbits.User

LoadReplyToUser from context

func LoadUser

func LoadUser(ctx context.Context) *lnbits.User

LoadUser from context

func LoadUserLocalizer

func LoadUserLocalizer(ctx context.Context) *i18n2.Localizer

LoadUser from context

func MakeProgressbar

func MakeProgressbar(current int, total int) string

func MakeTipjarbar

func MakeTipjarbar(current int, total int) string

func RandStringRunes

func RandStringRunes(n int) string

func ResetUserState

func ResetUserState(user *lnbits.User, bot *TipBot)

func SetUserState

func SetUserState(user *lnbits.User, bot *TipBot, stateKey lnbits.UserStateKey, stateData string)

func TipCheckSyntax

func TipCheckSyntax(ctx context.Context, m *tb.Message) (bool, string)

func Translate

func Translate(ctx context.Context, MessgeID string) string

func TranslateUser

func TranslateUser(ctx context.Context, MessgeID string) string

func TryRecognizeQrCode

func TryRecognizeQrCode(img image.Image) (*gozxing.Result, error)

TryRecognizeInvoiceFromQrCode will try to read an invoice string from a qr code and invoke the payment handler.

func UpdateUserRecord

func UpdateUserRecord(user *lnbits.User, bot TipBot) error

func UserGetLNURL

func UserGetLNURL(user *lnbits.User) (string, error)

Types

type Cache

type Cache struct {
	*store.GoCacheStore
}

type EnterAmountStateData

type EnterAmountStateData struct {
	ID              string `json:"ID"`              // holds the ID of the tx object in bunt db
	Type            string `json:"Type"`            // holds type of the tx in bunt db (needed for type checking)
	Amount          int64  `json:"Amount"`          // holds the amount entered by the user mSat
	AmountMin       int64  `json:"AmountMin"`       // holds the minimum amount that needs to be entered mSat
	AmountMax       int64  `json:"AmountMax"`       // holds the maximum amount that needs to be entered mSat
	OiringalCommand string `json:"OiringalCommand"` // hold the originally entered command for evtl later use
}

type EnterUserStateData added in v0.4.2

type EnterUserStateData struct {
	ID              string `json:"ID"`              // holds the ID of the tx object in bunt db
	Type            string `json:"Type"`            // holds type of the tx in bunt db (needed for type checking)
	Amount          int64  `json:"Amount"`          // holds the amount entered by the user mSat
	AmountMin       int64  `json:"AmountMin"`       // holds the minimum amount that needs to be entered mSat
	AmountMax       int64  `json:"AmountMax"`       // holds the maximum amount that needs to be entered mSat
	OiringalCommand string `json:"OiringalCommand"` // hold the originally entered command for evtl later use
}

type Handler

type Handler struct {
	Endpoints   []interface{}
	Handler     interface{}
	Interceptor *Interceptor
}

type InlineFaucet

type InlineFaucet struct {
	*transaction.Base
	Message         string         `json:"inline_faucet_message"`
	Amount          int            `json:"inline_faucet_amount"`
	RemainingAmount int            `json:"inline_faucet_remainingamount"`
	PerUserAmount   int            `json:"inline_faucet_peruseramount"`
	From            *lnbits.User   `json:"inline_faucet_from"`
	To              []*lnbits.User `json:"inline_faucet_to"`
	Memo            string         `json:"inline_faucet_memo"`
	NTotal          int            `json:"inline_faucet_ntotal"`
	NTaken          int            `json:"inline_faucet_ntaken"`
	UserNeedsWallet bool           `json:"inline_faucet_userneedswallet"`
	LanguageCode    string         `json:"languagecode"`
}

type InlineReceive

type InlineReceive struct {
	*transaction.Base
	Message           string       `json:"inline_receive_message"`
	Amount            int          `json:"inline_receive_amount"`
	From              *lnbits.User `json:"inline_receive_from"`
	To                *lnbits.User `json:"inline_receive_to"`
	From_SpecificUser bool         `json:"from_specific_user"`
	Memo              string       `json:"inline_receive_memo"`
	LanguageCode      string       `json:"languagecode"`
}

type InlineSend

type InlineSend struct {
	*transaction.Base
	Message         string       `json:"inline_send_message"`
	Amount          int          `json:"inline_send_amount"`
	From            *lnbits.User `json:"inline_send_from"`
	To              *lnbits.User `json:"inline_send_to"`
	To_SpecificUser bool         `json:"to_specific_user"`
	Memo            string       `json:"inline_send_memo"`
	LanguageCode    string       `json:"languagecode"`
}

type InlineTipjar

type InlineTipjar struct {
	*transaction.Base
	Message       string         `json:"inline_tipjar_message"`
	Amount        int            `json:"inline_tipjar_amount"`
	GivenAmount   int            `json:"inline_tipjar_givenamount"`
	PerUserAmount int            `json:"inline_tipjar_peruseramount"`
	To            *lnbits.User   `json:"inline_tipjar_to"`
	From          []*lnbits.User `json:"inline_tipjar_from"`
	Memo          string         `json:"inline_tipjar_memo"`
	NTotal        int            `json:"inline_tipjar_ntotal"`
	NGiven        int            `json:"inline_tipjar_ngiven"`
	LanguageCode  string         `json:"languagecode"`
}

type Interceptor

type Interceptor struct {
	Type   InterceptorType
	Before []intercept.Func
	After  []intercept.Func
}

type InterceptorType

type InterceptorType int
const (
	MessageInterceptor InterceptorType = iota
	CallbackInterceptor
	QueryInterceptor
)

type LnurlPayState

type LnurlPayState struct {
	*transaction.Base
	From           *lnbits.User         `json:"from"`
	LNURLPayParams lnurl.LNURLPayParams `json:"LNURLPayParams"`
	LNURLPayValues lnurl.LNURLPayValues `json:"LNURLPayValues"`
	Amount         int                  `json:"amount"`
	Comment        string               `json:"comment"`
	LanguageCode   string               `json:"languagecode"`
}

LnurlPayState saves the state of the user for an LNURL payment

type LnurlWithdrawState

type LnurlWithdrawState struct {
	*transaction.Base
	From                  *lnbits.User                `json:"from"`
	LNURLWithdrawResponse lnurl.LNURLWithdrawResponse `json:"LNURLWithdrawResponse"`
	LNURResponse          lnurl.LNURLResponse         `json:"LNURLResponse"`
	Amount                int                         `json:"amount"`
	Comment               string                      `json:"comment"`
	LanguageCode          string                      `json:"languagecode"`
	Success               bool                        `json:"success"`
	Invoice               lnbits.BitInvoice           `json:"invoice"`
	Message               string                      `json:"message"`
}

LnurlWithdrawState saves the state of the user for an LNURL payment

type Message

type Message struct {
	Message *tb.Message `json:"message"`
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(m *tb.Message, opts ...MessageOption) *Message

func (Message) Key

func (msg Message) Key() string

type MessageOption

type MessageOption func(m *Message)

func WithDuration

func WithDuration(duration time.Duration, tipBot *TipBot) MessageOption

type PayData

type PayData struct {
	*transaction.Base
	From            *lnbits.User `json:"from"`
	Invoice         string       `json:"invoice"`
	Hash            string       `json:"hash"`
	Proof           string       `json:"proof"`
	Memo            string       `json:"memo"`
	Message         string       `json:"message"`
	Amount          int64        `json:"amount"`
	LanguageCode    string       `json:"languagecode"`
	TelegramMessage *tb.Message  `json:"telegrammessage"`
}

type SendData

type SendData struct {
	*transaction.Base
	From           *lnbits.User `json:"from"`
	ToTelegramId   int64        `json:"to_telegram_id"`
	ToTelegramUser string       `json:"to_telegram_user"`
	Memo           string       `json:"memo"`
	Message        string       `json:"message"`
	Amount         int64        `json:"amount"`
	LanguageCode   string       `json:"languagecode"`
}

type TipBot

type TipBot struct {
	Database *gorm.DB
	Bunt     *storage.DB

	Telegram *telebot.Bot
	Client   *lnbits.Client

	Cache
	// contains filtered or unexported fields
}

func NewBot

func NewBot() TipBot

NewBot migrates data and creates a new bot

func (*TipBot) CreateWalletForTelegramUser

func (bot *TipBot) CreateWalletForTelegramUser(tbUser *tb.User) (*lnbits.User, error)

func (*TipBot) GetHttpClient

func (bot *TipBot) GetHttpClient() (*http.Client, error)

func (*TipBot) GetUserBalance

func (bot *TipBot) GetUserBalance(user *lnbits.User) (amount int, err error)

func (*TipBot) GetUserBalanceCached

func (bot *TipBot) GetUserBalanceCached(user *lnbits.User) (amount int, err error)

func (TipBot) HandleLNURL added in v0.4.2

func (bot TipBot) HandleLNURL(rawlnurl string) (string, lnurl.LNURLParams, error)

fiatjaf/go-lnurl 1.8.4 with proxy

func (*TipBot) SendCheckSyntax

func (bot *TipBot) SendCheckSyntax(ctx context.Context, m *tb.Message) (bool, string)

func (TipBot) Start

func (bot TipBot) Start()

Start will initialize the Telegram bot and lnbits.

func (*TipBot) UserExists

func (bot *TipBot) UserExists(user *tb.User) (*lnbits.User, bool)

func (*TipBot) UserGetAnonLightningAddress

func (bot *TipBot) UserGetAnonLightningAddress(user *lnbits.User) (string, error)

func (*TipBot) UserGetLightningAddress

func (bot *TipBot) UserGetLightningAddress(user *lnbits.User) (string, error)

type TipTooltip

type TipTooltip struct {
	Message
	TipAmount int        `json:"tip_amount"`
	Ntips     int        `json:"ntips"`
	LastTip   time.Time  `json:"last_tip"`
	Tippers   []*tb.User `json:"tippers"`
}

func NewTipTooltip

func NewTipTooltip(m *tb.Message, opts ...TipTooltipOption) *TipTooltip

func (TipTooltip) Key

func (ttt TipTooltip) Key() string

type TipTooltipOption

type TipTooltipOption func(m *TipTooltip)

func TipAmount

func TipAmount(amount int) TipTooltipOption

func Tips

func Tips(nTips int) TipTooltipOption

type Transaction

type Transaction struct {
	ID           uint              `gorm:"primarykey"`
	Time         time.Time         `json:"time"`
	Bot          *TipBot           `gorm:"-"`
	From         *lnbits.User      `json:"from" gorm:"-"`
	To           *lnbits.User      `json:"to" gorm:"-"`
	FromId       int64             `json:"from_id" `
	ToId         int64             `json:"to_id" `
	FromUser     string            `json:"from_user"`
	ToUser       string            `json:"to_user"`
	Type         string            `json:"type"`
	Amount       int               `json:"amount"`
	ChatID       int64             `json:"chat_id"`
	ChatName     string            `json:"chat_name"`
	Memo         string            `json:"memo"`
	Success      bool              `json:"success"`
	FromWallet   string            `json:"from_wallet"`
	ToWallet     string            `json:"to_wallet"`
	FromLNbitsID string            `json:"from_lnbits"`
	ToLNbitsID   string            `json:"to_lnbits"`
	Invoice      lnbits.BitInvoice `gorm:"embedded;embeddedPrefix:invoice_"`
}

func NewTransaction

func NewTransaction(bot *TipBot, from *lnbits.User, to *lnbits.User, amount int, opts ...TransactionOption) *Transaction

func (*Transaction) Send

func (t *Transaction) Send() (success bool, err error)

func (*Transaction) SendTransaction

func (t *Transaction) SendTransaction(bot *TipBot, from *lnbits.User, to *lnbits.User, amount int, memo string) (bool, error)

type TransactionOption

type TransactionOption func(t *Transaction)

func TransactionChat

func TransactionChat(chat *tb.Chat) TransactionOption

func TransactionType

func TransactionType(transactionType string) TransactionOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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