func StartBot() { log.Printf("stats-bot: v%v#%v", Version, Commit) go StartHTTPServer() // Has to run in a Goroutine. Blocks bot := slack.New(Config.Token) Census = census.NewCensus("s:maximumtwang", "ps2ps4us:v2") CensusEU = census.NewCensus("s:maximumtwang", "ps2ps4eu:v2") StartPopGathering() t, err := bot.AuthTest() if err != nil { log.Printf("Error in auth test: [%v]", err.Error()) return } log.Printf("Auth: %v on team %v", t.User, t.Team) rtm := bot.NewRTM() go rtm.ManageConnection() for { select { case msg := <-rtm.IncomingEvents: switch m := msg.Data.(type) { case *slack.MessageEvent: Dispatch(&Context{Bot: bot, Ev: m, RTM: rtm}) } } } }
func TestNewOutfit(t *testing.T) { c := census.NewCensus("maximumtwang", "ps2ps4us:v2") NewOutfit("Testing Outfit", "r2877654", "THUNDERGROOVE", c) }
func main() { fmt.Printf("Starting to gather server population info\nPress Ctrl-C to quit\n") c := census.NewCensus("s:maximumtwang", "ps2ps4us:v2") events := c.NewEventStream() sub := census.NewEventSubscription() sub.Worlds = []string{"all"} sub.Characters = []string{"all"} sub.EventNames = []string{"PlayerLogin", "PlayerLogout"} if err := events.Subscribe(sub); err != nil { fmt.Printf("FAIL: Couldn't subscribe to events: [%v]\n", err.Error()) return } pop := c.NewPopulationSet() infoChan := make(chan struct{}, 0) go func() { fmt.Printf("Press Enter to print stats!\n") for { pause() infoChan <- struct{}{} } }() for { select { case <-infoChan: fmt.Printf("Printing server population info: \n") for name, server := range pop.Servers { fmt.Printf("%v:\n", name) fmt.Printf("VS: %v:%%%v\n", server.VS, server.VSPercent()) fmt.Printf("TR: %v:%%%v\n", server.TR, server.TRPercent()) fmt.Printf("NC: %v:%%%v\n", server.NC, server.NCPercent()) } case err := <-events.Err: fmt.Printf("error: %v\n", err.Error()) case <-events.Closed: fmt.Printf("Websocket closed\n") break case event := <-events.Events: switch event.Payload.EventName { case "PlayerLogin": ch, err := c.GetCharacterByID(event.Payload.CharacterID) if err != nil { fmt.Printf("ERROR: Failed to get character from ID: '%v' [%v]\n", event.Payload.CharacterID, err.Error()) continue } server := c.GetServerByID(event.Payload.WorldID) pop.PlayerLogin(server.Name.En, ch.FactionID) case "PlayerLogout": ch, err := c.GetCharacterByID(event.Payload.CharacterID) if err != nil { fmt.Printf("ERROR: Failed to get character from ID: '%v' [%v]\n", event.Payload.CharacterID, err.Error()) continue } server := c.GetServerByID(event.Payload.WorldID) pop.PlayerLogin(server.Name.En, ch.FactionID) } } } }