Skip to content

Commit 4037dbe

Browse files
committed
Lint issues fixed
1 parent d638757 commit 4037dbe

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

bot.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse,
8181
return apiResp, nil
8282
}
8383

84-
func (bot *BotAPI) MakeMessageRequest(endpoint string, params url.Values) (Message, error) {
84+
func (bot *BotAPI) makeMessageRequest(endpoint string, params url.Values) (Message, error) {
8585
resp, err := bot.MakeRequest(endpoint, params)
8686
if err != nil {
8787
return Message{}, err
@@ -169,14 +169,17 @@ func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldna
169169
return apiResp, nil
170170
}
171171

172-
func (this *BotAPI) GetFileDirectUrl(fileID string) (string, error) {
173-
file, err := this.GetFile(FileConfig{fileID})
172+
// GetFileDirectURL returns direct URL to file
173+
//
174+
// Requires fileID
175+
func (bot *BotAPI) GetFileDirectURL(fileID string) (string, error) {
176+
file, err := bot.GetFile(FileConfig{fileID})
174177

175178
if err != nil {
176179
return "", err
177180
}
178181

179-
return file.Link(this.Token), nil
182+
return file.Link(bot.Token), nil
180183
}
181184

182185
// GetMe fetches the currently authenticated bot.
@@ -198,10 +201,16 @@ func (bot *BotAPI) GetMe() (User, error) {
198201
return user, nil
199202
}
200203

204+
// IsMessageToMe returns true if message directed to this bot
205+
//
206+
// Requires message
201207
func (bot *BotAPI) IsMessageToMe(message Message) bool {
202208
return strings.Contains(message.Text, "@"+bot.Self.UserName)
203209
}
204210

211+
// Send will send event(Message, Photo, Audio, ChatAction, anything) to Telegram
212+
//
213+
// Requires Chattable
205214
func (bot *BotAPI) Send(c Chattable) (Message, error) {
206215
switch c.(type) {
207216
case Fileable:
@@ -225,7 +234,7 @@ func (bot *BotAPI) sendExisting(method string, config Fileable) (Message, error)
225234
return Message{}, err
226235
}
227236

228-
message, err := bot.MakeMessageRequest(method, v)
237+
message, err := bot.makeMessageRequest(method, v)
229238
if err != nil {
230239
return Message{}, err
231240
}
@@ -270,7 +279,7 @@ func (bot *BotAPI) sendChattable(config Chattable) (Message, error) {
270279
return Message{}, err
271280
}
272281

273-
message, err := bot.MakeMessageRequest(config.Method(), v)
282+
message, err := bot.makeMessageRequest(config.Method(), v)
274283

275284
if err != nil {
276285
return Message{}, err
@@ -359,6 +368,9 @@ func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) {
359368
return updates, nil
360369
}
361370

371+
// RemoveWebhook removes webhook
372+
//
373+
// There are no parameters for this method.
362374
func (bot *BotAPI) RemoveWebhook() (APIResponse, error) {
363375
return bot.MakeRequest("setWebhook", url.Values{})
364376
}
@@ -393,7 +405,9 @@ func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
393405
return apiResp, nil
394406
}
395407

396-
// UpdatesChan starts a channel for getting updates.
408+
// GetUpdatesChan starts and returns a channel for getting updates.
409+
//
410+
// Requires UpdateConfig
397411
func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (<-chan Update, error) {
398412
updatesChan := make(chan Update, 100)
399413

configs.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ const (
3838
ModeMarkdown = "Markdown"
3939
)
4040

41+
//Chattable represents any event in chat(MessageConfig, PhotoConfig, ChatActionConfig and others)
4142
type Chattable interface {
4243
Values() (url.Values, error)
4344
Method() string
4445
}
4546

47+
//Fileable represents any file event(PhotoConfig, DocumentConfig, AudioConfig, VoiceConfig, VideoConfig, StickerConfig)
4648
type Fileable interface {
4749
Chattable
4850
Params() (map[string]string, error)
@@ -51,14 +53,15 @@ type Fileable interface {
5153
UseExistingFile() bool
5254
}
5355

54-
// Base struct for all chat event(Message, Photo and so on)
56+
// BaseChat is base struct for all chat event(Message, Photo and so on)
5557
type BaseChat struct {
5658
ChatID int
5759
ChannelUsername string
5860
ReplyToMessageID int
5961
ReplyMarkup interface{}
6062
}
6163

64+
// Values returns url.Values representation of BaseChat
6265
func (chat *BaseChat) Values() (url.Values, error) {
6366
v := url.Values{}
6467
if chat.ChannelUsername != "" {
@@ -83,6 +86,7 @@ func (chat *BaseChat) Values() (url.Values, error) {
8386
return v, nil
8487
}
8588

89+
// BaseFile is base struct for all file events(PhotoConfig, DocumentConfig, AudioConfig, VoiceConfig, VideoConfig, StickerConfig)
8690
type BaseFile struct {
8791
BaseChat
8892
FilePath string
@@ -91,6 +95,7 @@ type BaseFile struct {
9195
UseExisting bool
9296
}
9397

98+
// Params returns map[string]string representation of BaseFile
9499
func (file BaseFile) Params() (map[string]string, error) {
95100
params := make(map[string]string)
96101

@@ -116,6 +121,7 @@ func (file BaseFile) Params() (map[string]string, error) {
116121
return params, nil
117122
}
118123

124+
// GetFile returns abstract representation of File inside BaseFile
119125
func (file BaseFile) GetFile() interface{} {
120126
var result interface{}
121127
if file.FilePath == "" {
@@ -127,6 +133,7 @@ func (file BaseFile) GetFile() interface{} {
127133
return result
128134
}
129135

136+
// UseExistingFile returns true if BaseFile contains already uploaded file by FileID
130137
func (file BaseFile) UseExistingFile() bool {
131138
return file.UseExisting
132139
}
@@ -140,6 +147,7 @@ type MessageConfig struct {
140147
ReplyMarkup interface{}
141148
}
142149

150+
// Values returns url.Values representation of MessageConfig
143151
func (config MessageConfig) Values() (url.Values, error) {
144152
v, _ := config.BaseChat.Values()
145153
v.Add("text", config.Text)
@@ -151,6 +159,7 @@ func (config MessageConfig) Values() (url.Values, error) {
151159
return v, nil
152160
}
153161

162+
// Method returns Telegram API method name for sending Message
154163
func (config MessageConfig) Method() string {
155164
return "SendMessage"
156165
}
@@ -163,13 +172,15 @@ type ForwardConfig struct {
163172
MessageID int
164173
}
165174

175+
// Values returns url.Values representation of ForwardConfig
166176
func (config ForwardConfig) Values() (url.Values, error) {
167177
v, _ := config.BaseChat.Values()
168178
v.Add("from_chat_id", strconv.Itoa(config.FromChatID))
169179
v.Add("message_id", strconv.Itoa(config.MessageID))
170180
return v, nil
171181
}
172182

183+
// Method returns Telegram API method name for sending Forward
173184
func (config ForwardConfig) Method() string {
174185
return "forwardMessage"
175186
}
@@ -180,6 +191,7 @@ type PhotoConfig struct {
180191
Caption string
181192
}
182193

194+
// Params returns map[string]string representation of PhotoConfig
183195
func (config PhotoConfig) Params() (map[string]string, error) {
184196
params, _ := config.BaseFile.Params()
185197

@@ -190,6 +202,7 @@ func (config PhotoConfig) Params() (map[string]string, error) {
190202
return params, nil
191203
}
192204

205+
// Values returns url.Values representation of PhotoConfig
193206
func (config PhotoConfig) Values() (url.Values, error) {
194207
v, _ := config.BaseChat.Values()
195208

@@ -200,10 +213,12 @@ func (config PhotoConfig) Values() (url.Values, error) {
200213
return v, nil
201214
}
202215

216+
// Name return field name for uploading file
203217
func (config PhotoConfig) Name() string {
204218
return "photo"
205219
}
206220

221+
// Method returns Telegram API method name for sending Photo
207222
func (config PhotoConfig) Method() string {
208223
return "SendPhoto"
209224
}
@@ -216,6 +231,7 @@ type AudioConfig struct {
216231
Title string
217232
}
218233

234+
// Values returns url.Values representation of AudioConfig
219235
func (config AudioConfig) Values() (url.Values, error) {
220236
v, _ := config.BaseChat.Values()
221237

@@ -234,6 +250,7 @@ func (config AudioConfig) Values() (url.Values, error) {
234250
return v, nil
235251
}
236252

253+
// Params returns map[string]string representation of AudioConfig
237254
func (config AudioConfig) Params() (map[string]string, error) {
238255
params, _ := config.BaseFile.Params()
239256

@@ -251,10 +268,12 @@ func (config AudioConfig) Params() (map[string]string, error) {
251268
return params, nil
252269
}
253270

271+
// Name return field name for uploading file
254272
func (config AudioConfig) Name() string {
255273
return "audio"
256274
}
257275

276+
// Method returns Telegram API method name for sending Audio
258277
func (config AudioConfig) Method() string {
259278
return "SendAudio"
260279
}
@@ -264,6 +283,7 @@ type DocumentConfig struct {
264283
BaseFile
265284
}
266285

286+
// Values returns url.Values representation of DocumentConfig
267287
func (config DocumentConfig) Values() (url.Values, error) {
268288
v, _ := config.BaseChat.Values()
269289

@@ -272,16 +292,19 @@ func (config DocumentConfig) Values() (url.Values, error) {
272292
return v, nil
273293
}
274294

295+
// Params returns map[string]string representation of DocumentConfig
275296
func (config DocumentConfig) Params() (map[string]string, error) {
276297
params, _ := config.BaseFile.Params()
277298

278299
return params, nil
279300
}
280301

302+
// Name return field name for uploading file
281303
func (config DocumentConfig) Name() string {
282304
return "document"
283305
}
284306

307+
// Method returns Telegram API method name for sending Document
285308
func (config DocumentConfig) Method() string {
286309
return "sendDocument"
287310
}
@@ -291,6 +314,7 @@ type StickerConfig struct {
291314
BaseFile
292315
}
293316

317+
// Values returns url.Values representation of StickerConfig
294318
func (config StickerConfig) Values() (url.Values, error) {
295319
v, _ := config.BaseChat.Values()
296320

@@ -299,16 +323,19 @@ func (config StickerConfig) Values() (url.Values, error) {
299323
return v, nil
300324
}
301325

326+
// Params returns map[string]string representation of StickerConfig
302327
func (config StickerConfig) Params() (map[string]string, error) {
303328
params, _ := config.BaseFile.Params()
304329

305330
return params, nil
306331
}
307332

333+
// Name return field name for uploading file
308334
func (config StickerConfig) Name() string {
309335
return "sticker"
310336
}
311337

338+
// Method returns Telegram API method name for sending Sticker
312339
func (config StickerConfig) Method() string {
313340
return "sendSticker"
314341
}
@@ -320,6 +347,7 @@ type VideoConfig struct {
320347
Caption string
321348
}
322349

350+
// Values returns url.Values representation of VideoConfig
323351
func (config VideoConfig) Values() (url.Values, error) {
324352
v, _ := config.BaseChat.Values()
325353

@@ -334,16 +362,19 @@ func (config VideoConfig) Values() (url.Values, error) {
334362
return v, nil
335363
}
336364

365+
// Params returns map[string]string representation of VideoConfig
337366
func (config VideoConfig) Params() (map[string]string, error) {
338367
params, _ := config.BaseFile.Params()
339368

340369
return params, nil
341370
}
342371

372+
// Name return field name for uploading file
343373
func (config VideoConfig) Name() string {
344374
return "video"
345375
}
346376

377+
// Method returns Telegram API method name for sending Video
347378
func (config VideoConfig) Method() string {
348379
return "sendVideo"
349380
}
@@ -354,6 +385,7 @@ type VoiceConfig struct {
354385
Duration int
355386
}
356387

388+
// Values returns url.Values representation of VoiceConfig
357389
func (config VoiceConfig) Values() (url.Values, error) {
358390
v, _ := config.BaseChat.Values()
359391

@@ -365,6 +397,7 @@ func (config VoiceConfig) Values() (url.Values, error) {
365397
return v, nil
366398
}
367399

400+
// Params returns map[string]string representation of VoiceConfig
368401
func (config VoiceConfig) Params() (map[string]string, error) {
369402
params, _ := config.BaseFile.Params()
370403

@@ -375,10 +408,12 @@ func (config VoiceConfig) Params() (map[string]string, error) {
375408
return params, nil
376409
}
377410

411+
// Name return field name for uploading file
378412
func (config VoiceConfig) Name() string {
379413
return "voice"
380414
}
381415

416+
// Method returns Telegram API method name for sending Voice
382417
func (config VoiceConfig) Method() string {
383418
return "sendVoice"
384419
}
@@ -390,6 +425,7 @@ type LocationConfig struct {
390425
Longitude float64
391426
}
392427

428+
// Values returns url.Values representation of LocationConfig
393429
func (config LocationConfig) Values() (url.Values, error) {
394430
v, _ := config.BaseChat.Values()
395431

@@ -399,6 +435,7 @@ func (config LocationConfig) Values() (url.Values, error) {
399435
return v, nil
400436
}
401437

438+
// Method returns Telegram API method name for sending Location
402439
func (config LocationConfig) Method() string {
403440
return "sendLocation"
404441
}
@@ -409,12 +446,14 @@ type ChatActionConfig struct {
409446
Action string
410447
}
411448

449+
// Values returns url.Values representation of ChatActionConfig
412450
func (config ChatActionConfig) Values() (url.Values, error) {
413451
v, _ := config.BaseChat.Values()
414452
v.Add("action", config.Action)
415453
return v, nil
416454
}
417455

456+
// Method returns Telegram API method name for sending ChatAction
418457
func (config ChatActionConfig) Method() string {
419458
return "sendChatAction"
420459
}

types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ func (m *Message) IsGroup() bool {
113113
return m.From.ID != m.Chat.ID
114114
}
115115

116+
// IsCommand returns true if message starts from /
116117
func (m *Message) IsCommand() bool {
117118
return m.Text != "" && m.Text[0] == '/'
118119
}
119120

121+
// Command returns first word from message
120122
func (m *Message) Command() string {
121123
return strings.Split(m.Text, " ")[0]
122124
}

0 commit comments

Comments
 (0)