FILE / ScuroNeko/Laniakea
tgrich/ast.go
Исходный файл и его история в репозитории.
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
192 lines
5.4 KiB
Go
192 lines
5.4 KiB
Go
package tgrich
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
|
)
|
|
|
|
const (
|
|
maxRichTextChars = 32768
|
|
maxRichBlocks = 500
|
|
maxRichDepth = 16
|
|
maxRichMedia = 50
|
|
maxTableColumns = 20
|
|
)
|
|
|
|
// Text creates a plain rich-text node.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Text(s string) tgapi.RichText { return tgapi.RichTextPlain(s) }
|
|
|
|
// Bold applies bold formatting to t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Bold(t tgapi.RichText) tgapi.RichText { return tgapi.RichTextWrap{Tag: "bold", Text: t} }
|
|
|
|
// Italic applies italic formatting to t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Italic(t tgapi.RichText) tgapi.RichText { return tgapi.RichTextWrap{Tag: "italic", Text: t} }
|
|
|
|
// Underline applies underline formatting to t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Underline(t tgapi.RichText) tgapi.RichText { return tgapi.RichTextWrap{Tag: "underline", Text: t} }
|
|
|
|
// Strikethrough applies strikethrough formatting to t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Strikethrough(t tgapi.RichText) tgapi.RichText {
|
|
return tgapi.RichTextWrap{Tag: "strikethrough", Text: t}
|
|
}
|
|
|
|
// Spoiler hides t behind a spoiler.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Spoiler(t tgapi.RichText) tgapi.RichText { return tgapi.RichTextWrap{Tag: "spoiler", Text: t} }
|
|
|
|
// DateTime associates t with ts using Telegram's default date-time format.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func DateTime(t tgapi.RichText, ts time.Time) tgapi.RichText {
|
|
return tgapi.RichTextDateTime{Text: t, UnixTime: ts.Unix()}
|
|
}
|
|
|
|
// DateTimeWithFormat associates t with ts using format.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func DateTimeWithFormat(t tgapi.RichText, ts time.Time, format string) tgapi.RichText {
|
|
return tgapi.RichTextDateTime{Text: t, UnixTime: ts.Unix(), DateTimeFormat: format}
|
|
}
|
|
|
|
// TextMention mentions u with the display text t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func TextMention(t tgapi.RichText, u tgapi.User) tgapi.RichText {
|
|
return tgapi.RichTextTextMention{Text: t, User: u}
|
|
}
|
|
|
|
// Subscript applies subscript formatting to t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Subscript(t tgapi.RichText) tgapi.RichText { return tgapi.RichTextWrap{Tag: "subscript", Text: t} }
|
|
|
|
// Superscript applies superscript formatting to t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Superscript(t tgapi.RichText) tgapi.RichText {
|
|
return tgapi.RichTextWrap{Tag: "superscript", Text: t}
|
|
}
|
|
|
|
// Marked highlights t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Marked(t tgapi.RichText) tgapi.RichText { return tgapi.RichTextWrap{Tag: "marked", Text: t} }
|
|
|
|
// Code applies monospaced formatting to t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Code(t tgapi.RichText) tgapi.RichText { return tgapi.RichTextWrap{Tag: "code", Text: t} }
|
|
|
|
// Emoji creates a custom emoji with emojiID and alternative text t.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Emoji(t, emojiID string) tgapi.RichText {
|
|
return tgapi.RichTextCustomEmoji{CustomEmojiID: emojiID, AlternativeText: t}
|
|
}
|
|
|
|
// MathExpression creates an inline LaTeX expression.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func MathExpression(exp string) tgapi.RichTextMathematicalExpression {
|
|
return tgapi.RichTextMathematicalExpression{Expression: exp}
|
|
}
|
|
|
|
// URL links t to url.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func URL(t tgapi.RichText, url string) tgapi.RichTextURL { return tgapi.RichTextURL{Text: t, URL: url} }
|
|
|
|
// Email marks t as an email address.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Email(t tgapi.RichText, email string) tgapi.RichTextEmailAddress {
|
|
return tgapi.RichTextEmailAddress{Text: t, EmailAddress: email}
|
|
}
|
|
|
|
// Phone marks t as a phone number.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Phone(t tgapi.RichText, phone string) tgapi.RichTextPhoneNumber {
|
|
return tgapi.RichTextPhoneNumber{Text: t, PhoneNumber: phone}
|
|
}
|
|
|
|
// BankCardNumber marks t as a bank card number.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func BankCardNumber(t tgapi.RichText, number string) tgapi.RichTextBankCardNumber {
|
|
return tgapi.RichTextBankCardNumber{Text: t, BankCardNumber: number}
|
|
}
|
|
|
|
// Mention marks t as a mention of username.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Mention(t tgapi.RichText, username string) tgapi.RichTextMention {
|
|
return tgapi.RichTextMention{Text: t, Username: username}
|
|
}
|
|
|
|
// Hashtag marks t as hashtag.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Hashtag(t tgapi.RichText, hashtag string) tgapi.RichTextHashtag {
|
|
return tgapi.RichTextHashtag{Text: t, Hashtag: hashtag}
|
|
}
|
|
|
|
// Cashtag marks t as cashtag.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Cashtag(t tgapi.RichText, cashtag string) tgapi.RichTextCashtag {
|
|
return tgapi.RichTextCashtag{Text: t, Cashtag: cashtag}
|
|
}
|
|
|
|
// BotCommand marks t as command.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func BotCommand(t tgapi.RichText, command string) tgapi.RichTextBotCommand {
|
|
return tgapi.RichTextBotCommand{Text: t, BotCommand: command}
|
|
}
|
|
|
|
// TextAnchor creates an inline anchor named name.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func TextAnchor(name string) tgapi.RichTextAnchor {
|
|
return tgapi.RichTextAnchor{Name: name}
|
|
}
|
|
|
|
// AnchorLink links t to the anchor named name.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func AnchorLink(t tgapi.RichText, name string) tgapi.RichTextAnchorLink {
|
|
return tgapi.RichTextAnchorLink{Text: t, AnchorName: name}
|
|
}
|
|
|
|
// Reference defines t as a named reference target.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Reference(t tgapi.RichText, name string) tgapi.RichTextReference {
|
|
return tgapi.RichTextReference{Text: t, Name: name}
|
|
}
|
|
|
|
// ReferenceLink links t to the named reference name.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func ReferenceLink(t tgapi.RichText, name string) tgapi.RichTextReferenceLink {
|
|
return tgapi.RichTextReferenceLink{Text: t, ReferenceName: name}
|
|
}
|
|
|
|
// Concat concatenates rich-text nodes.
|
|
//
|
|
// Since: Bot API 10.1
|
|
func Concat(items ...tgapi.RichText) tgapi.RichText { return tgapi.RichTextArray(items) }
|