all repos — telegram-bot-api @ 54b9c7e14b7d8b48ceae32f94d2cce514a02c525

Golang bindings for the Telegram Bot API

Refactoring
Gleb Sinyavsky zhulik.gleb@gmail.com
Fri, 20 Nov 2015 15:15:34 +0300
commit

54b9c7e14b7d8b48ceae32f94d2cce514a02c525

parent

d8ba9c84c817ae4f7eccb12c98fc764cf8c966f8

2 files changed, 26 insertions(+), 32 deletions(-)

jump to
M configs.goconfigs.go

@@ -44,6 +44,12 @@ ChatID int

ChannelUsername string } +type Fileable struct { + FilePath string + File interface{} + FileID string +} + func (chattable *Chattable) Values() (url.Values, error) { v := url.Values{} if chattable.ChannelUsername != "" {

@@ -110,13 +116,11 @@

// PhotoConfig contains information about a SendPhoto request. type PhotoConfig struct { Chattable + Fileable Caption string ReplyToMessageID int ReplyMarkup interface{} UseExistingPhoto bool - FilePath string - File interface{} - FileID string } func (config *PhotoConfig) Values() (url.Values, error) {

@@ -144,15 +148,13 @@

// AudioConfig contains information about a SendAudio request. type AudioConfig struct { Chattable + Fileable Duration int Performer string Title string ReplyToMessageID int ReplyMarkup interface{} UseExistingAudio bool - FilePath string - File interface{} - FileID string } func (config *AudioConfig) Values() (url.Values, error) {

@@ -186,12 +188,10 @@

// DocumentConfig contains information about a SendDocument request. type DocumentConfig struct { Chattable + Fileable ReplyToMessageID int ReplyMarkup interface{} UseExistingDocument bool - FilePath string - File interface{} - FileID string } func (config *DocumentConfig) Values() (url.Values, error) {

@@ -216,12 +216,10 @@

// StickerConfig contains information about a SendSticker request. type StickerConfig struct { Chattable + Fileable ReplyToMessageID int ReplyMarkup interface{} UseExistingSticker bool - FilePath string - File interface{} - FileID string } func (config *StickerConfig) Values() (url.Values, error) {

@@ -246,14 +244,12 @@

// VideoConfig contains information about a SendVideo request. type VideoConfig struct { Chattable + Fileable Duration int Caption string ReplyToMessageID int ReplyMarkup interface{} UseExistingVideo bool - FilePath string - File interface{} - FileID string } func (config *VideoConfig) Values() (url.Values, error) {

@@ -284,13 +280,11 @@

// VoiceConfig contains information about a SendVoice request. type VoiceConfig struct { Chattable + Fileable Duration int ReplyToMessageID int ReplyMarkup interface{} UseExistingVoice bool - FilePath string - File interface{} - FileID string } func (config *VoiceConfig) Values() (url.Values, error) {
M helpers.gohelpers.go

@@ -37,8 +37,8 @@ // chatID is where to send it, file is a string path to the file, or FileReader or FileBytes.

func NewPhotoUpload(chatID int, file interface{}) PhotoConfig { return PhotoConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingPhoto: false, - File: file, } }

@@ -49,8 +49,8 @@ // chatID is where to send it, fileID is the ID of the file already uploaded.

func NewPhotoShare(chatID int, fileID string) PhotoConfig { return PhotoConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingPhoto: true, - FileID: fileID, } }

@@ -62,8 +62,8 @@ // chatID is where to send it, file is a string path to the file, or FileReader or FileBytes.

func NewAudioUpload(chatID int, file interface{}) AudioConfig { return AudioConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingAudio: false, - File: file, } }

@@ -73,9 +73,9 @@ //

// chatID is where to send it, fileID is the ID of the audio already uploaded. func NewAudioShare(chatID int, fileID string) AudioConfig { return AudioConfig{ - Chattable: Chattable{ChatID: chatID}, + Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingAudio: true, - FileID: fileID, } }

@@ -87,8 +87,8 @@ // chatID is where to send it, file is a string path to the file, or FileReader or FileBytes.

func NewDocumentUpload(chatID int, file interface{}) DocumentConfig { return DocumentConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingDocument: false, - File: file, } }

@@ -99,8 +99,8 @@ // chatID is where to send it, fileID is the ID of the document already uploaded.

func NewDocumentShare(chatID int, fileID string) DocumentConfig { return DocumentConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingDocument: true, - FileID: fileID, } }

@@ -111,8 +111,8 @@ // chatID is where to send it, file is a string path to the file, or FileReader or FileBytes.

func NewStickerUpload(chatID int, file interface{}) StickerConfig { return StickerConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingSticker: false, - File: file, } }

@@ -122,9 +122,9 @@ //

// chatID is where to send it, fileID is the ID of the sticker already uploaded. func NewStickerShare(chatID int, fileID string) StickerConfig { return StickerConfig{ - Chattable: Chattable{ChatID: chatID}, + Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingSticker: true, - FileID: fileID, } }

@@ -136,8 +136,8 @@ // chatID is where to send it, file is a string path to the file, or FileReader or FileBytes.

func NewVideoUpload(chatID int, file interface{}) VideoConfig { return VideoConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingVideo: false, - File: file, } }

@@ -149,7 +149,7 @@ func NewVideoShare(chatID int, fileID string) VideoConfig {

return VideoConfig{ Chattable: Chattable{ChatID: chatID}, UseExistingVideo: true, - FileID: fileID, + Fileable: Fileable{FileID: fileID}, } }

@@ -161,8 +161,8 @@ // chatID is where to send it, file is a string path to the file, or FileReader or FileBytes.

func NewVoiceUpload(chatID int, file interface{}) VoiceConfig { return VoiceConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingVoice: false, - File: file, } }

@@ -173,8 +173,8 @@ // chatID is where to send it, fileID is the ID of the video already uploaded.

func NewVoiceShare(chatID int, fileID string) VoiceConfig { return VoiceConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingVoice: true, - FileID: fileID, } }