handleUploadFile handles native upload of files
(msg *config.Message, chatid int64, parentID int)
| 444 | |
| 445 | // handleUploadFile handles native upload of files |
| 446 | func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64, parentID int) (string, error) { |
| 447 | var media []interface{} |
| 448 | for _, f := range msg.Extra["file"] { |
| 449 | fi := f.(config.FileInfo) |
| 450 | file := tgbotapi.FileBytes{ |
| 451 | Name: fi.Name, |
| 452 | Bytes: *fi.Data, |
| 453 | } |
| 454 | |
| 455 | if b.GetString("MessageFormat") == HTMLFormat { |
| 456 | fi.Comment = makeHTML(html.EscapeString(fi.Comment)) |
| 457 | } |
| 458 | |
| 459 | switch filepath.Ext(fi.Name) { |
| 460 | case ".jpg", ".jpe", ".png": |
| 461 | pc := tgbotapi.NewInputMediaPhoto(file) |
| 462 | if fi.Comment != "" { |
| 463 | pc.Caption, pc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) |
| 464 | } |
| 465 | media = append(media, pc) |
| 466 | case ".mp4", ".m4v": |
| 467 | vc := tgbotapi.NewInputMediaVideo(file) |
| 468 | if fi.Comment != "" { |
| 469 | vc.Caption, vc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) |
| 470 | } |
| 471 | media = append(media, vc) |
| 472 | case ".mp3", ".oga": |
| 473 | ac := tgbotapi.NewInputMediaAudio(file) |
| 474 | if fi.Comment != "" { |
| 475 | ac.Caption, ac.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) |
| 476 | } |
| 477 | media = append(media, ac) |
| 478 | case ".ogg": |
| 479 | voc := tgbotapi.NewVoice(chatid, file) |
| 480 | voc.Caption, voc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) |
| 481 | voc.ReplyToMessageID = parentID |
| 482 | res, err := b.c.Send(voc) |
| 483 | if err != nil { |
| 484 | return "", err |
| 485 | } |
| 486 | return strconv.Itoa(res.MessageID), nil |
| 487 | default: |
| 488 | dc := tgbotapi.NewInputMediaDocument(file) |
| 489 | if fi.Comment != "" { |
| 490 | dc.Caption, dc.ParseMode = TGGetParseMode(b, msg.Username, fi.Comment) |
| 491 | } |
| 492 | media = append(media, dc) |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | return b.sendMediaFiles(msg, chatid, parentID, media) |
| 497 | } |
| 498 | |
| 499 | func (b *Btelegram) handleQuote(message, quoteNick, quoteMessage string) string { |
| 500 | format := b.GetString("quoteformat") |
no test coverage detected