def brokenQueue(player: Member, roles: List[Role]) -> Embed: """ Removes the active match that the author is in. Parameters: player: dicord.Member - The author of the message. roles: List[discord.Role] - The roles of the author of the message. Returns: dicord.Embed - The embedded message to respond with. """ if (not Queue.isBotAdmin(roles)): return ErrorEmbed( title="Permission Denied", desc="You do not have permission to break the queue without a majority." ) msg = lbBrokenQueue(player) if (":white_check_mark:" in msg): return QueueUpdateEmbed( title="Popped Queue Removed", desc="The popped queue has been removed from active matches. You may now re-queue." ).add_field( name="Current Queue 0/6", value="Queue is empty." ) return ErrorEmbed( title="Could Not Remove Queue", desc=msg )
def NormQ() -> List[str or Embed]: playerList = Queue.getQueueList() queueSize = Queue.getQueueLength() blueTeam, orangeTeam = Queue.getTeamList() blueCap, orangeCap = Queue.getCaptains() embed = None if (Queue.queueAlreadyPopped() or queueSize == 6): embed = ErrorEmbed( title="Current Lobby Not Set", desc="Whoa there Norm! You can't queue until the current queue has finished popping." ) elif (len(playerList) == 0): embed = QueueUpdateEmbed( title="Norm has Started the Queue!", desc="<@629502587963572225> wants to queue!\n\nQueued for 0 minutes.\n\nType **!q** to join", ) else: embed = QueueUpdateEmbed( title="Norm Added to Queue", desc="<@629502587963572225> has been added to the queue for 0 minutes.\n\n" "**Queue size: " + str(queueSize + 1) + "/6**\n\n" "**Current Queue:**\nNorm (0 mins)\n" + playerList ) return embed edited_embed = CaptainsRandomHelpEmbed(embed, blueTeam, orangeTeam, blueCap, orangeCap) return edited_embed
def captains(player: Member) -> Embed: """ Pops the queue and randomly assigns two captains. Will show captains if captains are already set. Parameters: player: dicord.Member - The author of the message. Returns: dicord.Embed - The embedded message to respond with. """ if (Queue.getQueueLength() != 6): return ErrorEmbed( title="Queue is Not Full", desc="You cannot pop a queue until is full." ) if (not Queue.isPlayerInQueue(player)): return ErrorEmbed( title="Not in Queue", desc="You are not in the queue, therefore you cannot pop the queue." ).add_field( name="Queue Popped!", value="React to the \U0001F1E8 or \U0001F1F7 for captains or random.\n", inline=False ).add_field( name="Current Queue " + str(Queue.getQueueLength()) + "/6", value=Queue.getQueueList(), inline=False ) blueCap, orangeCap = Queue.captainsPop() playerList = Queue.getQueueList(includeTimes=False, includeLetters=True) if (Queue.queueAlreadyPopped()): blueTeam, _ = Queue.getTeamList() return CaptainsPopEmbed( blueCap, orangeCap, playerList ) return CaptainsPopEmbed( blueCap, orangeCap, playerList )
def fill(roles: List[Role]) -> Embed: if (Queue.isBotAdmin(roles)): TestHelper.fillQueue() return AdminEmbed(title="Queue Filled", desc="Queue has been filled with fake/real players") return ErrorEmbed(title="Permission Denied", desc="You do not have permission to fill the queue.")
def flipCap(roles: List[Role]) -> Embed: if (Queue.isBotAdmin(roles)): TestHelper.flipCaptains() return AdminEmbed(title="Captains Flipped", desc="Captains have been flipped.") return ErrorEmbed(title="Permission Denied", desc="You do not have permission to flip the captains.")
def flipReport(roles: List[Role]) -> Embed: if (Queue.isBotAdmin(roles)): TestHelper.swapReportedPlayer() return AdminEmbed(title="Reported Player Swapped", desc="The player who reported has been swapped out.") return ErrorEmbed( title="Permission Denied", desc="You do not have permission to flip the reporting player.")
async def forceReport(mentions: str, roles: List[Role], lbChannel: Channel, *arg) -> Embed: if (Queue.isBotAdmin(roles)): if (len(arg) == 2 and "<@!" in arg[0]): split = mentions.split("<@!") if (str(arg[1]).lower() == Team.BLUE): player_id = split[1][:-6] elif(str(arg[1]).lower() == Team.ORANGE): player_id = split[1][:-8] else: return ErrorEmbed( title="You Must Report A Valid Team", desc="You did not supply a valid team to report." ) if (player_id.isdigit()): msg = reportMatch(player_id, arg[1], True) if (msg): try: # if match was reported successfully, update leaderboard channel await updateLeaderboardChannel(lbChannel) except Exception as e: print("! Norm does not have access to update the leaderboard.", e) return AdminEmbed( title="Match Force Reported Successfully", desc="You may now re-queue." ) else: return ErrorEmbed( title="Did Not Mention a Player", desc="You must mention one player who is in the match you want to report." ) else: ErrorEmbed( title="Did Not Mention a Player", desc="You must mention one player who is in the match you want to report." ) else: return ErrorEmbed( title="Permission Denied", desc="You do not have the strength to force report matches. Ask an admin if you need to force report a match." # noqa )
def leave(player: Member) -> Embed: """ Removes author from the Queue. Parameters: player: discord.Member - The author of the message. The person being removed from the queue. Returns: dicord.Embed - The embedded message to respond with. """ username = player.display_name if (Queue.queueAlreadyPopped()): return ErrorEmbed( title="Queue Already Popped", desc="TOO LATE! You should've left before captains were picked." ) if (Queue.isPlayerInQueue(player)): Queue.removeFromQueue(player) playerList = Queue.getQueueList() if(Queue.getQueueLength() != 0): return QueueUpdateEmbed( title="Player Left Queue", desc=username + " has left the queue." ).add_field( name="Remaining Players (" + str(Queue.getQueueLength()) + "/6)", value=playerList ) return QueueUpdateEmbed( title="Player Left Queue", desc=username + " has left the queue.\n\n" "Queue is now empty.\n\n" "Join the queue by reacting to the β .\n" ) playerList = Queue.getQueueList() embed = ErrorEmbed( title="Not in Queue", desc="You are not in the queue, react to the β to join if there is space.\n" ) if (Queue.getQueueLength() == 6): embed.add_field( name="Queue Popped!", value="React to the \U0001F1E8 or \U0001F1F7 for captains or random.\n", inline=False ) embed.add_field( name="Queued Players (" + str(Queue.getQueueLength()) + "/6)", value="Queue is empty." if playerList == "" else playerList ) return embed
def random(player: Member) -> Embed: """ Pops the queue and randomly assigns players to teams. Parameters: player: dicord.Member - The author of the message. Returns: dicord.Embed - The embedded message to respond with. """ if (Queue.queueAlreadyPopped()): return ErrorEmbed( title="Captains Already Chosen", desc="You cannot change your mind once you pick captains." ) if (Queue.getQueueLength() != 6): return ErrorEmbed( title="Queue is Not Full", desc="You cannot pop a queue until is full." ) if (not Queue.isPlayerInQueue(player)): return ErrorEmbed( title="Not in Queue", desc="You are not in the queue, therefore you cannot pop the queue." ).add_field( name="Queue Popped!", value="React to the \U0001F1E8 or \U0001F1F7 for captains or random.\n", inline=False ).add_field( name="Current Queue " + str(Queue.getQueueLength()) + "/6", value=Queue.getQueueList(), inline=False ) blueTeam, orangeTeam = Queue.randomPop() Leaderboard.startMatch(blueTeam, orangeTeam) return PlayersSetEmbed(blueTeam, orangeTeam)
def clear(roles: List[Role]) -> Embed: """ Clears the current queue if the author has the Bot Admin role. Parameters: roles: List[discord.Role] - The roles of the author of the message. Returns: dicord.Embed - The embedded message to respond with. """ if(Queue.isBotAdmin(roles)): Queue.clearQueue() return AdminEmbed( title="Queue Cleared", desc="The queue has been cleared by an admin. <:UNCCfeelsgood:538182514091491338>" ) return ErrorEmbed( title="Permission Denied", desc="You do not have permission to clear the queue." )
def blueTeamPick(pickedPlayer: BallChaser, blueCap: BallChaser, orangeCap: BallChaser) -> Embed: """ Helper function for the !pick command when blue team is picking. Parameters: pickedPlayer: BallChaser - The player that has been picked. blueCap: BallChaser - The blue team captain. orangeCap: BallChaser - The orange team captain. Returns: discord.Embed - An embedded message to send. """ errorMsg = Queue.pick(pickedPlayer) if (errorMsg == ""): return QueueUpdateEmbed( title="Player Added to Team", desc="π· " + blueCap.name + " π· picked " + pickedPlayer.mention ).add_field(name="\u200b", value="\u200b", inline=False).add_field( name="πΆ " + orangeCap.name + " πΆ please pick 2οΈβ£ players.", value= "Pick a player from the list below by reacting to the numbers.", inline=False).add_field(name="\u200b", value="\u200b", inline=False).add_field( name="Available picks", value=Queue.getQueueList( includeTimes=False, includeLetters=True), inline=False) return ErrorEmbed(title="Player Not in Queue", desc=errorMsg)
def brokenQueue(player: Member) -> Embed: """ Removes the active match that the author is in. Parameters: player: dicord.Member - The author of the message. Returns: dicord.Embed - The embedded message to respond with. """ msg = Leaderboard.brokenQueue(player) if (":white_check_mark:" in msg): return QueueUpdateEmbed( title="Popped Queue Removed", desc="The popped queue has been removed from active matches. You may now re-queue." ).add_field( name="Current Queue 0/6", value="Queue is empty." ) return ErrorEmbed( title="Could Not Remove Queue", desc=msg )
def pick(player: Member, reactionNumber: int) -> Embed: """ Assigns picked players to their respective teams. Parameters: player: discord.Member - The author of the message reactionNumber: int - The picked player by reaction. Returns: dicord.Embed - The embedded message to respond with. """ if (not Queue.queueAlreadyPopped()): return ErrorEmbed( title="Captains Not Set", desc="If queue is full, please react to the \U0001F1E8 or \U0001F1F7" # noqa | regional indicator C / regional indicator R ) blueCap, orangeCap = Queue.captainsPop() blueTeam, orangeTeam = Queue.getTeamList() if (Queue.isPlayerInQueue(player)): if (Queue.validateBluePick(player)): availablePicks = Queue.getAvailablePicks() return blueTeamPick(availablePicks[reactionNumber - 1], blueCap, orangeCap) if (len(blueTeam) == 1): if (not Queue.validateBluePick(player)): return ErrorEmbed( title="Not the Blue Captain", desc="You are not π· BLUE Team Captain π·\n\n" "π· BLUE Team Captain π· is: " + blueCap.mention ).add_field( name="π· " + blueCap.name.split("#")[0] + " π· picks first. \n" "πΆ ORANGE Team Captain πΆ is: " + orangeCap.name.split("#")[0], value="Pick a player from the list below by reacting to the numbers.\n", inline=False ).add_field( name="\u200b", value="\u200b", inline=False ).add_field( name="Available picks", value=Queue.getQueueList(includeTimes=False, includeLetters=True), inline=False ) if (Queue.validateOrangePick(player)): availablePicks = Queue.getAvailablePicks() return orangeTeamPick(availablePicks[reactionNumber - 1], orangeTeam, blueCap, orangeCap) if (len(blueTeam) == 2): if (not Queue.validateOrangePick(player)): return ErrorEmbed( title="Not the Orange Captain", desc="You are not πΆ ORANGE Team Captain πΆ \n\n" "πΆ ORANGE Team Captain πΆ is: " + orangeCap.mention ).add_field( name="πΆ " + orangeCap.name.split("#")[0] + " πΆ picks second. \n" "π· BLUE Team Captain π· is: " + blueCap.name.split("#")[0], value="Pick a player from the list below by reacting to the numbers.\n", inline=False ).add_field( name="\u200b", value="\u200b", inline=False ).add_field( name="Available picks", value=Queue.getQueueList(includeTimes=False, includeLetters=True), inline=False ) else: if (len(blueTeam) == 1): return ErrorEmbed( title="Not in Queue", desc="You are not in the queue!\n", ).add_field( name="π· " + blueCap.name.split("#")[0] + " π· picks first. \n" "πΆ ORANGE Team Captain πΆ is: " + orangeCap.name.split("#")[0], value="Pick a player from the list below by reacting to the numbers.\n", inline=False ).add_field( name="\u200b", value="\u200b", inline=False ).add_field( name="Available picks", value=Queue.getQueueList(includeTimes=False, includeLetters=True), inline=False ) if (len(blueTeam) == 2): return ErrorEmbed( title="Not in Queue", desc="You are not in the queue!\n", ).add_field( name="πΆ " + orangeCap.name.split("#")[0] + " πΆ picks second. \n" "π· BLUE Team Captain π· is: " + blueCap.name.split("#")[0], value="Pick a player from the list below by reacting to the numbers.\n", inline=False ).add_field( name="\u200b", value="\u200b", inline=False ).add_field( name="Available picks", value=Queue.getQueueList(includeTimes=False, includeLetters=True), inline=False )
def leaderboard(author: Member, mentions: str, lbChannelId: int, *arg) -> Embed: """ Shows the leaderboard. Shows top 5 if no one mentioned. Shows player stats if mentioned or used keyword "me". Parameters: author: discord.Member - The author of the message mentions: str - The content in the message. *arg - The rest of the args in the message. Returns: dicord.Embed - The embedded message to respond with. """ playerMentioned: bool = False selfRank: bool = False if (len(arg) > 0): if ("<@!" in arg[0]): split = mentions.split("<@!") player_id = split[1][:-1] if (player_id.isdigit()): playerMentioned = True elif (arg[0] == "me"): selfRank = True blueTeam, orangeTeam = Queue.getTeamList() blueCap, orangeCap = Queue.getCaptains() if (playerMentioned or selfRank): player = player_id if playerMentioned else str(author.id) players_rank = Leaderboard.showLeaderboard(player) member = Leaderboard.getBallChaser(player) if (type(players_rank) == str and member): embed = InfoEmbed( title="Leaderboard Placement for {0}".format(member["Name"].split("#")[0]), desc=players_rank ) edited_embed = CaptainsRandomHelpEmbed(embed, blueTeam, orangeTeam, blueCap, orangeCap) return edited_embed embed = ErrorEmbed( title="No Matches Played", desc="{0} hasn't played any matches and won't show up on the leaderboard.".format(arg[0]) ) edited_embed = CaptainsRandomHelpEmbed(embed, blueTeam, orangeTeam, blueCap, orangeCap) return edited_embed elif (len(arg) == 0 and playerMentioned == False): if (Leaderboard.countLeaderboard() >= 6): viewFullLb = "\nTo see the full leaderboard, visit <#{0}>.".format(lbChannelId) if (lbChannelId != -1) else "" # noqa embed = InfoEmbed( title="UNCC 6 Mans | Top 5", desc=Leaderboard.showLeaderboard(limit=5) + viewFullLb ) edited_embed = CaptainsRandomHelpEmbed(embed, blueTeam, orangeTeam, blueCap, orangeCap) return edited_embed else: embed = ErrorEmbed( title="No Leaderboard!", desc="There are currently no leaderboard statistics!" ) edited_embed = CaptainsRandomHelpEmbed(embed, blueTeam, orangeTeam, blueCap, orangeCap) return edited_embed else: embed = ErrorEmbed( title="Leaderboard Command Help", desc="Mention someone to see their rank, use 'me' to see your rank," " include nothing to see the top 5 on the leaderboard." ) edited_embed = CaptainsRandomHelpEmbed(embed, blueTeam, orangeTeam, blueCap, orangeCap) return edited_embed
def playerQueue(player: Member, *arg, quiet: bool = False) -> List[str or Embed]: """ Adds the author to the Queue for the specified amount of time. Parameters: player: discord.Member - The author of the message. The person being removed from the queue. *arg: tuple - The args passed into the client function. quiet: bool (optional, default is False) - Specifies whether to include @here ping in channel. Returns: dicord.Embed - The embedded message to respond with. """ queue_length = Queue.getQueueLength() try: queueTime = int(arg[0]) if len(arg) > 0 else 60 except ValueError: # if someone doesn't input a number we default to 60 minutes queueTime = 60 # this converts the input to the next highest value of 10 # ex: 14 -> 20, 9 -> 10, -5 -> 10, 3 -> 10 queueTime = int(ceil(queueTime / 10)) * 10 # minimum queue time of 10 minutes and maximum of 60 minutes if (queueTime < 10): queueTime = 10 elif (queueTime > 60): queueTime = 60 if (Queue.queueAlreadyPopped()): return [ErrorEmbed( title="Current Lobby Not Set", desc="Please wait until current lobby has been set.", )] if (Queue.isPlayerInQueue(player) and Queue.getQueueLength() != 6): Queue.resetPlayerQueueTime(player, queueTime) playerList = Queue.getQueueList() return [QueueUpdateEmbed( title="Already in Queue, Queue Time Reset", desc="You're already in the queue, but your queue time has been reset to {0} minutes.".format(queueTime), ).add_field( name="Current Queue (" + str(queue_length) + "/6)", value=playerList )] if (Queue.isPlayerInQueue(player) and Queue.getQueueLength() == 6): Queue.resetPlayerQueueTime(player, queueTime) playerList = Queue.getQueueList() return [QueueUpdateEmbed( title="Already in Queue, Queue Time Reset", desc="You're already in the queue, but your queue time has been reset to {0} minutes.".format(queueTime), ).add_field( name="Queue Popped!", value="**React to the \U0001F1E8 or \U0001F1F7 for captains or random.**\n\n" "**Current Queue (" + str(queue_length) + "/6)**\n" + playerList, inline=False )] if (Leaderboard.getActiveMatch(player) is not None): return [ErrorEmbed( title="Your previous match has not been reported yet.", desc="React to the π· or πΆ to report the match.\n" "One player from each team must report the match.\n" "You will not be able to queue again until the match has been reported!" ).add_field( name="React to the π to broken queue.", value="There must be at least 4οΈβ£ players that want to broken queue.", inline=False )] if(queue_length == 0): Queue.addToQueue(player, queueTime) if (quiet): return [QueueUpdateEmbed( title="Queue has Started :shushing_face:", desc="{0} wants to queue!\n\nQueued for {1} minutes.\n\n" "React to the β to join".format(player.mention, queueTime), )] return ["@here Queue has started!", QueueUpdateEmbed( title="Queue Started", desc="{0} wants to queue!\n\nQueued for {1} minutes.\n\n" "React to the β to join".format(player.mention, queueTime), )] if (queue_length >= 6): playerList = Queue.getQueueList() return [ErrorEmbed( title="Queue Already Full", desc="Queue is already full, please wait until the current queue is set and try again.", ).add_field( name="Queue Popped!", value="React to the \U0001F1E8 or \U0001F1F7 for captains or random.\n", inline=False ).add_field( name="Current Queue " + str(queue_length) + "/6", value=playerList )] if (queue_length == 5): Queue.addToQueue(player, queueTime) playerList = Queue.getQueueList() mentionedPlayerList = Queue.getQueueList(mentionPlayers=True, separator=", ") return [QueueUpdateEmbed( title="Queue Popped!", desc=player.mention + " has been added to the queue for " + str(queueTime) + " minutes.\n\n" "**Queue is now full!** \n\n" "React to the \U0001F1E8 or \U0001F1F7 for captains or random.\n" ).add_field( name="Current Queue " + str(queue_length + 1) + "/6", value=playerList ), "Queue has popped! Get ready!\n" + mentionedPlayerList] Queue.addToQueue(player, queueTime) playerList = Queue.getQueueList() return [QueueUpdateEmbed( title="Player Added to Queue", desc=player.mention + " has been added to the queue for " + str(queueTime) + " minutes." ).add_field( name="Current Queue " + str(queue_length + 1) + "/6", value=playerList )]
def kick(mentions: str, roles: List[Role], *arg) -> Embed: """ Kicks the mentioned player from the queue. Requires Bot Admin role. Parameters: mentions: str - The content of the message. roles: List[discord.Role] - The roles of the author of the message. *arg: - The arguments in the message. Returns: discord.Embed - The embedded message to respond with. """ blueTeam, orangeTeam = Queue.getTeamList() blueCap, orangeCap = Queue.getCaptains() if (len(arg) > 0 and "<@!" in arg[0]): split = mentions.split("<@!") player_id = split[1][:-1] if (player_id.isdigit()): embed = None if (not Queue.isBotAdmin(roles)): embed = ErrorEmbed( title="Permission Denied", desc="You do not have the leg strength to kick other players." ) elif (Queue.queueAlreadyPopped()): embed = ErrorEmbed( title="Queue Already Popped", desc="Can't kick players while picking teams." ) elif (Queue.getQueueLength() == 0): embed = ErrorEmbed( title="Queue is Empty", desc="The queue is empty, what are you doing?" ) elif (not Queue.isPlayerInQueue(player_id)): embed = ErrorEmbed( title="User Not in Queue", desc="To see who is in current queue, type: **!list**" ) else: member = Queue.getPlayerFromQueue(player_id) Queue.removeFromQueue(player_id) embed = AdminEmbed( title="Kicked Player", desc="Removed {0} from the queue".format(member["name"].split("#")[0]) ) edited_embed = CaptainsRandomHelpEmbed(embed, blueTeam, orangeTeam, blueCap, orangeCap) return edited_embed embed = ErrorEmbed( title="Did Not Mention a Player", desc="Please mention a player in the queue to kick." ) edited_embed = CaptainsRandomHelpEmbed(embed, blueTeam, orangeTeam, blueCap, orangeCap) return edited_embed