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')))
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})
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')
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 })
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
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.')
def can_create_leagues(self): if self.is_subscribed(): return True if League.where('owner_id', self.id).count() > 3: return False return True
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))
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')
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()
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})
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))
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()
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})
def show(self, Request, View): league = League.find(Request.param('id')) return View('leagues/index', {'league': league})
def __init__(self, request: Request): self.request = request self.league = League.find(request.param('id'))
def show(self): league = League.find(self.request.param('id')) return view('leagues/apps', {'league': league})
def send(self): league = League.find(self.request.param('league')) return IntegrationDiscordDriver().send(self.request, state=league.id, scopes=('webhook.incoming', ))