Example #1
0
func Init(ctx context.Context) context.Context {
	handleRE.Longest()
	adminRE.Longest()

	var err error
	state, err = persist.New("factoids.state", &st{
		Factoids: map[string]string{},
		Aliases:  map[string]string{},
		Used:     map[string]time.Time{},
	})
	if err != nil {
		d.F(err.Error())
	}

	s = state.Get().(*st)

	tpl.init()
	path := config.FromContext(ctx).Factoids.HookPath
	http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
		tpl.render()
		tpl.execute(w)
	})

	return ctx
}
Example #2
0
func Init(ctx context.Context) context.Context {
	cfg := config.FromContext(ctx).Github
	gh := &gh{
		cfg: cfg,
		irc: sirc.FromContext(ctx),
		tpl: tpl.FromContext(ctx),
	}

	http.HandleFunc(gh.cfg.HookPath, gh.handler)
	return ctx
}
Example #3
0
// Init initializes the printing of debugging information based on its arg
func Init(ctx context.Context) context.Context {
	cfg := config.FromContext(ctx)

	mu.Lock()
	debuggingEnabled = cfg.Debug.Debug
	mu.Unlock()

	logfile := cfg.Debug.Logfile
	w, err := os.OpenFile(logfile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0660)
	if err != nil {
		panic(logfile + err.Error())
	}
	mw := io.MultiWriter(os.Stderr, w)
	log.SetOutput(mw)
	log.SetFlags(log.LstdFlags | log.Lmicroseconds)

	return ctx
}
Example #4
0
func main() {
	time.Local = time.UTC
	ctx := context.Background()
	ctx = config.Init(ctx)
	ctx = d.Init(ctx)
	ctx = tpl.Init(ctx)
	ctx = initIRC(ctx)
	ctx = analyzer.Init(ctx)
	ctx = factoids.Init(ctx)
	ctx = rss.Init(ctx)
	ctx = github.Init(ctx)

	cfg := config.FromContext(ctx).Website

	if err := http.ListenAndServe(cfg.Addr, nil); err != nil {
		d.F("ListenAndServe:", err)
	}
}
Example #5
0
func Init(ctx context.Context) context.Context {
	var err error
	state, err = persist.New("rss.state", &seenLinks)
	if err != nil {
		d.F(err.Error())
	}

	seenLinks = *state.Get().(*map[[16]byte]int64)

	r := &rs{
		cfg: config.FromContext(ctx).RSS,
		irc: sirc.FromContext(ctx),
		tpl: tpl.FromContext(ctx),
	}

	go r.pollRSS()
	go r.pollMantis()

	return ctx
}
Example #6
0
func handleIRC(ctx context.Context, c *sirc.IConn, m *irc.Message) bool {
	if m.Command == irc.RPL_WELCOME {
		cfg := config.FromContext(ctx).IRC
		for _, ch := range cfg.Channels {
			c.Write(&irc.Message{Command: irc.JOIN, Params: []string{ch}})
		}

		return false
	}

	if m.Command != irc.PRIVMSG {
		return false
	}

	if factoids.Handle(c, m) == true {
		return true
	}
	if analyzer.Handle(c, m) == true {
		return true
	}

	if m.Prefix != nil && len(m.Prefix.Host) > 0 {
		adminState.Lock()
		_, admin := admins[m.Prefix.Host]
		adminState.Unlock()
		if !admin {
			return true
		}
		if factoids.HandleAdmin(c, m) {
			return true
		}

		if handleAdmin(c, m) {
			return true
		}
	}

	return false
}
Example #7
0
func initIRC(ctx context.Context) context.Context {
	adminRE.Longest()

	var err error
	adminState, err = persist.New("admins.state", &map[string]struct{}{
		"melkor":                       struct{}{},
		"sztanpet.users.quakenet.org":  struct{}{},
		"R1CH.users.quakenet.org":      struct{}{},
		"Jim.users.quakenet.org":       struct{}{},
		"Warchamp7.users.quakenet.org": struct{}{},
		"hwd.users.quakenet.org":       struct{}{},
		"paibox.users.quakenet.org":    struct{}{},
		"ThoNohT.users.quakenet.org":   struct{}{},
		"dodgepong.users.quakenet.org": struct{}{},
		"Sapiens.users.quakenet.org":   struct{}{},
	})
	if err != nil {
		d.F(err.Error())
	}

	admins = *adminState.Get().(*map[string]struct{})

	tcfg := config.FromContext(ctx)
	sirc.DebuggingEnabled = tcfg.Debug.Debug
	cfg := sirc.Config{
		Addr:     tcfg.IRC.Addr,
		Nick:     tcfg.IRC.Nick,
		Password: tcfg.IRC.Password,
		RealName: "http://obscommits.sztanpet.net/",
	}
	c := sirc.Init(cfg, func(c *sirc.IConn, m *irc.Message) bool {
		return handleIRC(ctx, c, m)
	})

	return c.ToContext(ctx)
}
Example #8
0
func Init(ctx context.Context) context.Context {
	anurl = config.FromContext(ctx).Analyzer.URL
	return ctx
}