How to use the hypixel.PlayerNotFoundException function in hypixel

To help you get started, we’ve selected a few hypixel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Snuggle / hypixel.py / hypixel.py View on Github external
allURLS = [HYPIXEL_API_URL + '{}?key={}{}'.format(typeOfRequest, api_key, requestEnd)] # Create request URL.

    # If url exists in request cache, and time hasn't expired...
    if cacheURL in requestCache and requestCache[cacheURL]['cacheTime'] > time():
        response = requestCache[cacheURL]['data'] # TODO: Extend cache time
    else:
        requests = (grequests.get(u) for u in allURLS)
        responses = grequests.imap(requests)
        for r in responses:
            response = r.json()

        if response['success'] is False:
            raise HypixelAPIError(response)
        if typeOfRequest == 'player':
            if response['player'] is None:
                raise PlayerNotFoundException(uuid)
        if typeOfRequest != 'key': # Don't cache key requests.
            requestCache[cacheURL] = {}
            requestCache[cacheURL]['data'] = response
            requestCache[cacheURL]['cacheTime'] = time() + cacheTime # Cache request and clean current cache.
            cleanCache()
    try:
        return response[typeOfRequest]
    except KeyError:
        return response
github robingall2910 / RobTheBoat / commands / hypixel.py View on Github external
awdr = '{:,.2f}'.format(wdr)
            akdr = '{:,.2f}'.format(kdr)
            afkdr = '{:,.2f}'.format(fkdr)
            embed.add_field(name='Win/Loss Ratio', value=f"{awdr}")
            embed.add_field(name='Kill/Death Ratio', value=f"{akdr}")
            embed.add_field(name='Final Kill/Final Death Ratio', value=f"{afkdr}")
            if sys.platform == "windows":
                embed.set_footer(
                    text=f"Requested by: {ctx.message.author} / {datetime.fromtimestamp(time.time()).strftime('%A, %B %#d, %Y at %#I:%M %p %Z')}",
                    icon_url=ctx.message.author.avatar_url)
            elif sys.platform == "linux":
                embed.set_footer(
                    text=f"Requested by: {ctx.message.author} / {datetime.fromtimestamp(time.time()).strftime('%A, %B %-d, %Y at %-I:%M %p %Z')}",
                    icon_url=ctx.message.author.avatar_url)
            await ctx.send(embed=embed)
        except hypixel.PlayerNotFoundException:
            await ctx.send("Player not found! Try another UUID or username.")
        except KeyError:
            await ctx.send("This user has never played Bed Wars before.")
        except Exception:
            await ctx.send(traceback.print_exc())
github Snuggle / hypixel.py / hypixel.py View on Github external
def __init__(self, UUID):
        """ This is called whenever someone uses hypixel.Player('Snuggle').
            Get player's UUID, if it's a username. Get Hypixel-API data. """
        self.UUID = UUID
        if len(UUID) <= 16: # If the UUID isn't actually a UUID... *rolls eyes* Lazy people.
            self.JSON = getJSON('player', uuid=UUID) # Get player's Hypixel-API JSON information.
            JSON = self.JSON
            self.UUID = JSON['uuid'] # Pretend that nothing happened and get the UUID from the API.
        elif len(UUID) == 32 or len(UUID) == 36: # If it's actually a UUID, with/without hyphens...
            self.JSON = getJSON('player', uuid=UUID)
        else:
            raise PlayerNotFoundException(UUID)
github Snuggle / hypixel.py / .examples / advancedExample.py View on Github external
print("The player is rank: " + player.getRank()['rank']) # Get the rank and print it.
            print("Were they previously a staff member? {}".format(player.getRank()['wasStaff']))

        elif optionInput.lower() == "level":
            print("The player is level: " + str(player.getLevel())) # Print the player's low level!

        elif optionInput.lower() == "karma":
            print("The player has {} karma.".format(player.JSON['karma'])) # +25 karma ;)

        elif optionInput.lower() == "twitter": # Okay this is a little more complicated
            try:
                socialMedias = player.JSON['socialMedia']['links'] # Check their social media
                print(socialMedias['TWITTER']) # And if they have a Twitter account, print it.
            except KeyError: # If an error comes up, saying they don't have a twitter account...
                print("This user doesn't have a Twitter account linked.") # Say that.
    except hypixel.PlayerNotFoundException: # If the player doesn't live on earth, catch this exception.
        print("Cannot find player. :/")