all repos — paprika @ 1eda21165d7e41e8fcf7a6f86431972b7ab37a75

go rewrite of taigabot

Fix tell recepient, wrap errs
Anirudh Oppiliappan x@icyphox.sh
Tue, 28 Dec 2021 19:48:35 +0530
commit

1eda21165d7e41e8fcf7a6f86431972b7ab37a75

parent

5ca463bc263ef78c7994a29a7ef32b515c013ac1

1 files changed, 14 insertions(+), 10 deletions(-)

jump to
M plugins/tell.goplugins/tell.go

@@ -5,7 +5,6 @@ "bytes"

"crypto/rand" "encoding/gob" "fmt" - "io" "sort" "strings" "time"

@@ -54,8 +53,9 @@ return nil

} // Decodes tell data from encoding/gob into a Tell. -func getTell(data io.Reader) (*Tell, error) { - dec := gob.NewDecoder(data) +func getTell(data []byte) (*Tell, error) { + r := bytes.NewReader(data) + dec := gob.NewDecoder(r) t := Tell{} if err := dec.Decode(&t); err != nil { return nil, err

@@ -100,26 +100,30 @@ for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {

item := it.Item() k := item.Key() err := item.Value(func(v []byte) error { - var r bytes.Reader - tell, err := getTell(&r) + tell, err := getTell(v) if err != nil { - return err + return fmt.Errorf("degobbing: %w", err) } tells = append(tells, *tell) return nil }) if err != nil { - return err + return fmt.Errorf("iterating: %w", err) } err = txn.Delete(k) if err != nil { - return err + return fmt.Errorf("deleting key: %w", err) } } return nil }) if err != nil { - return "", err + return "", fmt.Errorf("fetching tells: %w", err) + } + + // No tells for this user. + if len(tells) == 0 { + return "", NoReply } // Sort tells by time.

@@ -140,6 +144,6 @@ ),

) } - return strings.Join(tellsFmtd, "\n"), &IsPrivateNotice{To: t.To} + return strings.Join(tellsFmtd, "\n"), &IsPrivateNotice{To: tells[0].To} } }