Exemplo n.º 1
0
// handles `s commands to get the current fight card
func manualFightCard(m *irc.Message) {
	if m.IsChannelMsg() && m.Parameters[0] == settings.Channel && m.Trail == "`s" {
		if data, err := spicerack.GetSecretData(settings.TheShiznit); err == nil {
			announceFightCard(data, nil)
		}
	}
}
Exemplo n.º 2
0
func (serv DreamService) GetCurrentFight() FightData {
	db := spicerack.Db(dbUser, dbPass, dbName)
	defer db.Close()
	fc, err := spicerack.GetSecretData(theShiznit)
	if err != nil {
		serv.ResponseBuilder().SetResponseCode(500)
		return *new(FightData)
	}
	fs, err := spicerack.GetFighterStats(webClient, statsUrl)
	if err != nil {
		serv.ResponseBuilder().SetResponseCode(500)
		return *new(FightData)
	}

	card := &FightData{
		History: make([]spicerack.History, 2),
		Stats:   *fs,
	}

	red, _ := db.GetFighter(fc.RedName)
	blue, _ := db.GetFighter(fc.BlueName)
	card.History[0] = *db.GetHistory(red)
	card.History[1] = *db.GetHistory(blue)
	card.Alert = fc.Alert

	serv.ResponseBuilder().SetResponseCode(200)
	return *card
}
Exemplo n.º 3
0
// websocket loop
func pollSalty() {
	for {
		socket, err := socketio.DialAndConnect(settings.Websocket, "", "")
		if err != nil {
			log("Failed to connect to websocket: %v. Trying again in 10 sec.", err)
			time.Sleep(time.Second * 10)
			continue
		}

		var lastStatus string = ""
		var lastAlert string = ""
		for {
			_, err := socket.Receive()
			if err != nil {
				log("Failed to receive websocket data: %v. Reconnecting.", err)
				break
			}

			data, err := spicerack.GetSecretData(settings.TheShiznit)
			if err != nil {
				log("%v", err)
			} else {
				if lastStatus != data.Status {
					// reset the cooldown so we always get an up-to-date triggered annoucement
					lastAnnounce = time.Now().Add(time.Second * -5)

					if data.TakingBets() {
						announceFightCard(data, nil)
					} else if data.InProgress() {
						announceOdds(data)
					} else if data.WeHaveAWinner() {
						announceWinner(data)
					}

					lastStatus = data.Status
				}

				if data.Alert != "" && lastAlert != data.Alert {
					lastAlert = data.Alert
					client.Privmsg(settings.Channel, fmt.Sprintf("Salty Alert: %s", data.Alert))
				}
			}
		}
	}
}