Skip to content

Commit

Permalink
options.go: remove BaseOptions from 99% of the *Options
Browse files Browse the repository at this point in the history
This implementation wasn't really convenient, so I guess we'll roll this back.
  • Loading branch information
DjMike238 committed Sep 9, 2021
1 parent 080a491 commit 27d6636
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 105 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ _Example: `sendMessage` becomes `SendMessage`_
- In some methods, you might find a `InputFile` type parameter. [`InputFile`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#InputFile) is a struct with unexported fields, since only three combination of fields are valid, which can be obtained through the methods [`NewInputFileID`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewInputFileID), [`NewInputFilePath`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewInputFilePath) and [`NewInputFileBytes`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewInputFileBytes).
- In some methods, you might find a `MessageIDOptions` type parameter. [`MessageIDOptions`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#MessageIDOptions) is another struct with unexported fields, since only two combination of field are valid, which can be obtained through the methods [`NewMessageID`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewMessageID) and [`NewInlineMessageID`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewInlineMessageID).
- Optional parameters can be added by passing the correct struct to each method that might request optional parameters. If you don't want to pass any optional parameter, `nil` is more than enough. Refer to the [docs](https://pkg.go.dev/badge/github.com/NicoNex/echotron/v3) to check for each method's optional parameters struct: it's the type of the `opts` parameter.
- Some of the optional parameters can be found in the [`BaseOptions`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#BaseOptions) struct. That's to keep the implementation as clean as possible, since those are some frequently used parameters in most of the structs.
- Some parameters are hardcoded to avoid putting random stuff which isn't recognized by the Telegram API. Some notable examples are [`ParseMode`](https://github.com/NicoNex/echotron/blob/master/options.go#L21), [`ChatAction`](https://github.com/NicoNex/echotron/blob/master/options.go#L54) and [`InlineQueryType`](https://github.com/NicoNex/echotron/blob/master/inline.go). For a full list of custom hardcoded parameters, refer to the [docs](https://pkg.go.dev/badge/github.com/NicoNex/echotron/v3) for each custom type: by clicking on the type's name, you'll get the source which contains the possible values for that type.

## Usage
Expand Down
48 changes: 15 additions & 33 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ func TestSendMessageReply(t *testing.T) {
"TestSendMessageReply",
chatID,
&MessageOptions{
BaseOptions: BaseOptions{
ReplyToMessageID: msgTmp.ID,
},
ReplyToMessageID: msgTmp.ID,
},
)

Expand All @@ -241,9 +239,7 @@ func TestSendMessageWithKeyboard(t *testing.T) {
"TestSendMessageWithKeyboard",
chatID,
&MessageOptions{
BaseOptions: BaseOptions{
ReplyMarkup: keyboard,
},
ReplyMarkup: keyboard,
},
)

Expand Down Expand Up @@ -323,10 +319,8 @@ func TestSendPhotoWithKeyboard(t *testing.T) {
NewInputFilePath("assets/tests/echotron_test.png"),
chatID,
&PhotoOptions{
Caption: "TestSendPhotoWithKeyboard",
BaseOptions: BaseOptions{
ReplyMarkup: keyboard,
},
Caption: "TestSendPhotoWithKeyboard",
ReplyMarkup: keyboard,
},
)

Expand Down Expand Up @@ -380,10 +374,8 @@ func TestSendAudioWithKeyboard(t *testing.T) {
NewInputFilePath("assets/tests/audio.mp3"),
chatID,
&AudioOptions{
Caption: "TestSendAudioWithKeyboard",
BaseOptions: BaseOptions{
ReplyMarkup: keyboard,
},
Caption: "TestSendAudioWithKeyboard",
ReplyMarkup: keyboard,
},
)

Expand Down Expand Up @@ -461,10 +453,8 @@ func TestSendDocumentWithKeyboard(t *testing.T) {
NewInputFilePath("assets/tests/document.pdf"),
chatID,
&DocumentOptions{
Caption: "TestSendDocumentWithKeyboard",
BaseOptions: BaseOptions{
ReplyMarkup: keyboard,
},
Caption: "TestSendDocumentWithKeyboard",
ReplyMarkup: keyboard,
},
)

Expand Down Expand Up @@ -548,10 +538,8 @@ func TestSendVideoWithKeyboard(t *testing.T) {
NewInputFilePath("assets/tests/video.webm"),
chatID,
&VideoOptions{
Caption: "TestSendVideoWithKeyboard",
BaseOptions: BaseOptions{
ReplyMarkup: keyboard,
},
Caption: "TestSendVideoWithKeyboard",
ReplyMarkup: keyboard,
},
)

Expand Down Expand Up @@ -629,10 +617,8 @@ func TestSendAnimationWithKeyboard(t *testing.T) {
NewInputFilePath("assets/tests/animation.mp4"),
chatID,
&AnimationOptions{
Caption: "TestSendAnimationWithKeyboard",
BaseOptions: BaseOptions{
ReplyMarkup: keyboard,
},
Caption: "TestSendAnimationWithKeyboard",
ReplyMarkup: keyboard,
},
)

Expand Down Expand Up @@ -710,10 +696,8 @@ func TestSendVoiceWithKeyboard(t *testing.T) {
NewInputFilePath("assets/tests/audio.mp3"),
chatID,
&VoiceOptions{
Caption: "TestSendVoiceWithKeyboard",
BaseOptions: BaseOptions{
ReplyMarkup: keyboard,
},
Caption: "TestSendVoiceWithKeyboard",
ReplyMarkup: keyboard,
},
)

Expand Down Expand Up @@ -787,9 +771,7 @@ func TestSendVideoNoteWithKeyboard(t *testing.T) {
NewInputFilePath("assets/tests/video_note.mp4"),
chatID,
&VideoNoteOptions{
BaseOptions: BaseOptions{
ReplyMarkup: keyboard,
},
ReplyMarkup: keyboard,
},
)

Expand Down
181 changes: 110 additions & 71 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,13 @@ type BaseOptions struct {

// MessageOptions contains the optional parameters used by some Telegram API methods.
type MessageOptions struct {
BaseOptions `query:"recursive"`
ParseMode ParseMode `query:"parse_mode"`
Entities []MessageEntity `query:"entities"`
DisableWebPagePreview bool `query:"disable_web_page_preview"`
ParseMode ParseMode `query:"parse_mode"`
Entities []MessageEntity `query:"entities"`
DisableWebPagePreview bool `query:"disable_web_page_preview"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// DisableNotificationOptions contains the optional parameters used by some Telegram API methods.
Expand All @@ -200,10 +203,13 @@ type DisableNotificationOptions struct {

// CopyOptions contains the optional parameters used by the CopyMessage method.
type CopyOptions struct {
BaseOptions `query:"recursive"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// InputFile is a struct which contains data about a file to be sent.
Expand All @@ -230,74 +236,95 @@ func NewInputFileBytes(fileName string, content []byte) InputFile {

// PhotoOptions contains the optional parameters used by the SendPhoto method.
type PhotoOptions struct {
BaseOptions `query:"recursive"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// AudioOptions contains the optional parameters used by the SendAudio method.
type AudioOptions struct {
BaseOptions `query:"recursive"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
Duration int `query:"duration"`
Performer string `query:"performer"`
Title string `query:"title"`
Thumb InputFile `query:"thumb"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
Duration int `query:"duration"`
Performer string `query:"performer"`
Title string `query:"title"`
Thumb InputFile `query:"thumb"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// DocumentOptions contains the optional parameters used by the SendDocument method.
type DocumentOptions struct {
BaseOptions `query:"recursive"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
DisableContentTypeDetection bool `query:"disable_content_type_detection"`
Thumb InputFile `query:"thumb"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// VideoOptions contains the optional parameters used by the SendVideo method.
type VideoOptions struct {
BaseOptions `query:"recursive"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
Duration int `query:"duration"`
Width int `query:"width"`
Height int `query:"height"`
Thumb InputFile `query:"thumb"`
SupportsStreaming bool `query:"supports_streaming"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
Duration int `query:"duration"`
Width int `query:"width"`
Height int `query:"height"`
Thumb InputFile `query:"thumb"`
SupportsStreaming bool `query:"supports_streaming"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// AnimationOptions contains the optional parameters used by the SendAnimation method.
type AnimationOptions struct {
BaseOptions `query:"recursive"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
Duration int `query:"duration"`
Width int `query:"width"`
Height int `query:"height"`
Thumb InputFile `query:"thumb"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
Duration int `query:"duration"`
Width int `query:"width"`
Height int `query:"height"`
Thumb InputFile `query:"thumb"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// VoiceOptions contains the optional parameters used by the SendVoice method.
type VoiceOptions struct {
BaseOptions `query:"recursive"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
Duration int `query:"duration"`
ParseMode ParseMode `query:"parse_mode"`
Caption string `query:"caption"`
CaptionEntities []MessageEntity `query:"caption_entities"`
Duration int `query:"duration"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// VideoNoteOptions contains the optional parameters used by the SendVideoNote method.
type VideoNoteOptions struct {
BaseOptions `query:"recursive"`
Duration int `query:"duration"`
Length int `query:"length"`
Thumb InputFile `query:"thumb"`
Duration int `query:"duration"`
Length int `query:"length"`
Thumb InputFile `query:"thumb"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// MediaGroupOptions contains the optional parameters used by the SendMediaGroup method.
Expand All @@ -309,11 +336,14 @@ type MediaGroupOptions struct {

// LocationOptions contains the optional parameters used by the SendLocation method.
type LocationOptions struct {
BaseOptions `query:"recursive"`
HorizontalAccuracy float64 `query:"horizontal_accuracy"`
LivePeriod int `query:"live_period"`
Heading int `query:"heading"`
ProximityAlertRadius int `query:"proximity_alert_radius"`
HorizontalAccuracy float64 `query:"horizontal_accuracy"`
LivePeriod int `query:"live_period"`
Heading int `query:"heading"`
ProximityAlertRadius int `query:"proximity_alert_radius"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// EditLocationOptions contains the optional parameters used by the EditMessageLiveLocation method.
Expand All @@ -326,33 +356,42 @@ type EditLocationOptions struct {

// VenueOptions contains the optional parameters used by the SendVenue method.
type VenueOptions struct {
BaseOptions `query:"recursive"`
FoursquareID string `query:"foursquare_id"`
FoursquareType string `query:"foursquare_type"`
GooglePlaceID string `query:"google_place_id"`
GooglePlaceType string `query:"google_place_type"`
FoursquareID string `query:"foursquare_id"`
FoursquareType string `query:"foursquare_type"`
GooglePlaceID string `query:"google_place_id"`
GooglePlaceType string `query:"google_place_type"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// ContactOptions contains the optional parameters used by the SendContact method.
type ContactOptions struct {
BaseOptions `query:"recursive"`
LastName string `query:"last_name"`
VCard string `query:"vcard"`
LastName string `query:"last_name"`
VCard string `query:"vcard"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// PollOptions contains the optional parameters used by the SendPoll method.
type PollOptions struct {
BaseOptions `query:"recursive"`
IsAnonymous bool `query:"is_anonymous"`
Type PollType `query:"type"`
AllowsMultipleAnswers bool `query:"allows_multiple_answers"`
CorrectOptionID int `query:"correct_option_id"`
Explanation string `query:"explanation"`
ExplanationParseMode ParseMode `query:"explanation_parse_mode"`
ExplanationEntities []MessageEntity `query:"explanation_entities"`
OpenPeriod int `query:"open_period"`
CloseDate int `query:"close_date"`
IsClosed bool `query:"is_closed"`
IsAnonymous bool `query:"is_anonymous"`
Type PollType `query:"type"`
AllowsMultipleAnswers bool `query:"allows_multiple_answers"`
CorrectOptionID int `query:"correct_option_id"`
Explanation string `query:"explanation"`
ExplanationParseMode ParseMode `query:"explanation_parse_mode"`
ExplanationEntities []MessageEntity `query:"explanation_entities"`
OpenPeriod int `query:"open_period"`
CloseDate int `query:"close_date"`
IsClosed bool `query:"is_closed"`
DisableNotification bool `query:"disable_notification"`
ReplyToMessageID int `query:"reply_to_message_id"`
AllowSendingWithoutReply bool `query:"allow_sending_without_reply"`
ReplyMarkup ReplyMarkup `query:"reply_markup"`
}

// BanOptions contains the optional parameters used by the BanChatMember method.
Expand Down

0 comments on commit 27d6636

Please sign in to comment.