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