From 1e471a043589fab943e2cc6f073a1bf066642dc7 Mon Sep 17 00:00:00 2001 From: David Haukeness Date: Fri, 15 Jan 2021 09:15:58 -0700 Subject: [PATCH] new logging, implement price --- main.go | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/main.go b/main.go index 3e2945e..0263d24 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "os" "os/signal" "syscall" @@ -14,35 +13,14 @@ import ( "samhofi.us/x/keybase/v2/types/chat1" ) -// We'll use this to create a writer for the Logger which will be able to write logs to -// stdout, and optionally also to a Keybase chat conversation -type kbWriter struct { - convID chat1.ConvIDStr - bot *keybasebot.Bot -} - -func (k kbWriter) Write(p []byte) (n int, err error) { - opt := keybase.SendMessageOptions{ - ConversationID: k.convID, - Message: keybase.SendMessageBody{Body: string(p)}, - } - go k.bot.KB.SendMessage("send", opt) - fmt.Fprintf(os.Stdout, string(p)) - return len(p), nil -} - func main() { opts := parseArgs(os.Args) b := keybasebot.New("", keybase.SetHomePath(opts.HomePath)) b.Debug = opts.Debug b.JSON = opts.JSON + b.LogWriter = os.Stdout + b.LogConv = chat1.ConvIDStr(opts.LogConvIDStr) - // set up the log writer - w := kbWriter{ - convID: chat1.ConvIDStr(opts.LogConvIDStr), - bot: b, - } - b.LogWriter = w // register the bot commands b.Commands = append(b.Commands, keybasebot.BotCommand{ @@ -60,6 +38,11 @@ func main() { Ad: &cmd.ConvertAd, Run: keybasebot.Adapt(cmd.Convert, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!convert")), }, + keybasebot.BotCommand{ + Name: "price", + Ad: &cmd.PriceAd, + Run: keybasebot.Adapt(cmd.SendPrice, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!price")), + }, ) // catch ctrl-c so we can clean up c := make(chan os.Signal)