You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
54 lines
1.2 KiB
package main |
|
|
|
import ( |
|
"fmt" |
|
"os" |
|
|
|
"github.com/kf5grd/keybasebot" |
|
bot "github.com/kf5grd/keybasebot" |
|
"samhofi.us/x/keybase/v2" |
|
"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 *bot.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 |
|
|
|
// 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{ |
|
Name: "Ping", |
|
Ad: &pingAd, |
|
Run: keybasebot.Adapt(sendPong, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!ping")), |
|
}, |
|
) |
|
|
|
// then run |
|
b.Run() |
|
}
|
|
|