functions

package
v0.0.0-...-ace172b Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MaxChannelID int64 = -1000000000000

Variables

View Source
var ErrFileNotFound = errors.New("no media was found in the message")

Functions

func ChatIdToMtproto

func ChatIdToMtproto(id int64) int64

ChatIdToMtproto converts a bot api channel id starting with -100 to an mtproto id.

func FileFromMessage

func FileFromMessage(m *gotgbot.Message) *model.File

FileFromMessage extracts data about a file from the message.

func FileSizeToString

func FileSizeToString(n int64) string

FileSizeToString converts file size in bytes to a user friendly string.

func FormatString

func FormatString(template string, values map[string]string) string

FormatString formats a Pythonic syntax string using a map of key-value pairs.

func FormatUnixTimestamp

func FormatUnixTimestamp(timestamp int64) string

FormatUnixTimestamp converts a unix timestamp into a string in the dd/mm/yyyy format.

func GetChatFromUsername

func GetChatFromUsername(bot *gotgbot.Bot, username string) (*gotgbot.ChatFullInfo, error)

GetChatFromUsername constructs a getChat request using a username.

func HasMedia

func HasMedia(m *gotgbot.Message) bool

HasMedia reports whether message contains media.

func MtprotoToChatId

func MtprotoToChatId(id int64) int64

MtprotoToChatId converts a mtproto chat id to a bot api one. Should only be used for channel or supergroup ids.

func RandString

func RandString(length int) string

RandString creates a randomly generated string of given length.

func RemoveExtension

func RemoveExtension(input string) string

RemoveExtension removes the extension from a file name if any.

func RemoveSymbols

func RemoveSymbols(input string) string

RemoveSymbols returns a copy of the string will all non alpha-numeric characters removed.

Types

type FloodWaitError

type FloodWaitError struct {
	Method   string
	Duration int64
}

FloodWaitError is a telegram rate limit error.

func AsFloodWait

func AsFloodWait(e error) (*FloodWaitError, bool)

AsFloodWait attemots to parse a telegram bot API floodwait error as a FloodWaitError.

func (*FloodWaitError) Error

func (f *FloodWaitError) Error() string

func (*FloodWaitError) Wait

func (f *FloodWaitError) Wait()

Wait sleeps for duration.

type MessageLink struct {
	ChatId    int64
	MessageId int64
	Username  string
}

MessageLink is parsed data from a message link.

func ParseMessageLink(s string) (*MessageLink, error)

ParseMessageLink parses a message link in the format t.me/c/<id> or t.me/<username>.

func (*MessageLink) GetChat

func (m *MessageLink) GetChat(bot *gotgbot.Bot) (*gotgbot.ChatFullInfo, error)

GetChat gets a chat using it's id or username.

Jump to

Keyboard shortcuts

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