async def step5(self, ctx, tournament, post_result_message, parameter): """Step 5 (mp links) of the post_result command""" mp_links = [] links = re.split(" |\n", parameter) for link in links: link = osu.get_from_string(link) mp_links.append(link) post_result_message.mp_links = "\n".join(mp_links) await self.update_post_result_setup_message_with_ctx( ctx, post_result_message, 6)
async def post_result_one_liner_( self, ctx, match_id, score_team1, score_team2, best_of, roll_team1, roll_team2, n_warmup, others, ): """Allows referees to post the result of a match""" tournament, bracket = await self.init_post_result(ctx, match_id) mp_links = [] bans = [] tb_bans = [] i = 0 others_kind = others.split("|'|") while i < len(others_kind): for other in others_kind[i].strip().split('"\'"'): other = other.strip() if i == 0: mp_links.append(other) elif i == 1: bans.append(other) else: tb_bans.append(other) i += 1 mp_links = [osu.get_from_string(mp_link) for mp_link in mp_links] bans_team1 = [] bans_team2 = [] if len(bans) % 2 == 0: bans_team1 = bans[: int(len(bans) / 2)] bans_team2 = bans[int(len(bans) / 2) :] tb_bans_team1 = [] tb_bans_team2 = [] if len(tb_bans) % 2 == 0: tb_bans_team1 = tb_bans[: int(len(tb_bans) / 2)] tb_bans_team2 = tb_bans[int(len(tb_bans) / 2) :] post_result_message = PostResultMessage( tournament_id=tournament.id, bracket_id=bracket.id, referee_id=ctx.author.id, step=8, match_id=match_id, score_team1=score_team1, score_team2=score_team2, best_of=best_of, roll_team1=roll_team1, roll_team2=roll_team2, n_warmup=n_warmup, mp_links="\n".join(mp_links), bans_team1="\n".join(bans_team1), bans_team2="\n".join(bans_team2), tb_bans_team1="\n".join(tb_bans_team1), tb_bans_team2="\n".join(tb_bans_team2), ) message = await self.step7_send_message(ctx, tournament, post_result_message) self.bot.session.add(post_result_message) await self.add_reaction_to_setup_message(message)
async def register( self, ctx, osu_link: str, timezone: str = ""): # TODO handle teams + multiples brackets """Registers the player to the tournament.""" tournament = self.get_tournament(ctx.guild.id) if len(tournament.brackets) != 1: await self.send_reply(ctx, ctx.command.name, "not_supported_yet") return bracket = tournament.current_bracket players_spreadsheet = bracket.players_spreadsheet if players_spreadsheet.range_timezone: if not timezone: raise commands.MissingRequiredArgument("timezone") if not re.match(r"(UTC)?[-\+]([0-9]|1[0-4])$", timezone, re.IGNORECASE): raise InvalidTimezone(timezone) timezone = "UTC" + re.sub( r"^UTC", "", timezone, flags=re.IGNORECASE) if players_spreadsheet.range_team_name: await self.send_reply(ctx, ctx.command.name, "not_supported_yet") return await players_spreadsheet.get_spreadsheet() team_info = TeamInfo.get_first_blank_fields(players_spreadsheet) osu_name = osu.get_from_string(osu_link) osu_user = osu.get_user(osu_name) if not osu_user: raise tosurnament.UserNotFound(osu_name) team_info.players[0].value = osu_user.name team_info.discord[0].value = str(ctx.author) team_info.discord_ids[0].value = str(ctx.author.id) team_info.ranks[0].value = str(osu_user.rank) team_info.bws_ranks[0].value = str(osu_user.rank) # TODO team_info.osu_ids[0].value = str(osu_user.id) team_info.pps[0].value = str(int(float(osu_user.pp))) team_info.timezones[0].value = timezone self.add_update_spreadsheet_background_task(players_spreadsheet) roles_to_give = [ tosurnament.get_role(ctx.guild.roles, tournament.player_role_id, "Player") ] roles_to_give.append( tosurnament.get_role(ctx.guild.roles, bracket.role_id, bracket.name)) await ctx.author.add_roles(*filter(None, roles_to_give)) try: await ctx.author.edit(nick=osu_user.name) except (discord.Forbidden, discord.HTTPException): pass await self.send_reply(ctx, ctx.command.name, "success")