(fix): finalize v2 contracts (tests): cover v2 migration (doc): prepare release guidance
This commit is contained in:
+51
-5
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/tgapi"
|
||||
)
|
||||
|
||||
type richValidator struct {
|
||||
@@ -132,6 +132,8 @@ func (v *richValidator) text(text tgapi.RichText, depth int) error {
|
||||
return v.addChars(el.AlternativeText)
|
||||
case tgapi.RichTextMathematicalExpression:
|
||||
return v.addChars(el.Expression)
|
||||
case tgapi.RichTextButton:
|
||||
return v.button(el.Button, depth+1)
|
||||
case tgapi.RichTextAnchor:
|
||||
return nil
|
||||
}
|
||||
@@ -143,33 +145,46 @@ func (v *richValidator) text(text tgapi.RichText, depth int) error {
|
||||
var child tgapi.RichText
|
||||
switch el := text.(type) {
|
||||
case tgapi.RichTextWrap:
|
||||
child = el.Text
|
||||
case tgapi.RichTextURL:
|
||||
child = el.Text
|
||||
case tgapi.RichTextEmailAddress:
|
||||
child = el.Text
|
||||
case tgapi.RichTextPhoneNumber:
|
||||
child = el.Text
|
||||
case tgapi.RichTextBankCardNumber:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, el.BankCardNumber); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextMention:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, "@"+strings.TrimPrefix(el.Username, "@")); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextHashtag:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, "#"+strings.TrimPrefix(el.Hashtag, "#")); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextCashtag:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, "$"+strings.TrimPrefix(el.Cashtag, "$")); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextBotCommand:
|
||||
child = el.Text
|
||||
if err := validateAutomaticEntity(el.Text, "/"+strings.TrimPrefix(el.BotCommand, "/")); err != nil {
|
||||
return err
|
||||
}
|
||||
case tgapi.RichTextAnchorLink:
|
||||
child = el.Text
|
||||
case tgapi.RichTextReference:
|
||||
child = el.Text
|
||||
case tgapi.RichTextReferenceLink:
|
||||
child = el.Text
|
||||
case tgapi.RichTextDateTime:
|
||||
child = el.Text
|
||||
case tgapi.RichTextTextMention:
|
||||
child = el.Text
|
||||
default:
|
||||
@@ -350,6 +365,40 @@ func (v *richValidator) block(block tgapi.InputRichBlock, depth int) error {
|
||||
return err
|
||||
}
|
||||
return v.nested(el.Blocks, depth+1)
|
||||
case tgapi.InputRichBlockButtons:
|
||||
if err := expectBlockType(el.Type, tgapi.InputRichTypeButtons); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(el.Buttons) < 1 || len(el.Buttons) > 8 {
|
||||
return ErrRichInvalidButton
|
||||
}
|
||||
switch el.Align {
|
||||
case "", tgapi.RichBlockButtonLeft, tgapi.RichBlockButtonCenter, tgapi.RichBlockButtonRight:
|
||||
default:
|
||||
return ErrRichInvalidButton
|
||||
}
|
||||
for _, button := range el.Buttons {
|
||||
if err := v.button(button, depth+1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case tgapi.InputRichBlockExpandableBlockQuotation:
|
||||
if err := expectBlockType(el.Type, tgapi.InputRichTypeExpandableBlockQuotation); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v.text(el.Text, depth+1); err != nil {
|
||||
return err
|
||||
}
|
||||
return v.textValue(el.Credit, depth+1)
|
||||
case tgapi.InputRichBlockDocument:
|
||||
if err := expectBlockType(el.Type, tgapi.InputRichTypeDocument); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v.addMedia(el.Document, tgapi.InputMediaTypeDocument); err != nil {
|
||||
return err
|
||||
}
|
||||
return v.caption(el.Caption, depth+1)
|
||||
case tgapi.InputRichBlockPullQuotation:
|
||||
if err := expectBlockType(el.Type, tgapi.InputRichTypePullQuotation); err != nil {
|
||||
return err
|
||||
@@ -390,10 +439,7 @@ func (v *richValidator) block(block tgapi.InputRichBlock, depth int) error {
|
||||
if err := validateTableCell(cell); err != nil {
|
||||
return err
|
||||
}
|
||||
span := cell.ColSpan
|
||||
if span < 1 {
|
||||
span = 1
|
||||
}
|
||||
span := max(cell.ColSpan, 1)
|
||||
columns += span
|
||||
if err := v.text(cell.Text, depth+1); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user