Exemple #1
0
 def new_coach(name, discord_id):
     coach = Coach.create(str(name), discord_id)
     pack = PackService.new_starter_pack(coach=coach)
     tran = Transaction(pack=pack,
                        price=pack.price,
                        description=PackService.description(pack))
     coach.make_transaction(tran)
     CoachService.award_bonus(coach)
     return coach
Exemple #2
0
    async def adminlist(self, ctx, coach: str):
        """List details of coach"""
        self.is_admin_channel(ctx.channel)
        coaches = Coach.find_all_by_name(coach)
        msg = []

        if not coaches:
            msg.append("No coaches found")

        for coach in coaches:
            for messg in self.coach_collection_msg(coach):
                msg.append(messg)
        await self.send_message(ctx.channel, msg)
        return
Exemple #3
0
async def coach_unique(name, ctx):
    """finds uniq coach by name"""
    coaches = Coach.find_all_by_name(name)
    if not coaches:
        raise ValueError(f"<coach> __{name}__ not found!!!")

    if len(coaches) > 1:
        emsg = f"<coach> __{name}__ not **unique**!!!\n"
        emsg += "Select one: "
        for coach in coaches:
            emsg += coach.name
            emsg += " "
        await ctx.send(emsg)
        return None
    return coaches[0]
Exemple #4
0
    def start_check(tourn):
        if not tourn.discord_channel:
            err = "Discord channel is not defined, please update it in Tournament sheet and run **!admincomp update**!\n"
            return False, err

        if not tourn.admin:
            err = f"Tournament admin is not defined, please update it in Tournament sheet and run **!admincomp update**!\n"
            return False, err

        coaches = Coach.find_all_by_name(tourn.admin)
        if not coaches:
            err = f"Tournament admin {tourn.admin} was not found on the discord server, check name in the Tournament sheet and run **!admincomp update**!\n"
            return False, err

        return True, None
Exemple #5
0
 async def newcoach(self, ctx):
     """Creates new coach account"""
     coach = CoachService.discord_user_to_coach(ctx.author)
     if coach:
         await ctx.send(f"**{ctx.author.mention}** account exists already")
     elif Coach.get_by_discord_id(ctx.author.id, deleted=True):
         await ctx.send(
             f"**{ctx.author.mention}** account is inactive, use the web page to activate it"
         )
     else:
         coach = CoachService.new_coach(ctx.author, ctx.author.id)
         msg = f"**{ctx.author.mention}** account created\n" \
             + f"**Bank:** {coach.account.amount} coins\n" \
             + f"**Rules**: <{RULES_LINK}>"
         await ctx.send(msg)
Exemple #6
0
    def commit(cls, deck):
        """Commit deck and notify admin"""
        deck.commited = True
        deck.phase_done = True
        db.session.commit()
        coach = deck.tournament_signup.coach
        tournament = deck.tournament_signup.tournament
        admins = Coach.find_all_by_name(tournament.admin)
        if len(admins) == 1:
            admin_mention = f'<@{admins[0].disc_id}>'
        elif len(admins) > 1:
            match_admins = [
                admin for admin in admins
                if admin.short_name() == tournament.admin
            ]
            # special scenario where admin is empty string
            if match_admins:
                admin_mention = f'<@{match_admins[0].disc_id}>'
            else:
                admin_mention = "Unknown admin"
        else:
            admin_mention = deck.tournament_signup.tournament.admin

        coach_mention = coach.short_name()

        Notificator("ledger").notify(
            f'{admin_mention} - {coach_mention} submitted ledger for ' +
            f'{tournament.tournament_id}. {tournament.name} - channel {tournament.discord_channel}'
        )

        # check if all ledgers are commited
        deck_states = [
            ts.deck.commited for ts in tournament.tournament_signups
        ]
        if False not in deck_states:
            Notificator("ledger").notify(
                f'{admin_mention} - All ledgers are locked & committed now for '
                + f'{tournament.tournament_id}. {tournament.name} - channel ' +
                f'{tournament.discord_channel}')
            tournament.phase = Tournament.LOCKED_PHASE
            db.session.commit()
        return deck
Exemple #7
0
    def commit(cls, deck):
        deck.commited = True
        db.session.commit()
        coach = deck.tournament_signup.coach
        tournament = deck.tournament_signup.tournament
        admins = Coach.find_all_by_name(tournament.admin)
        if len(admins) == 1:
            admin_mention = f'<@{admins[0].disc_id}>'
        elif len(admins) > 1:
            match_admins = [
                admin for admin in admins
                if admin.short_name() == tournament.admin
            ]
            # special scenario where admin is empty string
            if len(match_admins) > 0:
                admin_mention = f'<@{match_admins[0].disc_id}>'
            else:
                admin_mention = "Unknown admin"
        else:
            admin_mention = deck.tournament_signup.admin

        coach_mention = coach.short_name()

        LedgerNotificationService.notify(
            f'{admin_mention} - {coach_mention} submitted ledger for {tournament.tournament_id}. {tournament.name} - channel {tournament.discord_channel}'
        )

        # check if all ledgers are commited
        deck_states = [
            ts.deck.commited for ts in tournament.tournament_signups
        ]
        if False not in deck_states:
            LedgerNotificationService.notify(
                f'{admin_mention} - All ledgers are locked & committed now for {tournament.tournament_id}. {tournament.name} - channel {tournament.discord_channel}'
            )
            tournament.phase = "locked"
            db.session.commit()
        return deck
Exemple #8
0
from web import db, create_app
from models.data_models import Coach, Account, Transaction, Pack, Card
import imperiumbase as ib
from datetime import datetime

app = create_app()
app.app_context().push()

# for each coach
for coach_data in ib.Coach.all():
    coach = Coach(name=coach_data.name)
    acc = Account(amount=coach_data.account.cash, coach=coach)
    for transaction in coach_data.account.transactions:
        tr = Transaction(confirmed=transaction.confirmed,
                         price=transaction.price)
        tr.date_created = datetime.utcfromtimestamp(transaction.created_at)
        tr.date_confirmed = datetime.utcfromtimestamp(transaction.confirmed_at)
        if isinstance(transaction.comodity, ib.Pack):
            tr.description = transaction.comodity.description()
            p = transaction.comodity
            if hasattr(p, 'team'):
                team = p.team
            else:
                team = None
            pack = Pack(pack_type=p.pack_type, price=p.price, team=team)
            pack.coach = coach
            pack.transaction = tr
            for card in p.cards:
                cc = Card(name=card["Card Name"],
                          description=card["Description"],
                          card_type=card["Type"],
Exemple #9
0
 def discord_user_to_coach(discord_user):
     return Coach.get_by_discord_id(discord_user.id)
Exemple #10
0
"""resets coaches and tournaments in DB"""
from web import db, app
from models.data_models import Coach, Tournament
from services import Notificator, TournamentService, ImperiumSheetService, TournamentError

app.app_context().push()

tournaments = Tournament.query.filter_by(status="OPEN").all()
manual = []
for tournament in tournaments:
    if len(tournament.tournament_signups) == tournament.coach_limit:
        if not tournament.can_auto_start():
            manual.append(tournament)

c = Coach.find_all_by_name('zord')
if manual:
    msg=f"{c[0].mention()}\nFull tournaments:\n"
    for t in manual:
        msg += f"{t.tournament_id}. {t.name}\n"
    Notificator('tournament').notify(msg)