entity

package
v0.74.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: MIT Imports: 8 Imported by: 21

Documentation

Overview

Package entity contains message formatting and styling helpers.

Code generated by mkentity, DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeLength added in v0.30.0

func ComputeLength(s string) int

ComputeLength returns length of s encoded as UTF-16 string.

While Telegram API docs state that they expect the number of UTF-8 code points, in fact they are talking about UTF-16 code units.

func ComputeLengthBytes added in v0.54.0

func ComputeLengthBytes(s []byte) (n int)

ComputeLengthBytes returns length of s encoded as UTF-16 string.

While Telegram API docs state that they expect the number of UTF-8 code points, in fact they are talking about UTF-16 code units.

func SortEntities added in v0.54.0

func SortEntities(entity []tg.MessageEntityClass)

SortEntities sorts entities as TDLib does it.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder builds message string and text entities.

func (*Builder) BankCard

func (b *Builder) BankCard(s string) *Builder

BankCard adds and formats message as BankCard message entity.

See https://core.telegram.org/constructor/messageEntityBankCard.

func (*Builder) Blockquote

func (b *Builder) Blockquote(s string) *Builder

Blockquote adds and formats message as Blockquote message entity.

See https://core.telegram.org/constructor/messageEntityBlockquote.

func (*Builder) Bold

func (b *Builder) Bold(s string) *Builder

Bold adds and formats message as Bold message entity.

See https://core.telegram.org/constructor/messageEntityBold.

func (*Builder) BotCommand

func (b *Builder) BotCommand(s string) *Builder

BotCommand adds and formats message as BotCommand message entity.

See https://core.telegram.org/constructor/messageEntityBotCommand.

func (*Builder) Cashtag

func (b *Builder) Cashtag(s string) *Builder

Cashtag adds and formats message as Cashtag message entity.

See https://core.telegram.org/constructor/messageEntityCashtag.

func (*Builder) Code

func (b *Builder) Code(s string) *Builder

Code adds and formats message as Code message entity.

See https://core.telegram.org/constructor/messageEntityCode.

func (*Builder) Complete

func (b *Builder) Complete() (string, []tg.MessageEntityClass)

Complete returns build result and resets builder.

func (*Builder) CustomEmoji added in v0.63.0

func (b *Builder) CustomEmoji(s string, documentID int64) *Builder

CustomEmoji adds and formats message as CustomEmoji message entity.

See https://core.telegram.org/constructor/messageEntityCustomEmoji.

func (*Builder) Email

func (b *Builder) Email(s string) *Builder

Email adds and formats message as Email message entity.

See https://core.telegram.org/constructor/messageEntityEmail.

func (*Builder) EntitiesLen added in v0.54.0

func (b *Builder) EntitiesLen() int

EntitiesLen return length of added entities.

func (*Builder) Format added in v0.30.0

func (b *Builder) Format(s string, formats ...Formatter) *Builder

Format formats message using given formatters.

func (*Builder) GrowEntities

func (b *Builder) GrowEntities(n int)

GrowEntities grows internal buffer capacity.

func (*Builder) GrowText

func (b *Builder) GrowText(n int)

GrowText grows internal buffer capacity.

func (*Builder) Hashtag

func (b *Builder) Hashtag(s string) *Builder

Hashtag adds and formats message as Hashtag message entity.

See https://core.telegram.org/constructor/messageEntityHashtag.

func (*Builder) Italic

func (b *Builder) Italic(s string) *Builder

Italic adds and formats message as Italic message entity.

See https://core.telegram.org/constructor/messageEntityItalic.

func (*Builder) LastEntity added in v0.54.0

func (b *Builder) LastEntity() (tg.MessageEntityClass, bool)

LastEntity returns last entity if any.

func (*Builder) Mention

func (b *Builder) Mention(s string) *Builder

Mention adds and formats message as Mention message entity.

See https://core.telegram.org/constructor/messageEntityMention.

func (*Builder) MentionName

func (b *Builder) MentionName(s string, userID tg.InputUserClass) *Builder

MentionName adds and formats message as MentionName message entity.

See https://core.telegram.org/constructor/inputMessageEntityMentionName.

