def tournament_close(tournament_id): """Close tournaments and award prizes""" try: tourn = Tournament.query.get(tournament_id) coach = current_coach() #prizes for prize in request.get_json(): tmp_coach = Coach.query.options(raiseload(Coach.cards), raiseload(Coach.packs)).get( prize['coach']) reason = prize['reason'] + " by " + coach.short_name() TransactionService.process(tmp_coach, int(prize['amount']) * -1, reason) TournamentService.close_tournament(tourn) result = tournament_schema.dump(tourn) return jsonify(result.data) except (RegistrationError, TransactionError) as exc: raise InvalidUsage(str(exc), status_code=403)
async def admincomp(self, ctx, action: str, tournamnent_id: int = None): """Manipulate tournaments USAGE: !admincomp <action> [tournament_id] start: Notifies all registered coaches that tournament started in the tournament channel and links the ledger stop: Resigns all coaches from the tournament update: Updates data from Tournament sheet special_play: Initiates special play phase inducement: Initiates inducement phase blood_bowl: Initiates blood bowl phase <tournament_id>: id of tournament from Tournament master sheet """ self.is_admin_channel(ctx.channel) if action not in [ "start", "stop", "update", Tournament.SP_PHASE, Tournament.IND_PHASE, Tournament.BB_PHASE ]: raise ValueError("Incorrect arguments!!!") if action in [ "start", "stop", Tournament.SP_PHASE, Tournament.IND_PHASE, Tournament.BB_PHASE ]: if not tournamnent_id: raise ValueError("Incorrect arguments!!!") tourn = Tournament.query.filter_by( tournament_id=tournamnent_id).one_or_none() if not tourn: raise ValueError(f"Incorrect tournament **id** specified") if action == "update": await ctx.send("Updating...") TournamentService.update() await ctx.send("Tournaments updated!!!") if action == "stop": TournamentService.close_tournament(tourn) await ctx.send(f"Coaches have been resigned from {tourn.name}!!!") return if action in [ "start", Tournament.SP_PHASE, Tournament.IND_PHASE, Tournament.BB_PHASE ]: result, err = TournamentService.start_check(tourn) if err: raise Exception(err) channel = discord.utils.get(ctx.bot.get_all_channels(), name=tourn.discord_channel.lower()) if not channel: await ctx.send( f"Discord channel {tourn.discord_channel.lower()} does not exists, please create it and rerun this command!" ) return admin = discord.utils.get(ctx.guild.members, name=tourn.admin) if not admin: await ctx.send( f"Tournament admin {tourn.admin} was not found on the discord server, check name in the Tournament sheet and run **!admincomp update**!" ) return if action == "start": TournamentService.reset_phase(tourn) TournamentService.set_status(tourn, status="RUNNING") db.session.commit() TournamentService.release_reserves(tourn) submit_deck_channel = discord.utils.get( ctx.bot.get_all_channels(), name='submit-a-deck') members = [ discord.utils.get(ctx.guild.members, id=coach.disc_id) for coach in tourn.coaches.filter( TournamentSignups.mode == "active") ] msg = [member.mention for member in members if member] msg.append( f"This will be scheduling channel for your {tourn.name}") if submit_deck_channel: msg.append( f"Please submit decks as instructed in {submit_deck_channel.mention}" ) msg.append(f"We start on {tourn.expected_start_date}!") msg.append(f"Deadline is on {tourn.deadline_date}") msg.append(f"Your tournament admin is {admin.mention}") msg.append( f"**Deck Size/Deck Target Value/Deck Max Value**: {tourn.deck_limit}/{tourn.deck_value_target}/{tourn.deck_value_limit}" ) msg.append(f"**Conclave Ranges**:") msg.append( f"\t**3 Blessing Points:**\t\t {tourn.conclave_ranges().blessing3.start}-{tourn.conclave_ranges().blessing3.stop}" ) msg.append( f"\t**2 Blessing Points:**\t\t {tourn.conclave_ranges().blessing2.start}-{tourn.conclave_ranges().blessing2.stop}" ) msg.append( f"\t**1 Blessing Point:** \t\t {tourn.conclave_ranges().blessing1.start}-{tourn.conclave_ranges().blessing1.stop}" ) msg.append( f"\t**Conclave equilibrium:** {tourn.deck_value_target}") msg.append( f"\t**1 Curse Point:**\t\t\t\t {tourn.conclave_ranges().curse1.start}-{tourn.conclave_ranges().curse1.stop}" ) msg.append( f"\t**2 Curse Points:**\t\t\t {tourn.conclave_ranges().curse2.start}-{tourn.conclave_ranges().curse2.stop}" ) msg.append( f"\t**3 Curse Points:**\t\t\t {tourn.conclave_ranges().curse3.start}-{tourn.conclave_ranges().curse3.stop}" ) msg.append(f"**Tournament Sponsor:** {tourn.sponsor}") msg.append(f"{tourn.sponsor_description}") msg.append(f"**Special Rules:**") msg.append(f"{tourn.special_rules}") msg.append(f"**Banned Cards:**") msg.append(', '.join(tourn.banned_cards.split(';'))) msg.append(f"**Prizes:**") msg.append(f"{tourn.prizes}") msg.append(f"**Unique Prize:**") msg.append(f"{tourn.unique_prize}") #room setup if tourn.is_development(): msg.append(f"**In-game rooms:**") try: CompetitionService.import_competitions() comp = Competition.query.filter_by( name=tourn.ladder_room_name()).one_or_none() if not comp: comp = CompetitionService.create_imperium_ladder( tourn.ladder_room_name()) comp.tournament_id = tourn.id db.session.commit() for comp in tourn.competitions: msg.append( f"**{comp.name}** in **{comp.league_name}** league" ) except BB2APINotAvailable: msg.append( "Cyanide API is not available, in-game room was not created!" ) if action == Tournament.SP_PHASE: msg = TournamentService.special_play_msg(tourn) if action == Tournament.IND_PHASE: msg = TournamentService.inducement_msg(tourn) if action == Tournament.BB_PHASE: msg = TournamentService.blood_bowl_msg(tourn) await self.send_message(channel, msg) await ctx.send("Done.") return