From e140606ebf708fe76335f2d6aa3c9a41efa33161 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sat, 9 Apr 2022 22:16:15 +0100 Subject: [PATCH] Store the transcript in a file --- pkg/core/core.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pkg/core/core.go b/pkg/core/core.go index 2335793..016be4e 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -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)