Beispiel #1
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
}
Beispiel #2
0
// sends fight card / fighter stats information to IRC
func announceFightCard(data *spicerack.FightCard, opts *Options) {
	if len(data.RedName) == 0 && len(data.BlueName) == 0 {
		return // Nothing to announce!
	}

	diff := time.Now().Sub(lastAnnounce)
	if diff.Seconds() >= 3 {
		lastAnnounce = time.Now()
		db := spicerack.Db(settings.DbUser, settings.DbPass, settings.DbName)
		defer db.Close()
		var red, blue *spicerack.Fighter
		var e error

		if opts != nil && opts.LooseSearch {
			red, blue, e = db.SearchFighters(data.RedName, data.BlueName)
		} else {
			red, blue, e = db.GetFighters(data.RedName, data.BlueName)
		}

		if e == nil {
			p1f := formatFighterName(red, data.RedName, P1_NAME_FORMAT)
			p2f := formatFighterName(blue, data.BlueName, P2_NAME_FORMAT)
			p1stats := formatFighterStats(red)
			p2stats := formatFighterStats(blue)
			// ht := getHightowerUrl(data.RedName, data.BlueName)

			var card string = ""
			if len(data.RedName) > 0 && len(data.BlueName) > 0 {
				card = fmt.Sprintf(VS_FORMAT_NO_LINK, p1f, p1stats, p2f, p2stats /*, ht*/)
			} else if len(data.RedName) > 0 {
				card = fmt.Sprintf(SOLO_FORMAT_NO_LINK, p1f, p1stats /*, ht*/)
			} else if len(data.BlueName) > 0 {
				card = fmt.Sprintf(SOLO_FORMAT_NO_LINK, p2f, p2stats /*, ht*/)
			}

			client.Privmsg(settings.Channel, card)

			state, err := db.GetRematchState(red, blue)
			if err == nil {
				switch state {
				case spicerack.TradedWins:
					client.Privmsg(settings.Channel, fmt.Sprintf(REMATCH_TRADE_FORMAT, p1f, p2f))
				case spicerack.RedBeatBlue:
					client.Privmsg(settings.Channel, fmt.Sprintf(REMATCH_FORMAT, p1f, p2f))
				case spicerack.BlueBeatRed:
					client.Privmsg(settings.Channel, fmt.Sprintf(REMATCH_FORMAT, p2f, p1f))
				}
			}

			sprinkleMrsDash(data)
		} else {
			log("%v", e)
		}
	}
}
Beispiel #3
0
func getUntieredCount(m *irc.Message) {
	if m.IsChannelMsg() && m.Parameters[0] == settings.Channel && m.Trail == "`u" {
		db := spicerack.Db(settings.DbUser, settings.DbPass, settings.DbName)
		defer db.Close()

		if count, err := db.GetUntieredCount(); err != nil {
			client.Privmsg(settings.Channel, COUNT_MESSAGE_BAD)
		} else {
			client.Privmsg(settings.Channel, fmt.Sprintf(COUNT_MESSAGE_GOOD, count))
		}
	}
}
Beispiel #4
0
func (serv DreamService) GetHistory(CharId int) (h spicerack.History) {
	db := spicerack.Db(dbUser, dbPass, dbName)
	defer db.Close()

	f, err := db.GetFighter(CharId)
	if err != nil || f.Id == 0 {
		serv.ResponseBuilder().SetResponseCode(404)
		return
	}

	h = *db.GetHistory(f)
	serv.ResponseBuilder().SetResponseCode(200)
	return
}
Beispiel #5
0
func (serv DreamService) GetFighters() (fighters []FighterInfo) {
	db := spicerack.Db(dbUser, dbPass, dbName)
	defer db.Close()

	names, err := db.GetFighterNames()
	fighters = make([]FighterInfo, 0, len(names))
	if err != nil {
		serv.ResponseBuilder().SetResponseCode(500)
	} else {
		serv.ResponseBuilder().SetResponseCode(200)
		for k, v := range names {
			fighters = append(fighters, FighterInfo{Cid: k, Name: v})
		}
		sort.Sort(ByName(fighters))
	}

	return
}