func (*Builder) Phone

func (b *Builder) Phone(s string) *Builder

Phone adds and formats message as Phone message entity.

See https://core.telegram.org/constructor/messageEntityPhone.

func (*Builder) Plain

func (b *Builder) Plain(s string) *Builder

Plain formats message as plain text.

func (*Builder) Pre

func (b *Builder) Pre(s string, language string) *Builder

Pre adds and formats message as Pre message entity.

See https://core.telegram.org/constructor/messageEntityPre.

func (*Builder) Raw added in v0.54.0

func (b *Builder) Raw() (string, []tg.MessageEntityClass)

Raw returns raw result and resets builder without fixing spaces.

func (*Builder) Reset added in v0.54.0

func (b *Builder) Reset()

Reset resets the Builder to be empty.

func (*Builder) ShrinkPreCode added in v0.54.0

func (b *Builder) ShrinkPreCode()

ShrinkPreCode merges following <pre> and <code> entities, if needed.

This function is used by formatters to be compliant with TDLib.

func (*Builder) Spoiler added in v0.54.0

func (b *Builder) Spoiler(s string) *Builder

Spoiler adds and formats message as Spoiler message entity.

See https://core.telegram.org/constructor/messageEntitySpoiler.

func (*Builder) Strike

func (b *Builder) Strike(s string) *Builder

Strike adds and formats message as Strike message entity.

See https://core.telegram.org/constructor/messageEntityStrike.

func (*Builder) TextRange added in v0.54.0

func (b *Builder) TextRange(from, to int) string

TextRange returns message text of given byte (UTF-8) range.

If range is invalid, it will panic.

func (*Builder) TextURL

func (b *Builder) TextURL(s string, uRL string) *Builder

TextURL adds and formats message as TextURL message entity.

See https://core.telegram.org/constructor/messageEntityTextUrl.

func (*Builder) Token added in v0.54.0

func (b *Builder) Token() Token

Token creates new Token.

func (*Builder) URL

func (b *Builder) URL(s string) *Builder

URL adds and formats message as URL message entity.

See https://core.telegram.org/constructor/messageEntityUrl.

func (*Builder) UTF16Len added in v0.54.0

func (b *Builder) UTF16Len() int

UTF16Len returns length of text in UTF-16 codepoints.

func (*Builder) UTF8Len added in v0.54.0

func (b *Builder) UTF8Len() int

UTF8Len returns length of text in bytes.

func (*Builder) Underline

func (b *Builder) Underline(s string) *Builder

Underline adds and formats message as Underline message entity.

See https://core.telegram.org/constructor/messageEntityUnderline.

func (*Builder) Unknown added in v0.54.0

func (b *Builder) Unknown(s string) *Builder

Unknown adds and formats message as Unknown message entity.

See https://core.telegram.org/constructor/messageEntityUnknown.

func (*Builder) Write added in v0.54.0

func (b *Builder) Write(s []byte) (int, error)

Write implements io.Writer.

func (*Builder) WriteByte added in v0.54.0

func (b *Builder) WriteByte(s byte) error

WriteByte implements io.ByteWriter.

func (*Builder) WriteRune added in v0.54.0

func (b *Builder) WriteRune(s rune) (int, error)

WriteRune implements rune writer.

func (*Builder) WriteString added in v0.54.0

func (b *Builder) WriteString(s string) (int, error)

WriteString implements io.StringWriter.

type Formatter added in v0.30.0

type Formatter func(offset, limit int) tg.MessageEntityClass

Formatter is a message entity constructor.

func BankCard added in v0.30.0

func BankCard() Formatter

BankCard creates Formatter of BankCard message entity.

See https://core.telegram.org/constructor/messageEntityBankCard.

func Blockquote added in v0.30.0

func Blockquote() Formatter

Blockquote creates Formatter of Blockquote message entity.

See https://core.telegram.org/constructor/messageEntityBlockquote.

func Bold added in v0.30.0

func Bold() Formatter

Bold creates Formatter of Bold message entity.

See https://core.telegram.org/constructor/messageEntityBold.

func BotCommand added in v0.30.0

func BotCommand() Formatter

BotCommand creates Formatter of BotCommand message entity.

