kunt

golang IRC bot
git clone git://git.2f30.org/kunt.git
Log | Files | Refs | LICENSE

commit bdfd4fdcfac81d7cb61082a00cc58d84525443c9
parent 2366a5f3147478da15c5532c47e164463b18e0f2
Author: dsp <dsp@2f30.org>
Date:   Wed Apr 30 16:22:37 +0100

implementiation of the new configFile flag -c to load the configuration from a JSON encoded file

Diffstat:
src/kunt/kunt.go | 41+++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/src/kunt/kunt.go b/src/kunt/kunt.go @@ -412,7 +412,6 @@ func updateUrlDbTitles(path string) { log.Printf("*** urlDb update finished ***\n") } -var sslon = flag.Bool("s", false, "SSL support") var quoteDb *mapfs.Mapfs var urlDb *mapfs.Mapfs @@ -421,6 +420,13 @@ var geng games.GameEnger var botname string var ytregex *regexp.Regexp var titleregex *regexp.Regexp +var configfile string +var sslon = flag.Bool("s", false, "SSL support") +var cfg *irc.Config + +func init() { + flag.StringVar(&configfile,"c","","JSON configuration file") +} func main() { kunt.stime = time.Now() @@ -429,13 +435,12 @@ func main() { log.SetPrefix("kunt: ") flag.Parse() - if flag.NArg() < 1 { - fmt.Fprintf(os.Stderr, "usage: %s [-s] host:port\n", + if flag.NArg() < 1 && configfile == "" { + fmt.Fprintf(os.Stderr, "usage: %s [-s] [-c configfile] host:port\n", os.Args[0]) os.Exit(2) } - hostport := strings.Split(flag.Arg(0), ":") quotePlain := mapfs.NewPlainMap() quoteDb = mapfs.NewMapfs(quotePlain, "Quotes", "db/quotes", "quote") @@ -498,18 +503,26 @@ func main() { "!game": cmdGame, "!copyright": cmdCopyright, } - - cfg := irc.Config{ - NetworkName: "freenode", - Nick: botname, - User: "z0mg", - RealName: botname, - Serv: hostport[0], - Port: hostport[1], - Ssl: *sslon, + if configfile == "" { + hostport := strings.Split(flag.Arg(0), ":") + + cfg = &irc.Config{ + NetworkName: "freenode", + Nick: botname, + User: "z0mg", + RealName: botname, + Serv: hostport[0], + Port: hostport[1], + Ssl: *sslon, + } + } else { + cfg,err = irc.LoadConfig(configfile) + if err != nil { + log.Fatal(err) + } } - kunt.ircCtx = irc.NewIrcContext(cfg) + kunt.ircCtx = irc.NewIrcContext(*cfg) kunt.ircCtx.AddEventHandler(irc.Event{Command: "PRIVMSG", Fn: func(msg irc.Message) { cmd := msg.Args[1] for i, v := range dispatch {