From 04fed8f8b183eb19221e5e3228b286b9109f6346 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Mon, 30 Oct 2023 10:47:42 +0300 Subject: [PATCH] fix: refactor after schema update --- examples/go.mod | 4 ++-- examples/go.sum | 2 ++ telegram/message/builder.go | 8 +++++--- telegram/message/builder_test.go | 2 +- telegram/message/draft.go | 10 +++++----- telegram/message/inline.go | 2 +- telegram/message/media.go | 4 ++-- telegram/message/text.go | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index 466c117966..2ff626509d 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -31,7 +31,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/gotd/ige v0.2.2 // indirect github.com/gotd/neo v0.1.5 // indirect - github.com/klauspost/compress v1.17.0 // indirect + github.com/klauspost/compress v1.17.2 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -44,7 +44,7 @@ require ( golang.org/x/exp v0.0.0-20230116083435-1de6713980de // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.13.0 // indirect - nhooyr.io/websocket v1.8.7 // indirect + nhooyr.io/websocket v1.8.10 // indirect rsc.io/qr v0.2.0 // indirect ) diff --git a/examples/go.sum b/examples/go.sum index fd4de8e29f..41fa1b76fe 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -164,6 +164,7 @@ github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYs github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -404,5 +405,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= +nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY= rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs= diff --git a/telegram/message/builder.go b/telegram/message/builder.go index 783e69a19a..edff4a7f81 100644 --- a/telegram/message/builder.go +++ b/telegram/message/builder.go @@ -33,8 +33,8 @@ type Builder struct { // noForwards whether that sent message cannot be forwarded. noForwards bool - // The message ID to which this message will reply to. - replyToMsgID int + // The reply target. + replyTo tg.InputReplyToClass // Reply markup for sending bot buttons. replyMarkup tg.ReplyMarkupClass // Scheduled message date for scheduled messages. @@ -73,7 +73,9 @@ func (b *Builder) Clear() *Builder { // Reply sets message ID to reply. func (b *Builder) Reply(id int) *Builder { - b.replyToMsgID = id + b.replyTo = &tg.InputReplyToMessage{ + ReplyToMsgID: id, + } return b } diff --git a/telegram/message/builder_test.go b/telegram/message/builder_test.go index 73a78dc49c..07f1cc0e6c 100644 --- a/telegram/message/builder_test.go +++ b/telegram/message/builder_test.go @@ -26,7 +26,7 @@ func TestBuilder(t *testing.T) { a.True(b.noWebpage) b = b.ReplyMsg(&tg.Message{ID: 10}) - a.Equal(10, b.replyToMsgID) + a.Equal(10, b.replyTo.(*tg.InputReplyToMessage).ReplyToMsgID) date := time.Now() b = b.Schedule(date) diff --git a/telegram/message/draft.go b/telegram/message/draft.go index 8d25f4dcbc..d493899442 100644 --- a/telegram/message/draft.go +++ b/telegram/message/draft.go @@ -16,11 +16,11 @@ func (b *Builder) saveDraftRequest( entities []tg.MessageEntityClass, ) *tg.MessagesSaveDraftRequest { return &tg.MessagesSaveDraftRequest{ - NoWebpage: b.noWebpage, - Peer: peer, - ReplyToMsgID: b.replyToMsgID, - Message: msg, - Entities: entities, + NoWebpage: b.noWebpage, + Peer: peer, + ReplyTo: b.replyTo, + Message: msg, + Entities: entities, } } diff --git a/telegram/message/inline.go b/telegram/message/inline.go index 8cc6b4b482..b0448b809f 100644 --- a/telegram/message/inline.go +++ b/telegram/message/inline.go @@ -22,7 +22,7 @@ func (b *Builder) InlineResult(ctx context.Context, id string, queryID int64, hi ClearDraft: b.clearDraft, HideVia: hideVia, Peer: p, - ReplyTo: &tg.InputReplyToMessage{ReplyToMsgID: b.replyToMsgID}, + ReplyTo: b.replyTo, QueryID: queryID, ID: id, ScheduleDate: b.scheduleDate, diff --git a/telegram/message/media.go b/telegram/message/media.go index f47a71b5d5..a7243ded80 100644 --- a/telegram/message/media.go +++ b/telegram/message/media.go @@ -58,7 +58,7 @@ func (b *Builder) Album(ctx context.Context, media MultiMediaOption, album ...Mu Background: b.background, ClearDraft: b.clearDraft, Peer: p, - ReplyTo: &tg.InputReplyToMessage{ReplyToMsgID: b.replyToMsgID}, + ReplyTo: b.replyTo, MultiMedia: mb, ScheduleDate: b.scheduleDate, }) @@ -112,7 +112,7 @@ func (b *Builder) Media(ctx context.Context, media MediaOption) (tg.UpdatesClass Background: b.background, ClearDraft: b.clearDraft, Peer: p, - ReplyTo: &tg.InputReplyToMessage{ReplyToMsgID: b.replyToMsgID}, + ReplyTo: b.replyTo, Media: attachment.Media, Message: attachment.Message, ReplyMarkup: b.replyMarkup, diff --git a/telegram/message/text.go b/telegram/message/text.go index 7f8f9ca0bb..3f8b105626 100644 --- a/telegram/message/text.go +++ b/telegram/message/text.go @@ -22,7 +22,7 @@ func (b *Builder) sendRequest( ClearDraft: b.clearDraft, Noforwards: b.noForwards, Peer: p, - ReplyTo: &tg.InputReplyToMessage{ReplyToMsgID: b.replyToMsgID}, + ReplyTo: b.replyTo, Message: msg, RandomID: 0, ReplyMarkup: b.replyMarkup,