Store the transcript in a file
This commit is contained in:
parent
71a378ea10
commit
e140606ebf
|
@ -18,6 +18,7 @@ package core
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -69,17 +70,11 @@ func (bot *Bot) StartBot() {
|
|||
return
|
||||
}
|
||||
|
||||
// b.Handle(tele.OnText, func(c tele.Context) error {
|
||||
// if !bot.isOwner(c) {
|
||||
// return nil
|
||||
// }
|
||||
// })
|
||||
|
||||
b.Handle(tele.OnVoice, func(c tele.Context) error {
|
||||
if !bot.isOwner(c) {
|
||||
return nil
|
||||
}
|
||||
|
||||
c.Send("...")
|
||||
log.Println("Got a voice!")
|
||||
filepath, err := bot.StoreVoice(c)
|
||||
if err != nil {
|
||||
|
@ -91,17 +86,27 @@ func (bot *Bot) StartBot() {
|
|||
return err
|
||||
}
|
||||
|
||||
s := strings.Join(*text, "**")
|
||||
s := strings.Join(*text, " ")
|
||||
|
||||
err = bot.SaveTranscript(filepath, s)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Send(s)
|
||||
fmt.Println(s)
|
||||
|
||||
return c.Send("Got it!")
|
||||
return nil
|
||||
})
|
||||
|
||||
b.Start()
|
||||
}
|
||||
|
||||
func (bot *Bot) SaveTranscript(filepath *string, text *string) error {
|
||||
return ioutil.WriteFile(*filepath + ".txt", []byte(*text), 0600)
|
||||
}
|
||||
|
||||
func (bot *Bot) isOwner(c tele.Context) bool {
|
||||
me := c.Sender().Username
|
||||
log.Printf("[Info] User '%s' is trying to connect!", me)
|
||||
|
|
Loading…
Reference in New Issue