Example #1
0
    async def focus(self, ctx):
        """Reviews your deck and tells what the deck focus is"""
        me = CoachService.discord_user_to_coach(ctx.author)
        tourn = TournamentService.get_tournament_using_room(ctx.channel.name)
        deck = [ts.deck for ts in tourn.tournament_signups if ts.coach == me]
        if not deck:
            raise Exception(
                f"#{me.short_name()} is not signed into the tournament. Nice try!"
            )
        focus = DeckService.focus(deck[0])

        await ctx.send(f"Deck focus is {', '.join(focus)}")
Example #2
0
    async def comp(self, ctx, *args):
        """Manages in-game competitions for tournaments. Needs to be run in the tournament discord channel
      USAGE:
      !comp list
        list all competitions for tournament
      !comp create ladder
        creates ladder comp for tournament if it does not exists
      !comp create 1on1 <competition_name>
        creates 1 on 1 comp with <competition_name> for tournament if it does not exists
      !comp create knockout <team_number> <name>
        creates knockout comp with <name> for <team_number> teams
      !comp ticket <competition_name>
        sends ticket to the <competition_name> to the coach issuing the command in the tournament room
      !comp start <competition_name>
        starts comp with <competition_name> for tournament
      """
        room = ctx.channel.name
        args_len = len(args)
        if args_len == 0 \
            or (args_len > 0 and args[0] not in ["list","create", "ticket", "start"]) \
            or (args[0] == "create" and \
                (args_len < 2 or args[1] not in ["ladder", "1on1","knockout"] or (args[1] == "1on1" and args_len == 2) \
                    or (args[1] == "knockout" and args_len < 4 and not represents_int(args[2])))) \
            or (args[0] in ["ticket", "start"] and args_len < 2):
            raise ValueError("Incorrect arguments")

        tourn = TournamentService.get_tournament_using_room(room)

        if tourn.status != "RUNNING":
            await ctx.send("Tournament is not running!")
            return

        if args[0] == "create":
            if args[1] == "ladder":
                comp_name = tourn.ladder_room_name()
                comp = CompetitionService.create_imperium_ladder(comp_name)
            if args[1] == "1on1":
                comp_name = " ".join(args[2:])
                comp_name = comp_name[:25] if len(
                    comp_name) > 25 else comp_name
                comp = CompetitionService.create_imperium_rr(comp_name)
            if args[1] == "knockout":
                comp_name = " ".join(args[3:])
                comp_name = comp_name[:25] if len(
                    comp_name) > 25 else comp_name
                comp = CompetitionService.create_imperium_knockout(
                    comp_name, int(args[2]))
            tourn.competitions.append(comp)
            db.session.commit()
            await ctx.send(
                f"Competition **{comp.name}** created in **{comp.league_name}**"
            )
            return

        if args[0] == "list":
            msg = []
            msg.append('{:25s} | {:25} | {:25}'.format("League", "Name",
                                                       "Type"))
            msg.append(78 * "-")
            for comp in tourn.competitions:
                msg.append('{:25s} | {:25} | {:25}'.format(
                    comp.league_name, comp.name, comp.type_str()))

            await self.send_message(ctx.channel, msg, block=True)
            # await ctx.send("\n".join(msg))
            return

        if args[0] == "ticket":
            comp_name = " ".join(args[1:])
            # get coach
            coach = CoachService.discord_user_to_coach(ctx.author)
            result = CompetitionService.ticket_competition(
                comp_name, coach, tourn)
            team_name = result['ResponseCreateCompetitionTicket'][
                'TicketInfos']['RowTeam']['Name']
            await ctx.send(
                f"Ticket sent to **{team_name}** for competition **{comp_name}**"
            )
            return

        if args[0] == "start":
            comp_name = " ".join(args[1:])
            comp = Competition.query.filter_by(name=comp_name).one_or_none()
            if not comp:
                raise CompetitionError(
                    f"Competition **{comp_name}** does not exist")
            result = CompetitionService.start_competition(comp)
            await ctx.send(f"Started competition **{comp_name}**")
            return