~exprez135/go-hypixel

2d23f5ccfe8aee13b1dfaaec2744be4bdbf595a2 — Nate Ijams 3 years ago 2c0739d
Add handling for gameTime 0.
2 files changed, 14 insertions(+), 4 deletions(-)

M engine/discord.go
M main.go
M engine/discord.go => engine/discord.go +12 -2
@@ 293,14 293,24 @@ func playerRecent(ctx *exrouter.Context) {
	timeSince := time.Since(gameTime2)

	// check if gameTime is more than 1 hour ago
	if timeSince > oneHour {
	if (timeSince > oneHour && gameTime != 0) {
		// game was too long ago
		message += " They haven't played any Bed Wars games in the last hour. :("
	} else {
		// game was within hour

		// Wiki URL
		mapURL := "https://hypixel.fandom.com/wiki/" + strings.ReplaceAll(gameMap, " ", "_")

		// Ended or not ended statement
		var endMessage string
		if gameTime == 0 {
			endMessage = " is still running!"
		} else {
			endMessage = " map ended " + strconv.FormatFloat(timeSince.Minutes(), 'f', 2, 64) + " minutes ago. "
		}
		// TODO fix link in case of two words
		message += " Their last game in Bed Wars " + gameMode + " on the " + gameMap + " map ended " + strconv.FormatFloat(timeSince.Minutes(), 'f', 2, 64) + " minutes ago. " + mapURL
		message += " Their last game in Bed Wars " + gameMode + " on the " + gameMap + endMessage + mapURL
	}

	// put together message

M main.go => main.go +2 -2
@@ 7,8 7,8 @@ import (
	"os/signal"
	"syscall"

	"git.sr.ht/~exprez135/go-hypixel/engine"
	//"./engine"
	//"git.sr.ht/~exprez135/go-hypixel/engine"
	"./engine"
)

var platformName = "discord"