Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from mymmrac:main #111

Merged
merged 7 commits into from
Jun 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated types to Telegram Bot API v7.4
mymmrac committed Jun 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit fb691f1aedf4498978193faa7a0a2d07a4b48cc1
9 changes: 9 additions & 0 deletions telegoutil/message_entity.go
Original file line number Diff line number Diff line change
@@ -161,6 +161,15 @@ func (c MessageEntityCollection) Blockquote() MessageEntityCollection {
return c
}

// ExpandableBlockquote assigns expandable blockquote entity and returns new collection
func (c MessageEntityCollection) ExpandableBlockquote() MessageEntityCollection {
c.entities = append(c.entities, telego.MessageEntity{
Type: telego.EntityTypeExpandableBlockquote,
Length: UTF16TextLen(c.text),
})
return c
}

// Code assigns code entity and returns new collection
func (c MessageEntityCollection) Code() MessageEntityCollection {
c.entities = append(c.entities, telego.MessageEntity{
4 changes: 3 additions & 1 deletion telegoutil/message_entity_test.go
Original file line number Diff line number Diff line change
@@ -67,9 +67,10 @@ func TestMessageEntities(t *testing.T) {

Entity(text2).CustomEmoji(text1),
Entity(text3).Blockquote(),
Entity(text4).ExpandableBlockquote(),
)

assert.Equal(t, strings.Repeat(text1+text2+text3+text4, 5)+text1+text2+text3, text)
assert.Equal(t, strings.Repeat(text1+text2+text3+text4, 6), text)
assert.Equal(t, []telego.MessageEntity{
{Type: "italic", Offset: 4, Length: 5, URL: "", User: nil, Language: ""},
{Type: "bold", Offset: 9, Length: 5, URL: "", User: nil, Language: ""},
@@ -97,6 +98,7 @@ func TestMessageEntities(t *testing.T) {
{Type: "email", Offset: 95, Length: 4, URL: "", User: nil, Language: ""},
{Type: "custom_emoji", Offset: 99, Length: 5, URL: "", User: nil, Language: "", CustomEmojiID: text1},
{Type: "blockquote", Offset: 104, Length: 5, URL: "", User: nil, Language: ""},
{Type: "expandable_blockquote", Offset: 109, Length: 5, URL: "", User: nil, Language: ""},
}, entities)

t.Run("non_ascii", func(t *testing.T) {
37 changes: 19 additions & 18 deletions types.go
Original file line number Diff line number Diff line change
@@ -941,24 +941,25 @@ type MessageEntity struct {

// MessageEntity types
const (
EntityTypeMention = "mention"
EntityTypeHashtag = "hashtag"
EntityTypeCashtag = "cashtag"
EntityTypeBotCommand = "bot_command"
EntityTypeURL = "url"
EntityTypeEmail = "email"
EntityTypePhoneNumber = "phone_number"
EntityTypeBold = "bold"
EntityTypeItalic = "italic"
EntityTypeUnderline = "underline"
EntityTypeStrikethrough = "strikethrough"
EntityTypeSpoiler = "spoiler"
EntityTypeBlockquote = "blockquote"
EntityTypeCode = "code"
EntityTypePre = "pre"
EntityTypeTextLink = "text_link"
EntityTypeTextMention = "text_mention"
EntityTypeCustomEmoji = "custom_emoji"
EntityTypeMention = "mention"
EntityTypeHashtag = "hashtag"
EntityTypeCashtag = "cashtag"
EntityTypeBotCommand = "bot_command"
EntityTypeURL = "url"
EntityTypeEmail = "email"
EntityTypePhoneNumber = "phone_number"
EntityTypeBold = "bold"
EntityTypeItalic = "italic"
EntityTypeUnderline = "underline"
EntityTypeStrikethrough = "strikethrough"
EntityTypeSpoiler = "spoiler"
EntityTypeBlockquote = "blockquote"
EntityTypeExpandableBlockquote = "expandable_blockquote"
EntityTypeCode = "code"
EntityTypePre = "pre"
EntityTypeTextLink = "text_link"
EntityTypeTextMention = "text_mention"
EntityTypeCustomEmoji = "custom_emoji"
)

// TextQuote - This object contains information about the quoted part of a message that is replied to by the
4 changes: 2 additions & 2 deletions types_test.go
Original file line number Diff line number Diff line change
@@ -617,8 +617,8 @@ func TestTypesConstants(t *testing.T) {
{
EntityTypeMention, EntityTypeHashtag, EntityTypeCashtag, EntityTypeBotCommand, EntityTypeURL,
EntityTypeEmail, EntityTypePhoneNumber, EntityTypeBold, EntityTypeItalic, EntityTypeUnderline,
EntityTypeStrikethrough, EntityTypeSpoiler, EntityTypeBlockquote, EntityTypeCode, EntityTypePre,
EntityTypeTextLink, EntityTypeTextMention, EntityTypeCustomEmoji,
EntityTypeStrikethrough, EntityTypeSpoiler, EntityTypeBlockquote, EntityTypeExpandableBlockquote,
EntityTypeCode, EntityTypePre, EntityTypeTextLink, EntityTypeTextMention, EntityTypeCustomEmoji,
},
{
OriginTypeUser, OriginTypeHiddenUser, OriginTypeChat, OriginTypeChannel,