def test_get_name_history(self): names = MojangAPI.get_name_history(self.NOTCH_UUID)[0] self.assertEqual(names["changed_to_at"], 0)
async def gameofstats(self, ctx): """Compete with other members to guess the player from their stats""" if self.in_progress: await error_embed(ctx, "There is already a game in progress") return def check(message): return message.content.startswith( ">") and message.channel == ctx.channel self.in_progress = True winners = [] attempts = 0 await ctx.send( "Welcome to Game of Stats! Respond with `>[IGN]` to guess the player. Old names work too." ) for round_num in range(1, 6): while True: random_player = Player.fetch_random_player() random_ign = random_player.minecraft_username uuid = random_player.minecraft_id names_dict = MojangAPI.get_name_history(uuid) all_names = [item["name"].lower() for item in names_dict] pie_file = await self.comp_playtime_pie(random_ign) if pie_file: round_message = await ctx.channel.send( content=f"Round {round_num}:", file=pie_file) guessed = False n_guesses = 0 while not guessed: try: response = await self.bot.wait_for( "message", timeout=self.timeout, check=check) except TimeoutError: self.in_progress = False await round_message.reply( f"Game timed out; you took too long to answer. " f"The player was **{random_ign}**. " "Start a new game to play again.") return content = response.content.lower() if content.startswith(">>quit"): if response.author != ctx.author: await ctx.channel.send( f"You didn't start the game. Only {ctx.author.mention} can quit." ) continue self.in_progress = False await ctx.send(f"The player was **{random_ign}**.") if response.author.id != BOT_OWNER_ID: await ctx.channel.send(get_failure_gif()) else: await ctx.channel.send("You quit the game") if winners: await ctx.channel.send( "Thanks for playing " + " ".join( list( set(winner.mention for winner in winners)))) return elif content.startswith(">"): if content.strip(">") in all_names: await response.add_reaction("✅") await response.reply( f"You guessed correctly! ({random_ign})") winners.append(response.author) guessed = True else: await response.add_reaction("❌") if n_guesses >= self.repost_guesses: await round_message.reply( content=round_message.attachments[0].url) n_guesses = 0 n_guesses += 1 break else: if attempts > 5: ctx.channel.send( "There were errors getting stats or generating pie charts" ) return attempts += 1 continue if winners: await ctx.channel.send( "Game finished! Congratulations to the winners - " + " ".join(list(set(winner.mention for winner in winners)))) else: await ctx.channel.send("Game of Stats finished!") self.in_progress = False