Ejemplo n.º 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')))
Ejemplo n.º 2
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
Ejemplo n.º 3
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
     })
Ejemplo n.º 4
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')
Ejemplo n.º 5
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))
Ejemplo n.º 6
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()
Ejemplo n.º 7
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')
Ejemplo n.º 8
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))
Ejemplo n.º 9
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})
Ejemplo n.º 10
0
 def show(self, Request, View):
     league = League.find(Request.param('id'))
     return View('leagues/index', {'league': league})
Ejemplo n.º 11
0
 def send(self):
     league = League.find(self.request.param('league'))
     return IntegrationDiscordDriver().send(self.request,
                                            state=league.id,
                                            scopes=('webhook.incoming', ))
Ejemplo n.º 12
0
    def show(self):
        league = League.find(self.request.param('id'))

        return view('leagues/apps', {'league': league})
Ejemplo n.º 13
0
 def __init__(self, request: Request):
     self.request = request
     self.league = League.find(request.param('id'))