|
|
@ -1,7 +1,6 @@ |
|
|
|
package main |
|
|
|
package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/signal" |
|
|
|
"os/signal" |
|
|
|
"syscall" |
|
|
|
"syscall" |
|
|
@ -14,35 +13,14 @@ import ( |
|
|
|
"samhofi.us/x/keybase/v2/types/chat1" |
|
|
|
"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() { |
|
|
|
func main() { |
|
|
|
opts := parseArgs(os.Args) |
|
|
|
opts := parseArgs(os.Args) |
|
|
|
b := keybasebot.New("", keybase.SetHomePath(opts.HomePath)) |
|
|
|
b := keybasebot.New("", keybase.SetHomePath(opts.HomePath)) |
|
|
|
b.Debug = opts.Debug |
|
|
|
b.Debug = opts.Debug |
|
|
|
b.JSON = opts.JSON |
|
|
|
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
|
|
|
|
// register the bot commands
|
|
|
|
b.Commands = append(b.Commands, |
|
|
|
b.Commands = append(b.Commands, |
|
|
|
keybasebot.BotCommand{ |
|
|
|
keybasebot.BotCommand{ |
|
|
@ -60,6 +38,11 @@ func main() { |
|
|
|
Ad: &cmd.ConvertAd, |
|
|
|
Ad: &cmd.ConvertAd, |
|
|
|
Run: keybasebot.Adapt(cmd.Convert, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!convert")), |
|
|
|
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
|
|
|
|
// catch ctrl-c so we can clean up
|
|
|
|
c := make(chan os.Signal) |
|
|
|
c := make(chan os.Signal) |
|
|
|