async def __call__(self, context: Context) -> bool: match_id = self.match_id.evaluate(context) job = await self.api.request_match_parse(match_id) if self.result_job_id is not None: context.set_variable(self.result_job_id, job.job.jobId) return True
def evaluate(self, context: Context) -> List[TResult]: result = [] for k, v in self.collection.evaluate(context).items(): context.set_variable(self.key, k) # VIOLATES PURE FUNCTIONS! context.set_variable(self.value, v) # VIOLATES PURE FUNCTIONS! result.append(self.fn.evaluate(context)) return result
async def _fn(ctx: Context): m = ctx.get_var_value(var) v_key = key.evaluate(ctx) v_value = value.evaluate(ctx) m[v_key] = v_value ctx.set_variable(var, m) return True
def evaluate(self, context: Context) -> List[T]: result = [] for item in self.collection.evaluate(context): context.set_variable(self.x, item) # VIOLATES PURE FUNCTIONS! if self.fn.evaluate(context): result.append(item) return result
async def __call__(self, context: Context) -> bool: steam_id = self.steam_id.evaluate(context) rankings = await self.api.get_player_rankings(steam_id) rankings = sorted(rankings, key=lambda ranking: ranking.percent_rank, reverse=False) context.set_variable(self.result, rankings[:self.limit]) return True
async def __call__(self, context: Context) -> bool: match_id = self.match_id.evaluate(context) if not match_id: return False match = await self.api.get_match( match_id, cache_lifetime=self.use_cached_if_younger_than) context.set_variable(self.result, match) return True
async def __call__(self, context: Context) -> bool: player = self.match_player.evaluate(context) hero_name = self.dota.hero_id_to_localized_name(player.hero_id) match_data = spec.dump(player) # backwards compatibility phrase = self.phrase_generator.generate_phrase( match=match_data, player_name=context.author.member.display_name, hero_name=hero_name) context.set_variable(self.result, phrase) return True
async def __call__(self, context: Context) -> bool: steam_id = self.steam_id.evaluate(context) if not steam_id: return False matches = await self.api.get_player_recent_matches(steam_id) if not matches: return False last_match = matches[0] context.set_variable(self.result, last_match.match_id) return True
async def _fn(context: Context): steam_id = _parse_steam_id(str(context.message.content)) if not steam_id: return False try: steam_id = int(steam_id) except ValueError: return False context.set_variable(target_variable, steam_id) return True
async def __call__(self, context: Context) -> bool: hero_id = self.hero_id.evaluate(context) result = await self.api.get_hero_matchups(hero_id) total_games_played = 0 for matchup in result: total_games_played += matchup.games_played avg_games_played = total_games_played / len(result) result = (x for x in result if x.games_played >= avg_games_played) result = list(sorted(result, key=_win_rate, reverse=True))[:self.limit] context.set_variable(self.result, result) return True
async def __call__(self, context: Context) -> bool: steam_id = self.steam_id.evaluate(context) match = self.match.evaluate(context) player = find_player_by_steam_id(match, steam_id) if not player: # No player in that match return False medals = [] for medal in PLAYER_MEDALS: if medal.predicate.check(match, player): medals.append(medal) context.set_variable(self.result, medals) return True
async def __call__(self, context: Context) -> bool: match_id = self.match_id.evaluate(context) medal_matches = self.player_medal_matches.evaluate(context) if match_id in medal_matches: # Medal was already assigned return False match_medals = self.match_medals.evaluate(context) player_medals = self.player_medals.evaluate(context) for medal in match_medals: player_medals[medal.id] = player_medals.get(medal.id, 0) + 1 medal_matches.append(match_id) context.set_variable(self.player_medal_matches, medal_matches) context.set_variable(self.player_medals, player_medals) return True
async def action_igdb_query(self, context: Context, query: str, endpoint: str = 'games', success=None, fail=None): if not query: await execute_action(context, fail) return query = context.render_template(query) results = await self.query(endpoint=endpoint, query=query) if not results: await execute_action(context, fail) return context.local['results'] = results await execute_action(context, success)
async def __call__(self, context: Context) -> bool: result = context.local['result'] total_games_played = 0 for item in result: item['winrate'] = item['wins'] / item['games_played'] total_games_played += item['games_played'] avg_games_played = total_games_played / len(result) result = (x for x in result if x['games_played'] >= avg_games_played) result = list(sorted(result, key=lambda x: x['winrate'], reverse=True)) context.local['result'] = result return True
async def __call__(self, context: Context) -> bool: query = self.query.evaluate(context) async with aiohttp.ClientSession() as session: response = await session.get(f'{OPENDOTA_API_URL}{query}', params={ 'api_key': self.api_key, }) result = await response.json() _logger.debug( f'Received data url={response.url} response={result}') context.local['result'] = result if response.status == 200: return True return False
def evaluate(self, context: Context) -> str: return context.render_template(self.template, resolve_emoji=self.resolve_emoji)
async def _fn(ctx: Context): print(ctx.render_template(value)) return True
async def _fn(ctx: Context): value = input('> ').strip() if value: ctx.local[to] = value return True return False
async def _fn(ctx: Context): ctx.local[var] = ctx.render_template(value) return True
async def _fn(ctx: Context): return bool(ctx.render_template(condition))
async def _fn(context: Context): result = value.evaluate(context) if result is None: return False context.set_variable(var, result) return True