Esempio n. 1
0
func BenchmarkLoadBigHistory(b *testing.B) {
	c := foosbot.NewContext()
	m := randomOutcomes(100000)
	addMatches(c, m)
	c.Store()
	benchmarkLoadState(b, c)
}
Esempio n. 2
0
func BenchmarkStoreBigHistory(b *testing.B) {
	c := foosbot.NewContext()
	m := randomOutcomes(100000)
	addMatches(c, m)
	for i := 0; i < b.N; i++ {
		benchmarkStoreState(b, c)
	}
}
Esempio n. 3
0
func main() {
	flag.Parse()

	ctx := foosbot.NewContext()
	err := ctx.Load()
	if err != nil {
		log.Printf("cannot load repository")
		return
	}
	go backup(ctx)

	token, err := loadToken()
	if err != nil {
		log.Printf("cannot open slack access token: %s", err)
		return
	}

	api := slack.New(token)
	rtm := api.NewRTM()
	go rtm.ManageConnection()

	incomingExit := exit()
Loop:
	for {
		select {
		case <-incomingExit:
			break Loop
		case msg := <-rtm.IncomingEvents:
			switch ev := msg.Data.(type) {
			case *slack.HelloEvent:
			case *slack.ConnectedEvent:
			case *slack.PresenceChangeEvent:
			case *slack.LatencyReport:
			case *slack.RTMError:
			case *slack.MessageEvent:
				response := process(ctx, ev)
				rtm.SendMessage(rtm.NewOutgoingMessage(response, ev.Channel))
			case *slack.InvalidAuthEvent:
				fmt.Printf("Invalid credentials")
				break Loop
			default:
				// Ignore other events.
				// fmt.Printf("Unexpected: %v\n", msg.Data)
			}
		}
	}

	err = ctx.Store()
	if err != nil {
		log.Printf("cannot store repository")
		return
	}
}
Esempio n. 4
0
func main() {
	foosbot.Verbose = false
	ctx := foosbot.NewContext()
	err := ctx.Load()
	if err != nil {
		panic(err)
	}
	q := foosbot.Query(ctx)

	var limit int

	app := cli.NewApp()
	app.Name = "foosbot"
	app.Usage = "The foosball match tracker"
	app.Commands = []cli.Command{
		{
			Name:    "match",
			Aliases: []string{"m"},
			Usage:   "Match history listing",
			Action: func(c *cli.Context) {
				matches := q.Matches().Limit(limit).Get()
				for _, match := range matches {
					fmt.Println(foosbot.Print(match))
				}
			},
			Flags: []cli.Flag{
				cli.IntFlag{
					Name:        "limit",
					Value:       10,
					Usage:       "Limits to the specified amount of results",
					Destination: &limit,
				},
			},
		},
		{
			Name: "run",
			Action: func(c *cli.Context) {
				args := c.Args()
				s := args.First()
				s += " "
				s += strings.Join(args.Tail(), " ")
				r := bytes.NewReader([]byte(s))
				parser := parsing.NewParser(r)
				out := process(ctx, parser)
				fmt.Println(out)
				ctx.Store()
			},
		},
	}
	app.Run(os.Args)
}
Esempio n. 5
0
func BenchmarkCreateBigHistory(b *testing.B) {
	c := foosbot.NewContext()
	m := randomOutcomes(100000)
	benchmarkBuildHistory(b, c, m)
}