See https://core.telegram.org/constructor/messageEntityBotCommand.

func Cashtag added in v0.30.0

func Cashtag() Formatter

Cashtag creates Formatter of Cashtag message entity.

See https://core.telegram.org/constructor/messageEntityCashtag.

func Code added in v0.30.0

func Code() Formatter

Code creates Formatter of Code message entity.

See https://core.telegram.org/constructor/messageEntityCode.

func CustomEmoji added in v0.63.0

func CustomEmoji(documentID int64) Formatter

CustomEmoji creates Formatter of CustomEmoji message entity.

See https://core.telegram.org/constructor/messageEntityCustomEmoji.

func Email added in v0.30.0

func Email() Formatter

Email creates Formatter of Email message entity.

See https://core.telegram.org/constructor/messageEntityEmail.

func Hashtag added in v0.30.0

func Hashtag() Formatter

Hashtag creates Formatter of Hashtag message entity.

See https://core.telegram.org/constructor/messageEntityHashtag.

func Italic added in v0.30.0

func Italic() Formatter

Italic creates Formatter of Italic message entity.

See https://core.telegram.org/constructor/messageEntityItalic.

func Mention added in v0.30.0

func Mention() Formatter

Mention creates Formatter of Mention message entity.

See https://core.telegram.org/constructor/messageEntityMention.

func MentionName added in v0.30.0

func MentionName(userID tg.InputUserClass) Formatter

MentionName creates Formatter of MentionName message entity.

See https://core.telegram.org/constructor/inputMessageEntityMentionName.

func Phone added in v0.30.0

func Phone() Formatter

Phone creates Formatter of Phone message entity.

See https://core.telegram.org/constructor/messageEntityPhone.

func Pre added in v0.30.0

func Pre(language string) Formatter

Pre creates Formatter of Pre message entity.

See https://core.telegram.org/constructor/messageEntityPre.

func Spoiler added in v0.54.0

func Spoiler() Formatter

Spoiler creates Formatter of Spoiler message entity.

See https://core.telegram.org/constructor/messageEntitySpoiler.

func Strike added in v0.30.0

func Strike() Formatter

Strike creates Formatter of Strike message entity.

See https://core.telegram.org/constructor/messageEntityStrike.

func TextURL added in v0.30.0

func TextURL(uRL string) Formatter

TextURL creates Formatter of TextURL message entity.

See https://core.telegram.org/constructor/messageEntityTextUrl.

func URL added in v0.30.0

func URL() Formatter

URL creates Formatter of URL message entity.

See https://core.telegram.org/constructor/messageEntityUrl.

func Underline added in v0.30.0

func Underline() Formatter

Underline creates Formatter of Underline message entity.

See https://core.telegram.org/constructor/messageEntityUnderline.

func Unknown added in v0.54.0

func Unknown() Formatter

Unknown creates Formatter of Unknown message entity.

See https://core.telegram.org/constructor/messageEntityUnknown.

type Token added in v0.54.0

type Token struct {
	// contains filtered or unexported fields
}

Token represents raw point in a message string.

func (Token) Apply added in v0.54.0

func (t Token) Apply(builder *Builder, f ...Formatter)

Apply formats range between token start and current state using given Formatter slice.

func (Token) Text added in v0.54.0

func (t Token) Text(builder *Builder) string

Text message string between token start and current state.

func (Token) UTF16Length added in v0.54.0

func (t Token) UTF16Length(builder *Builder) int

UTF16Length returns UTF-16 length between token start and current state.

func (Token) UTF16Offset added in v0.54.0

func (t Token) UTF16Offset() int

UTF16Offset returns UTF-16 offset.

func (Token) UTF8Length added in v0.54.0

func (t Token) UTF8Length(builder *Builder) int

UTF8Length return UTF-8 length between token start and current state.

func (Token) UTF8Offset added in v0.54.0

func (t Token) UTF8Offset() int

UTF8Offset return UTF-8 offset.

type UserResolver added in v0.54.0

type UserResolver = func(id int64) (tg.InputUserClass, error)

UserResolver is callback for resolving InputUser by ID.

Jump to

Keyboard shortcuts

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