~exprez135/go-hypixel

224b7cfb00203f842937735411e48320b1051ed8 — Nate Ijams 3 years ago f5d033b v0.0.13
Disable updating of friends lists, temporarily.
5 files changed, 40 insertions(+), 32 deletions(-)

M engine/api.go
M engine/discord.go
M engine/organizations.go
M engine/scheduling.go
M engine/tracking.go
M engine/api.go => engine/api.go +3 -2
@@ 98,6 98,7 @@ func DeleteUsernames(username string) error {
	return nil
}

/*
// PutFriends fetches the raw JSON friends from the API and stores it in the "friends" bucket. Returns an error.
func PutFriends(uuid string) error {
	log.Println("STARTING PutFriends()...")


@@ 115,7 116,7 @@ func PutFriends(uuid string) error {
			log.Println("PutFriends(): problem putting. putErr is:", putErr)
			return putErr
		}
		return nil 
		return nil
	})
	if err != nil {
		log.Println("Error putting friends:", err)


@@ 186,7 187,7 @@ func GetFriendsList(uuid string) ([]string, error) {
	}
	return friendsList, nil
}

*/
// PutGuild fetches the raw JSON guild from the API and stores it in the "guilds" bucket. Returns an error.
func PutGuild(name string) error {
	rawGuild, err := Hclient.GuildByName(name)

M engine/discord.go => engine/discord.go +15 -12
@@ 68,11 68,11 @@ func StartDiscord() {
	router.On("trackguild", func(ctx *exrouter.Context) {
		trackGuild(ctx)
	}).Desc("adds a guild to the tracking list. You will get notifications when members get on or off Hypixel")

	router.On("trackfriends", func(ctx *exrouter.Context) {
		trackFriends(ctx)
	}).Desc("adds a player's friends to the tracking list. You will get notifications when their friends get on or off Hypixel")

/*
		router.On("trackfriends", func(ctx *exrouter.Context) {
			trackFriends(ctx)
		}).Desc("adds a player's friends to the tracking list. You will get notifications when their friends get on or off Hypixel")
*/
	router.On("removeplayer", func(ctx *exrouter.Context) {
		removePlayer(ctx)
	}).Desc("adds a player to the tracking list. You will get notifications when they get on or off Hypixel")


@@ 80,16 80,16 @@ func StartDiscord() {
	router.On("removeguild", func(ctx *exrouter.Context) {
		removeGuild(ctx)
	}).Desc("adds a guild to the tracking list. You will get notifications when members get on or off Hypixel")

	router.On("removefriends", func(ctx *exrouter.Context) {
		removeFriends(ctx)
	}).Desc("adds a player's friends to the tracking list. You will get notifications when their friends get on or off Hypixel")

	/*
		router.On("removefriends", func(ctx *exrouter.Context) {
			removeFriends(ctx)
		}).Desc("adds a player's friends to the tracking list. You will get notifications when their friends get on or off Hypixel")
	*/
	router.On("listtracked", func(ctx *exrouter.Context) {
		listTracked(ctx)
	}).Desc("lists all the players, guilds, and friend lists you are tracking.")

	router.On("online", func(ctx *exrouter.Context) {
	router.On("listonline", func(ctx *exrouter.Context) {
		listOnline(ctx)
	}).Desc("lists all the tracked players, guilds, and friends who are online.")



@@ 309,6 309,7 @@ func removeGuild(ctx *exrouter.Context) {

}

/*
func trackFriends(ctx *exrouter.Context) {
	arguments := ctx.Args
	arg := arguments.Get(1)


@@ 344,6 345,7 @@ func removeFriends(ctx *exrouter.Context) {
	ctx.Reply("Friends of " + arg + " are no longer being tracked! Please wait up to five minutes for notifications to stop. If the player is in a tracked guild or is being individually being tracked, notifications will continue as usual.")

}
*/

func listTracked(ctx *exrouter.Context) {
	players, friends, guilds, err := GetTrackedList("discord", ctx.Msg.GuildID)


@@ 387,6 389,7 @@ func listTracked(ctx *exrouter.Context) {
}

func listOnline(ctx *exrouter.Context) {
	log.Println("STARTING listOnline() run...")
	players, friends, guilds, err := GetTrackedList("discord", ctx.Msg.GuildID)

	if err != nil {


@@ 418,7 421,7 @@ func listOnline(ctx *exrouter.Context) {

	// RemoveDuplicates(listOfPlayers)

	newListOfPlayers := removeDuplicates(listOfPlayers)
	newListOfPlayers := RemoveDuplicates(listOfPlayers)

	// Reference tracked bucket, if online: add to onlineList


M engine/organizations.go => engine/organizations.go +2 -1
@@ 102,6 102,7 @@ func AddPlayerToOrganization(platform string, platformID string, uuid string) er
	return nil
}

/*
// AddFriendsToOrganization appends a new player uuid to the organizations list of tracked friend lists. First, it Gets the proper organization. Then it appends and Puts the new org structure into BoltDB. Returns an error.
func AddFriendsToOrganization(platform string, platformID string, uuid string) error {
	// put friends list


@@ 125,7 126,7 @@ func AddFriendsToOrganization(platform string, platformID string, uuid string) e
	}
	return nil
}

*/
// AddGuildToOrganization appends a new guild name to the organizations list of tracked guild lists. First, it Gets the proper organization. Then it appends and Puts the new org structure into BoltDB. Returns an error.
func AddGuildToOrganization(platform string, platformID string, guild string) error {
	// update guild or add it to guild bucket

M engine/scheduling.go => engine/scheduling.go +10 -10
@@ 34,17 34,17 @@ func UpdateFriendGuildLists() {
		log.Println(err)
	}
	// iterate through the two lists and call the Put functions to update them

	for _, f := range friendList {
		fErr := PutFriends(f)
		if fErr != nil {
			log.Println("fErr:", fErr)
			continue
	/*
		for _, f := range friendList {
			fErr := PutFriends(f)
			if fErr != nil {
				log.Println("fErr:", fErr)
				continue
			}
			// Sleep for 10 seconds so we don't do all this too quickly
			time.Sleep(10 * time.Second)
		}
		// Sleep for 10 seconds so we don't do all this too quickly
		time.Sleep(10 * time.Second)
	}

	*/
	for _, g := range guildList {
		gErr := PutGuild(g)
		if gErr != nil {

M engine/tracking.go => engine/tracking.go +10 -7
@@ 36,7 36,7 @@ func UpdateTrackedPlayerList() error {

			// take players and append to trackedPlayers
			trackedPlayers = append(trackedPlayers, obj.Players...)

/*
			// for each friends GetList then append
			for _, f := range obj.Friends {
				fList, err := GetFriendsList(f)


@@ 46,7 46,7 @@ func UpdateTrackedPlayerList() error {
				}
				trackedPlayers = append(trackedPlayers, fList...)
			}

*/
			// for each guild GetList then append
			for _, g := range obj.Guilds {
				gList, err := GetGuildList(g)


@@ 177,7 177,7 @@ func SendStatusNotifications(uuid string, newStatus bool) error {
					return nil
				}
			}

/*
			log.Println("Starting timer to time the GetFriendsList part of notifications")
			start := time.Now()
			log.Println("NOTIFICATIONS ISSUE MIGHT HAPPEN BELOW.")


@@ 202,7 202,7 @@ func SendStatusNotifications(uuid string, newStatus bool) error {
			}

			log.Println("TIME SINCE start timer:", time.Since(start))

*/
			return nil

		})


@@ 220,9 220,12 @@ func GetCachedPlayerStatus(uuid string) bool {
	Iron.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte("tracked"))
		v := b.Get([]byte(uuid))

		result = strconv.FormatBool(v)
		return nil
		if string(v) == "true" {
			result = true
		}
		else {
			result = false
		}
	})

	return result