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.
60 lines
1.5 KiB
60 lines
1.5 KiB
package main |
|
|
|
import ( |
|
"os" |
|
"os/signal" |
|
"syscall" |
|
"time" |
|
|
|
"app/cmd" |
|
|
|
"github.com/kf5grd/keybasebot" |
|
"samhofi.us/x/keybase/v2" |
|
"samhofi.us/x/keybase/v2/types/chat1" |
|
) |
|
|
|
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) |
|
|
|
// register the bot commands |
|
b.Commands = append(b.Commands, |
|
keybasebot.BotCommand{ |
|
Name: "ping", |
|
Ad: &cmd.PingAd, |
|
Run: keybasebot.Adapt(cmd.SendPong, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!ping")), |
|
}, |
|
keybasebot.BotCommand{ |
|
Name: "age", |
|
Ad: &cmd.AgeAd, |
|
Run: keybasebot.Adapt(cmd.Age, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!age")), |
|
}, |
|
keybasebot.BotCommand{ |
|
Name: "convert", |
|
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) |
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM) |
|
go func() { |
|
<-c |
|
b.Logger.Info("Caught SIGINT, cleaning up.") |
|
b.KB.ClearCommands() |
|
b.Logger.Info("Cleared command adverts. Bye.") |
|
time.Sleep(time.Second * 2) |
|
os.Exit(0) |
|
}() |
|
// then run |
|
b.Run() |
|
}
|
|
|