move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package styling
|
||||
|
||||
import (
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/message/entity"
|
||||
)
|
||||
|
||||
type textBuilder struct {
|
||||
*entity.Builder
|
||||
}
|
||||
|
||||
func (b *textBuilder) Perform(texts ...StyledTextOption) error {
|
||||
b.GrowEntities(len(texts))
|
||||
var length int
|
||||
for i := range texts {
|
||||
length += texts[i].size
|
||||
}
|
||||
b.GrowText(length)
|
||||
|
||||
for idx, opt := range texts {
|
||||
if err := opt.perform(b); err != nil {
|
||||
return errors.Wrapf(err, "perform %d styling option", idx+2)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Perform performs all options to the given builder.
|
||||
func Perform(builder *entity.Builder, texts ...StyledTextOption) error {
|
||||
tb := &textBuilder{Builder: builder}
|
||||
return tb.Perform(texts...)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// Package styling contains styling options for Telegram messages.
|
||||
package styling
|
||||
@@ -0,0 +1,43 @@
|
||||
package styling
|
||||
|
||||
import (
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/message/entity"
|
||||
)
|
||||
|
||||
// StyledTextOption is an option for styling text.
|
||||
type StyledTextOption struct {
|
||||
size int
|
||||
perform func(b *textBuilder) error
|
||||
}
|
||||
|
||||
// Zero returns true if option is zero value.
|
||||
func (s StyledTextOption) Zero() bool {
|
||||
return s.perform == nil
|
||||
}
|
||||
|
||||
func styledTextOption(s string, perform func(b *textBuilder) error) StyledTextOption {
|
||||
return StyledTextOption{
|
||||
perform: perform,
|
||||
size: len(s),
|
||||
}
|
||||
}
|
||||
|
||||
// Plain formats text without any entities.
|
||||
func Plain(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Plain(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Custom formats text using given callback.
|
||||
func Custom(cb func(eb *entity.Builder) error) StyledTextOption {
|
||||
return StyledTextOption{
|
||||
size: 0,
|
||||
perform: func(b *textBuilder) error {
|
||||
return cb(b.Builder)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
//go:generate go run go.mau.fi/mautrix-telegram/pkg/gotd/telegram/message/internal/mkentity -template styling -output options.gen.go
|
||||
@@ -0,0 +1,213 @@
|
||||
// Code generated by mkentity, DO NOT EDIT.
|
||||
package styling
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
var (
|
||||
_ = tg.Invoker(nil)
|
||||
_ = context.Context(nil)
|
||||
)
|
||||
|
||||
// Unknown formats text as Unknown entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityUnknown.
|
||||
func Unknown(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Unknown(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Mention formats text as Mention entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityMention.
|
||||
func Mention(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Mention(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Hashtag formats text as Hashtag entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityHashtag.
|
||||
func Hashtag(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Hashtag(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// BotCommand formats text as BotCommand entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityBotCommand.
|
||||
func BotCommand(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.BotCommand(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// URL formats text as URL entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityUrl.
|
||||
func URL(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.URL(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Email formats text as Email entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityEmail.
|
||||
func Email(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Email(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Bold formats text as Bold entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityBold.
|
||||
func Bold(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Bold(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Italic formats text as Italic entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityItalic.
|
||||
func Italic(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Italic(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Code formats text as Code entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityCode.
|
||||
func Code(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Code(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Pre formats text as Pre entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityPre.
|
||||
func Pre(s string, language string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Pre(s, language)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// TextURL formats text as TextURL entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityTextUrl.
|
||||
func TextURL(s string, uRL string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.TextURL(s, uRL)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// MentionName formats text as MentionName entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/inputMessageEntityMentionName.
|
||||
func MentionName(s string, userID tg.InputUserClass) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.MentionName(s, userID)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Phone formats text as Phone entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityPhone.
|
||||
func Phone(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Phone(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Cashtag formats text as Cashtag entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityCashtag.
|
||||
func Cashtag(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Cashtag(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Underline formats text as Underline entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityUnderline.
|
||||
func Underline(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Underline(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Strike formats text as Strike entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityStrike.
|
||||
func Strike(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Strike(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// BankCard formats text as BankCard entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityBankCard.
|
||||
func BankCard(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.BankCard(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Spoiler formats text as Spoiler entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntitySpoiler.
|
||||
func Spoiler(s string) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Spoiler(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// CustomEmoji formats text as CustomEmoji entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityCustomEmoji.
|
||||
func CustomEmoji(s string, documentID int64) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.CustomEmoji(s, documentID)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Blockquote formats text as Blockquote entity.
|
||||
//
|
||||
// See https://core.telegram.org/constructor/messageEntityBlockquote.
|
||||
func Blockquote(s string, collapsed bool) StyledTextOption {
|
||||
return styledTextOption(s, func(b *textBuilder) error {
|
||||
b.Blockquote(s, collapsed)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user