def priority_rng_signups(playing_signups_list, size): """ Randomly generates a list of signups. To be used for PUG events. If a player is not registered / does not exist, they will not be included in the random list. Handle this accordingly - a list of unregistered players is returned by this function. :param playing_signups_list: A list of Signup objects :param size: The amount of players you would like to include in the output list :return: (selected_players, benched_players, unregistered_signups) """ seed() players = [] unregistered_signups = [] for signup in playing_signups_list: try: players.append(Player.from_discord_id(signup.user_id)) except PlayerDoesNotExistError: unregistered_signups.append(signup) shuffle(players) players = sorted(players, key=lambda item: item.priority, reverse=True) selected_players = players[:size] for player in selected_players: player.set_priority(0) benched_players = players[size:] for player in benched_players: player.change_priority(1) return selected_players, benched_players, unregistered_signups
async def examine_members(self, ctx): """Examines the status and checks nicknames for all server members (for debug purposes)""" if not has_permissions(ctx, ADMIN_ROLE): await ctx.send( "You do not have sufficient permissions to perform this command", hidden=True) return False server = ctx.guild registered = [] unregistered = [] without_nick = [] for member in server.members: if not member.bot: if member.nick is None: without_nick.append(member.mention) else: try: player = Player.from_discord_id(member.id) except PlayerDoesNotExistError: unregistered.append(member.mention) else: team_list = re.findall(r"^\[(\w{1,4})\]", member.nick) alias_list = re.findall(r"\s\((.*)\)$", member.nick) new_nick = f"{'[' + team_list[0] + '] ' if team_list else ''}{player.minecraft_username}" + \ (f" ({alias_list[0]})" if alias_list else "") registered.append(f"{member.mention} → `{new_nick}`") await create_list_pages(self.bot, ctx, info=registered, title="Registered Users", elements_per_page=20) await create_list_pages(self.bot, ctx, info=unregistered, title="Unregistered Users", elements_per_page=20) await create_list_pages(self.bot, ctx, info=without_nick, title="Users without nicknames", elements_per_page=20)
async def unregister(self, ctx, user: User = None): if not has_permissions(ctx, MOD_ROLE): await ctx.send( "You do not have sufficient permissions to perform this command", hidden=True) return False """ Allows a PUG Mod to unregister a discord user from the Minecraft account they registered to. Usage: unregister <user_mention> Example: unregister @Ninsanity """ if not user: await error_embed(ctx, "Missing Argument <input_user>") try: player = Player.from_discord_id(user.id) except PlayerDoesNotExistError: await error_embed(ctx, "Player is not registered in the database.") return await response_embed( ctx, "Confirm", f"""Are you sure you want to delete {user.mention} from the database? \nThis action is **permanent** and **irreversible**, and will remove their elo and priority **forever**. \nReply with yes or no.""") def check(m): return m.author == ctx.author and m.channel == ctx.channel response = await self.bot.wait_for('message', check=check) if response.content.lower() == "y" or response.content.lower( ) == "yes": player.delete() await success_embed(ctx, f"User {user.mention} has been unregistered.") else: await response_embed( ctx, "Stopped Deletion", f"User {user.mention} will not be deleted from the database.")
async def profile(self, ctx, user: User = None): """ Displays a user's profile """ if user: if not isinstance(user, int): player_id = user.id else: player_id = user else: player_id = ctx.author.id try: player = Player.from_discord_id(player_id) except PlayerDoesNotExistError: await error_embed(ctx, "Player does not exist") return #Position in leaderboard data = get_sorted_elo() count = 1 for item in data: if player: if player.minecraft_username == item[0]: leader_pos = count break count += 1 stats = f"**ELO:** {getattr(player, 'elo')}\n**Rank**: #{leader_pos}\n**Discord:** <@{getattr(player, 'discord_id')}>" #for key in player.__dict__.keys(): # stats += f"**{key}:** {getattr(player, key)}\n" embed = Embed(description=stats, color=Colour.dark_purple()) embed.set_author( name=f"User profile - {getattr(player, 'minecraft_username')}", icon_url= f"https://cravatar.eu/helmavatar/{getattr(player, 'minecraft_id')}/128.png" ) await ctx.send(embed=embed)
async def user(self, ctx, discord_tag: User = None, action_type="get", variable_name=None, value=None): """ Allows a PUG Mod to edit information about a user. Usage: user @Tom <get/set> <variable_name> <value> Examples: user @Tom get returns user profile user @Tom set elo [elo] sets user ELO """ if not has_permissions(ctx, MOD_ROLE): await ctx.send( "You do not have sufficient permissions to perform this command", hidden=True) return False user = self.bot.get_user(discord_tag.id) if action_type == "get": try: player = Player.from_discord_id(user.id) except PlayerDoesNotExistError: await error_embed(ctx, "Player does not exist") return info = "" for key in player.__dict__.keys(): info += f"**{key}**: {getattr(player, key)}\n" embed = Embed(description=info, title=f"User Profile - {user.name}", color=Colour.dark_purple()) await ctx.send(embed=embed) elif action_type == "set": try: player = Player.from_discord_id(user.id) except PlayerDoesNotExistError: await error_embed(ctx, "Player does not exist") return if variable_name: if value: if variable_name == "username": old_username = player.update_minecraft_username() try: player.change_minecraft_username(value) await success_embed( ctx, f"Changed {discord_tag.mention}'s username: **{old_username}** -> **{value}**" ) except UsernameAlreadyExistsError: await error_embed( ctx, f"Username **{value}** is already in the database" ) except UsernameDoesNotExistError: await error_embed( ctx, f"Username **{value}** is not a valid username" ) elif variable_name == "discord": value = value[3:-1] if value.isdigit(): user = self.bot.get_user(int(value)) if user: try: player.change_discord_id(user.id) await success_embed( ctx, f"Changed discord user: {discord_tag.mention} -> {user.mention}" ) except DiscordAlreadyExistsError: await error_embed( ctx, f"User {user.mention} is already in the database" ) else: await error_embed(ctx, "Value must be a User") else: await error_embed(ctx, "Value must be a User") elif variable_name == "elo": old_elo = player.get_elo() if value.isdigit(): value = int(value) if player.set_elo(value): await success_embed( ctx, f"Set {discord_tag.mention}'s elo: **{old_elo}** -> **{value}**" ) else: await error_embed( ctx, f"Elo given (**{value}**) is below Elo floor (**{ELO_FLOOR}**)" ) else: await error_embed(ctx, "Value must be an int") else: old_priority = player.get_priority() if value.isdigit(): value = int(value) if player.set_priority(value): await success_embed( ctx, f"Set {discord_tag.mention}'s priority: **{old_priority}** -> **{value}**" ) else: await error_embed( ctx, f"Priority given (**{value}**) is negative" ) else: await error_embed(ctx, "Value must be an int") else: await error_embed(ctx, "No value inputted") else: await error_embed(ctx, "No variable name inputted") else: await error_embed(ctx, "Invalid action argument. Use 'get' or 'set'")