forked from fluffle/sp0rkle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (63 loc) · 1.85 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
// sp0rkle will live again!
import (
_ "expvar"
"flag"
"github.com/fluffle/golog/logging"
"github.com/fluffle/sp0rkle/bot"
"github.com/fluffle/sp0rkle/db"
"github.com/fluffle/sp0rkle/drivers/calcdriver"
"github.com/fluffle/sp0rkle/drivers/decisiondriver"
"github.com/fluffle/sp0rkle/drivers/factdriver"
"github.com/fluffle/sp0rkle/drivers/karmadriver"
"github.com/fluffle/sp0rkle/drivers/markovdriver"
// "github.com/fluffle/sp0rkle/drivers/netdriver"
"github.com/fluffle/sp0rkle/drivers/quotedriver"
"github.com/fluffle/sp0rkle/drivers/reminddriver"
"github.com/fluffle/sp0rkle/drivers/seendriver"
"github.com/fluffle/sp0rkle/drivers/urldriver"
"net/http"
"os"
"os/exec"
"syscall"
)
var (
httpPort *string = flag.String("http", ":6666", "Port to serve HTTP requests on.")
)
func main() {
flag.Parse()
logging.InitFromFlags()
// Initialise bot state
bot.Init()
// Connect to mongo
db.Init()
defer db.Close()
// Add drivers
calcdriver.Init()
decisiondriver.Init()
factdriver.Init()
karmadriver.Init()
markovdriver.Init()
quotedriver.Init()
reminddriver.Init()
seendriver.Init()
urldriver.Init()
// Start up the HTTP server
go http.ListenAndServe(*httpPort, nil)
// Connect the bot to IRC and wait; reconnects are handled automatically.
// If we get true back from the bot, re-exec the (rebuilt) binary.
if bot.Connect() {
// Calling syscall.Exec probably means deferred functions won't get
// called, so disconnect from mongodb first for politeness' sake.
db.Close()
// If sp0rkle was run from PATH, we need to do that lookup manually.
fq, _ := exec.LookPath(os.Args[0])
logging.Warn("Re-executing sp0rkle with args '%v'.", os.Args)
err := syscall.Exec(fq, os.Args, os.Environ())
if err != nil {
// hmmmmmm
logging.Fatal("Couldn't re-exec sp0rkle: %v", err)
}
}
logging.Info("Shutting down cleanly.")
}