예제 #1
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #2
0
파일: btdata.py 프로젝트: bshishov/ggbot
 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
예제 #3
0
파일: btree.py 프로젝트: bshishov/ggbot
 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
예제 #4
0
파일: btdata.py 프로젝트: bshishov/ggbot
 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
예제 #5
0
파일: component.py 프로젝트: bshishov/ggbot
 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
예제 #6
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #7
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #8
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #9
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #10
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #11
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #12
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #13
0
파일: igdb.py 프로젝트: bshishov/ggbot
    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)
예제 #14
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #15
0
파일: component.py 프로젝트: bshishov/ggbot
    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
예제 #16
0
파일: btdata.py 프로젝트: bshishov/ggbot
 def evaluate(self, context: Context) -> str:
     return context.render_template(self.template,
                                    resolve_emoji=self.resolve_emoji)
예제 #17
0
파일: btree.py 프로젝트: bshishov/ggbot
 async def _fn(ctx: Context):
     print(ctx.render_template(value))
     return True
예제 #18
0
파일: btree.py 프로젝트: bshishov/ggbot
 async def _fn(ctx: Context):
     value = input('> ').strip()
     if value:
         ctx.local[to] = value
         return True
     return False
예제 #19
0
파일: btree.py 프로젝트: bshishov/ggbot
 async def _fn(ctx: Context):
     ctx.local[var] = ctx.render_template(value)
     return True
예제 #20
0
파일: btree.py 프로젝트: bshishov/ggbot
 async def _fn(ctx: Context):
     return bool(ctx.render_template(condition))
예제 #21
0
파일: btdata.py 프로젝트: bshishov/ggbot
 async def _fn(context: Context):
     result = value.evaluate(context)
     if result is None:
         return False
     context.set_variable(var, result)
     return True