Exemple #1
0
    def get(self):
        response = IntegrationDiscordDriver().user(self.request)

        league = League.find(self.request.input('state'))
        discord = Discord.where('league_id', league.id).first()

        if not discord:
            Discord.create(
                access_token=response['access_token'],
                refresh_token=response['refresh_token'],
                scopes=response['scope'],
                expires_at=pendulum.now().add(
                    seconds=response['expires_in']).to_datetime_string(),
                league_id=self.request.input('state'),
                channel_id=response['webhook']['id'],
                token=response['webhook']['token'])
        else:
            discord.access_token = response['access_token']
            discord.refresh_token = response['refresh_token']
            discord.scopes = response['scope']
            discord.expires_at = pendulum.now().add(
                seconds=response['expires_in']).to_datetime_string()
            discord.channel_id = response['webhook']['id']
            discord.token = response['webhook']['token']
            discord.save()

        league = League.find(self.request.input('state'))
        league.broadcast('Successfully integrated Discord with GBALeague.com')

        return self.request.redirect(
            'http://localhost:8000/league/{0}/apps'.format(
                self.request.input('state')))
Exemple #2
0
    def discover(self) -> View.render:
        """Shows the discover page

        Returns:
            View.render
        """

        if self.request.input('search'):
            leagues = League.order_by(
                'id', 'desc').get().filter(lambda league: self.request.input(
                    'search').lower() in league.name.lower())
        else:
            leagues = League.order_by('id', 'desc').get().take(100)

        return self.view.render('discover', {'leagues': leagues})
Exemple #3
0
    def draft(self, Request):
        league = League.find(Request.param('id'))
        
        if Request.has('draft'):
            DraftedPokemon.create(
                team_id=league.current.team(league).id,
                pokemon_id=Request.input('pokemon'),
                league_id=league.id
            )

            DraftedPokemon.where('queue_id', Request.input('pokemon')).where('league_id', league.id).delete()

            return Request.redirect('/league/@id/draft?message=Draft Successful')

        elif Request.has('unqueue'):
            DraftedPokemon \
                .where('queue_id', Request.input('pokemon')) \
                .where('team_id', Request.user() \
                .team(league).id).where('league_id', league.id) \
                .first().delete()

            return Request.redirect('/league/@id/draft?message=Successfully Unqueued')

        elif Request.has('queue'):
            DraftedPokemon.create(
                team_id=league.current.team(league).id,
                queue_id=Request.input('pokemon'),
                league_id=league.id
            )
            return Request.redirect('/league/@id/draft?message=Queue Successful')
Exemple #4
0
 def show(self):
     league = League.find(request().param('id'))
     schedules = Schedule.where('league_id', league.id).get()
     return view('leagues/schedule', {
         'schedules': schedules,
         'league': league
     })
Exemple #5
0
 def __init__(self, league: League, view: View, request: Request):
     self.view = view
     self.request = request
     if request.param('id'):
         self.league = league.find(self.request.param('id'))
     else:
         self.league = None
Exemple #6
0
    def before(self):
        """ Run This Middleware Before The Route Executes """

        if self.request.user():
            if not League.where('owner_id',
                                self.request.user().id).where(
                                    'id', self.request.param('id')).first():
                raise Exception('You are not the league owner.')
Exemple #7
0
    def can_create_leagues(self):
        if self.is_subscribed():
            return True

        if League.where('owner_id', self.id).count() > 3:
            return False

        return True
Exemple #8
0
    def status(self):
        league = League.find(request().param('id'))
        if request().has('draft-open'):
            league.start_draft()
            league.broadcast('The draft has started!')
        elif request().has('draft-close'):
            league.close_draft()
            league.broadcast('The draft is closed!')

        return request().redirect('/league/{0}/draft'.format(league.id))
Exemple #9
0
 def before(self):
     """ Run This Middleware Before The Route Executes """
     if self.request.param('id'):
         try:
             if not League.find(self.request.param('id')):
                 self.request.session.flash('warning',
                                            'That league does not exist')
                 self.request.redirect_to('discover')
         except:
             self.request.session.flash('warning',
                                        'That league no longer exists')
             self.request.redirect_to('discover')
Exemple #10
0
    def remove(self):
        team = Team.find(self.request.input('team'))

        league = League.find(team.league_id)
        if league.current_id == team.owner_id:
            league.skip_user()

        team.league_id = None
        team.save()

        self.request.session.flash('success', 'Successfully Removed Team')
        return self.request.back()
Exemple #11
0
    def store(self):
        league = League.create(
            name=self.request.input('league-name'),
            owner_id=self.request.user().id,
            description=self.request.input('league-overview'),
            slug=slugify(self.request.input('league-name')) + '-' +
            generate_string(4),
            current_id=None,
            draftorder=None,
        )

        return self.request.redirect_to('league.id', {'id': league.id})
Exemple #12
0
    def store(self):
        league = League.find(request().input('league_id'))
        date = pendulum.from_format(request().input('scheduled_time'),
                                    '%m/%d/%Y')

        Schedule.create(
            league_id=league.id,
            team1_id=request().input('team1'),
            team2_id=request().input('team2'),
            scheduled_for=date,
        )

        return request().redirect('/league/{0}/schedule'.format(league.id))
Exemple #13
0
 def get_all_leagues(self):
     league_id_collection = Team.where('owner_id', self.id).where_not_null('league_id').get().pluck('league_id')
     return League.where_in('id', league_id_collection).get()
Exemple #14
0
    def teams(self, Request, View):
        league = League.find(Request.param('id'))
        teams = Team.where('league_id', league.id).get()

        return View('leagues/teams', {'league': league, 'teams': teams})
Exemple #15
0
 def show(self, Request, View):
     league = League.find(Request.param('id'))
     return View('leagues/index', {'league': league})
Exemple #16
0
 def __init__(self, request: Request):
     self.request = request
     self.league = League.find(request.param('id'))
Exemple #17
0
    def show(self):
        league = League.find(self.request.param('id'))

        return view('leagues/apps', {'league': league})
Exemple #18
0
 def send(self):
     league = League.find(self.request.param('league'))
     return IntegrationDiscordDriver().send(self.request,
                                            state=league.id,
                                            scopes=('webhook.incoming', ))