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.
93 lines
2.0 KiB
93 lines
2.0 KiB
package main |
|
|
|
import ( |
|
"fmt" |
|
"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) |
|
if opts.RedditUser != "" && opts.RedditPass != "" { |
|
b.Meta["reddit-user"] = opts.RedditUser |
|
b.Meta["reddit-pass"] = opts.RedditPass |
|
} |
|
|
|
// 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") |
|
), |
|
}, |
|
) |
|
// if there are reddit credentials add the reddit commands |
|
if opts.RedditPass != "" && opts.RedditUser != "" { |
|
b.Commands = append(b.Commands, |
|
keybasebot.BotCommand{ |
|
Name: "eyebleach", |
|
Ad: &cmd.EyebleachAd, |
|
Run: keybasebot.Adapt(cmd.Eyebleach, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!eyebleach")), |
|
}, |
|
) |
|
fmt.Printf("%+v\n", opts) |
|
} |
|
|
|
// 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() |
|
}
|
|
|