Refactoring

bot-api-6.1
Gleb Sinyavsky 2015-11-20 15:15:34 +03:00
parent d8ba9c84c8
commit 54b9c7e14b
2 changed files with 26 additions and 32 deletions

View File

@ -44,6 +44,12 @@ type Chattable struct {
ChannelUsername string ChannelUsername string
} }
type Fileable struct {
FilePath string
File interface{}
FileID string
}
func (chattable *Chattable) Values() (url.Values, error) { func (chattable *Chattable) Values() (url.Values, error) {
v := url.Values{} v := url.Values{}
if chattable.ChannelUsername != "" { if chattable.ChannelUsername != "" {
@ -110,13 +116,11 @@ func (config *ForwardConfig) Values() (url.Values, error) {
// PhotoConfig contains information about a SendPhoto request. // PhotoConfig contains information about a SendPhoto request.
type PhotoConfig struct { type PhotoConfig struct {
Chattable Chattable
Fileable
Caption string Caption string
ReplyToMessageID int ReplyToMessageID int
ReplyMarkup interface{} ReplyMarkup interface{}
UseExistingPhoto bool UseExistingPhoto bool
FilePath string
File interface{}
FileID string
} }
func (config *PhotoConfig) Values() (url.Values, error) { func (config *PhotoConfig) Values() (url.Values, error) {
@ -144,15 +148,13 @@ func (config *PhotoConfig) Values() (url.Values, error) {
// AudioConfig contains information about a SendAudio request. // AudioConfig contains information about a SendAudio request.
type AudioConfig struct { type AudioConfig struct {
Chattable Chattable
Fileable
Duration int Duration int
Performer string Performer string
Title string Title string
ReplyToMessageID int ReplyToMessageID int
ReplyMarkup interface{} ReplyMarkup interface{}
UseExistingAudio bool UseExistingAudio bool
FilePath string
File interface{}
FileID string
} }
func (config *AudioConfig) Values() (url.Values, error) { func (config *AudioConfig) Values() (url.Values, error) {
@ -186,12 +188,10 @@ func (config *AudioConfig) Values() (url.Values, error) {
// DocumentConfig contains information about a SendDocument request. // DocumentConfig contains information about a SendDocument request.
type DocumentConfig struct { type DocumentConfig struct {
Chattable Chattable
Fileable
ReplyToMessageID int ReplyToMessageID int
ReplyMarkup interface{} ReplyMarkup interface{}
UseExistingDocument bool UseExistingDocument bool
FilePath string
File interface{}
FileID string
} }
func (config *DocumentConfig) Values() (url.Values, error) { func (config *DocumentConfig) Values() (url.Values, error) {
@ -216,12 +216,10 @@ func (config *DocumentConfig) Values() (url.Values, error) {
// StickerConfig contains information about a SendSticker request. // StickerConfig contains information about a SendSticker request.
type StickerConfig struct { type StickerConfig struct {
Chattable Chattable
Fileable
ReplyToMessageID int ReplyToMessageID int
ReplyMarkup interface{} ReplyMarkup interface{}
UseExistingSticker bool UseExistingSticker bool
FilePath string
File interface{}
FileID string
} }
func (config *StickerConfig) Values() (url.Values, error) { func (config *StickerConfig) Values() (url.Values, error) {
@ -246,14 +244,12 @@ func (config *StickerConfig) Values() (url.Values, error) {
// VideoConfig contains information about a SendVideo request. // VideoConfig contains information about a SendVideo request.
type VideoConfig struct { type VideoConfig struct {
Chattable Chattable
Fileable
Duration int Duration int
Caption string Caption string
ReplyToMessageID int ReplyToMessageID int
ReplyMarkup interface{} ReplyMarkup interface{}
UseExistingVideo bool UseExistingVideo bool
FilePath string
File interface{}
FileID string
} }
func (config *VideoConfig) Values() (url.Values, error) { func (config *VideoConfig) Values() (url.Values, error) {
@ -284,13 +280,11 @@ func (config *VideoConfig) Values() (url.Values, error) {
// VoiceConfig contains information about a SendVoice request. // VoiceConfig contains information about a SendVoice request.
type VoiceConfig struct { type VoiceConfig struct {
Chattable Chattable
Fileable
Duration int Duration int
ReplyToMessageID int ReplyToMessageID int
ReplyMarkup interface{} ReplyMarkup interface{}
UseExistingVoice bool UseExistingVoice bool
FilePath string
File interface{}
FileID string
} }
func (config *VoiceConfig) Values() (url.Values, error) { func (config *VoiceConfig) Values() (url.Values, error) {

View File

@ -37,8 +37,8 @@ func NewForward(chatID int, fromChatID int, messageID int) ForwardConfig {
func NewPhotoUpload(chatID int, file interface{}) PhotoConfig { func NewPhotoUpload(chatID int, file interface{}) PhotoConfig {
return PhotoConfig{ return PhotoConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{File: file},
UseExistingPhoto: false, UseExistingPhoto: false,
File: file,
} }
} }
@ -49,8 +49,8 @@ func NewPhotoUpload(chatID int, file interface{}) PhotoConfig {
func NewPhotoShare(chatID int, fileID string) PhotoConfig { func NewPhotoShare(chatID int, fileID string) PhotoConfig {
return PhotoConfig{ return PhotoConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{FileID: fileID},
UseExistingPhoto: true, UseExistingPhoto: true,
FileID: fileID,
} }
} }
@ -62,8 +62,8 @@ func NewPhotoShare(chatID int, fileID string) PhotoConfig {
func NewAudioUpload(chatID int, file interface{}) AudioConfig { func NewAudioUpload(chatID int, file interface{}) AudioConfig {
return AudioConfig{ return AudioConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{File: file},
UseExistingAudio: false, UseExistingAudio: false,
File: file,
} }
} }
@ -74,8 +74,8 @@ func NewAudioUpload(chatID int, file interface{}) AudioConfig {
func NewAudioShare(chatID int, fileID string) AudioConfig { func NewAudioShare(chatID int, fileID string) AudioConfig {
return AudioConfig{ return AudioConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{FileID: fileID},
UseExistingAudio: true, UseExistingAudio: true,
FileID: fileID,
} }
} }
@ -87,8 +87,8 @@ func NewAudioShare(chatID int, fileID string) AudioConfig {
func NewDocumentUpload(chatID int, file interface{}) DocumentConfig { func NewDocumentUpload(chatID int, file interface{}) DocumentConfig {
return DocumentConfig{ return DocumentConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{File: file},
UseExistingDocument: false, UseExistingDocument: false,
File: file,
} }
} }
@ -99,8 +99,8 @@ func NewDocumentUpload(chatID int, file interface{}) DocumentConfig {
func NewDocumentShare(chatID int, fileID string) DocumentConfig { func NewDocumentShare(chatID int, fileID string) DocumentConfig {
return DocumentConfig{ return DocumentConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{FileID: fileID},
UseExistingDocument: true, UseExistingDocument: true,
FileID: fileID,
} }
} }
@ -111,8 +111,8 @@ func NewDocumentShare(chatID int, fileID string) DocumentConfig {
func NewStickerUpload(chatID int, file interface{}) StickerConfig { func NewStickerUpload(chatID int, file interface{}) StickerConfig {
return StickerConfig{ return StickerConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{File: file},
UseExistingSticker: false, UseExistingSticker: false,
File: file,
} }
} }
@ -123,8 +123,8 @@ func NewStickerUpload(chatID int, file interface{}) StickerConfig {
func NewStickerShare(chatID int, fileID string) StickerConfig { func NewStickerShare(chatID int, fileID string) StickerConfig {
return StickerConfig{ return StickerConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{FileID: fileID},
UseExistingSticker: true, UseExistingSticker: true,
FileID: fileID,
} }
} }
@ -136,8 +136,8 @@ func NewStickerShare(chatID int, fileID string) StickerConfig {
func NewVideoUpload(chatID int, file interface{}) VideoConfig { func NewVideoUpload(chatID int, file interface{}) VideoConfig {
return VideoConfig{ return VideoConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{File: file},
UseExistingVideo: false, UseExistingVideo: false,
File: file,
} }
} }
@ -149,7 +149,7 @@ func NewVideoShare(chatID int, fileID string) VideoConfig {
return VideoConfig{ return VideoConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
UseExistingVideo: true, UseExistingVideo: true,
FileID: fileID, Fileable: Fileable{FileID: fileID},
} }
} }
@ -161,8 +161,8 @@ func NewVideoShare(chatID int, fileID string) VideoConfig {
func NewVoiceUpload(chatID int, file interface{}) VoiceConfig { func NewVoiceUpload(chatID int, file interface{}) VoiceConfig {
return VoiceConfig{ return VoiceConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{File: file},
UseExistingVoice: false, UseExistingVoice: false,
File: file,
} }
} }
@ -173,8 +173,8 @@ func NewVoiceUpload(chatID int, file interface{}) VoiceConfig {
func NewVoiceShare(chatID int, fileID string) VoiceConfig { func NewVoiceShare(chatID int, fileID string) VoiceConfig {
return VoiceConfig{ return VoiceConfig{
Chattable: Chattable{ChatID: chatID}, Chattable: Chattable{ChatID: chatID},
Fileable: Fileable{FileID: fileID},
UseExistingVoice: true, UseExistingVoice: true,
FileID: fileID,
} }
} }