def should_run(self, results: Dict[str, bool], user: Union[LoLUser, None] = None) -> bool: """""" if get_stat("winner")["user"]: # user won game, cant have inted return False deaths = get_stat("deaths") return (deaths["max_deaths_to_champ"]["deaths"] >= deaths["total_deaths"] / 2 and deaths["has_max_deaths"])
def should_run(self, results: Dict[str, bool], user: Union[LoLUser, None] = None) -> bool: if get_stat("winner")["user"]: return False if results["hard_inted"]: # dont run if hard inted ran return False kills = get_stat("kills") deaths = get_stat("deaths") return kills["solo_kills"] < deaths["solo_deaths"]
def run(self, results: Dict[str, bool], user: Union[LoLUser, None] = None): deaths = get_stat("deaths") champions = get_stat("champions") message = f"well well well, dinner has been served because <@{user.discord_id}> fed the absolute shit out of {champions[deaths['max_deaths_to_champ']['champ_id']]} giving them " # if max_solo_deaths_to_champ == solo_deaths: if deaths["max_deaths_to_champ"]["deaths"] == deaths["solo_deaths"]: message += f"all {deaths['max_deaths_to_champ']['deaths']} of their solo deaths" else: # message += f"{max_solo_deaths_to_champ} / {solo_deaths} of their solo deaths" message += f"{deaths['max_deaths_to_champ']['deaths']} / {deaths['solo_deaths']} of their solo deaths" send_discord_message(message, False)
def should_run(self, results: Dict[str, bool], user: Union[LoLUser, None] = None) -> bool: if get_stat("winner")["user"]: return False if results["hard_inted"] or results["inted"]: return False kills = get_stat("kills") deaths = get_stat("deaths") # should be true if 'inted' was false, just a double check :^) return kills["solo_kills"] >= deaths["solo_deaths"]
def process( self, data: Dict[str, Any], timeline: Dict[str, Any], account_id: str, ) -> Any: participant_id = get_stat("participant_ids")[account_id] result = { "total_deaths": 0, "solo_deaths": 0, "data": {}, "has_max_deaths": True, "max_deaths_to_champ": { "champ_id": 0, "deaths": 0 }, } td, sd, d = self._process_timeline(timeline, participant_id) result["total_deaths"] = td result["solo_deaths"] = sd result["data"] = d hmd = self._process_max_deaths(data, result["total_deaths"]) result["has_max_deaths"] = hmd msd, c = self._process_participants(result["data"]) result["max_deaths_to_champ"]["champ_id"] = c result["max_deaths_to_champ"]["deaths"] = msd return result
def _game_end_hook(user: Optional[LoLUser]): """ hook run after game_end rule """ match_end = get_stat("match_end") if user is not None: if match_end > user.last_updated: update_lol_user_last_updated(user, match_end)
def run(self, results: Dict[str, bool], user: Union[LoLUser, None] = None): kills = get_stat("kills") deaths = get_stat("deaths") champions = get_stat("champions") user_participant_id = get_stat("participant_ids")["user"] prefixes: List[LoLText] = get_lol_text_by_group("p0") stat_prefixes_01: List[LoLText] = get_lol_text_by_group("sp0") suffixes: List[LoLText] = get_lol_text_by_group("s0") prefix_index: int = random.randint(0, len(prefixes) - 1) stat_prefix_01_index: int = random.randint(0, len(stat_prefixes_01) - 1) suffix_index: int = random.randint(0, len(suffixes) - 1) send_discord_message( f"{prefixes[prefix_index].content} <@{user.discord_id}> {stat_prefixes_01[stat_prefix_01_index].content} {deaths['solo_deaths']} solo deaths and only {kills['solo_kills']} solo kills as {champions[user_participant_id]} in their latest defeat in league of legends. {suffixes[suffix_index].content}", False, )
def process( self, data: Dict[str, Any], timeline: Dict[str, Any], account_id: str, ) -> Any: for participant in data["participants"]: if (participant["participantId"] == get_stat("participant_ids") [account_id]): return participant["teamId"] return None
def process( self, data: Dict[str, Any], timeline: Dict[str, Any], account_id: str, ) -> Any: participant_id = get_stat("participant_ids")[account_id] result = 0 for participant in data["participants"]: if participant["participantId"] == participant_id: result = ( participant["stats"]["kills"] + participant["stats"]["assists"] ) return result
def process( self, data: Dict[str, Any], timeline: Dict[str, Any], account_id: str, ) -> Any: participant_id = get_stat("participant_ids")[account_id] result = {} # compute winning team for team in data["teams"]: if team["win"] == "Win": result["team"] = team["teamId"] for participant in data["participants"]: if participant["participantId"] == participant_id: result["user"] = participant["teamId"] == result["team"] return result
def process( self, data: Dict[str, Any], timeline: Dict[str, Any], account_id: str, ) -> Any: participant_id = get_stat("participant_ids")[account_id] result: Any = {"total_kills": 0, "solo_kills": 0, "data": {}} for frame in timeline["frames"]: for event in frame["events"]: if event["type"] == "CHAMPION_KILL": if event["killerId"] == participant_id: result["total_kills"] += 1 if len(event["assistingParticipantIds"]) == 0: result["solo_kills"] += 1 # handle kill data (used for feeding detection) if event["victimId"] in result["data"]: result["data"][event["victimId"]] += 1 else: result["data"][event["victimId"]] = 1 return result
def run(self, results: Dict[str, bool], user: Union[LoLUser, None]): if not get_stat("winner")["user"]: update_lol_user_winrate(user, GameResult.LOSS) else: update_lol_user_winrate(user, GameResult.WIN)
def _process_max_deaths(self, data, total_deaths): for participant in data["participants"]: if participant["teamId"] == get_stat("team"): if participant["stats"]["deaths"] > total_deaths: return False return True
def run(self, results: Dict[str, bool], user: Union[LoLUser, None]): if user is None: return did_win: bool = get_stat("winner")["user"] player_points = Casino.calculate_player_points( get_stat("takedowns"), did_win, GameMode.UNDEFINED ) betters = get_betters_on(user) if len(betters) == 0: logger.info("0 bets placed") add_lol_user_points(user, int(player_points)) return better_points: List[int] = [] for better in betters: if better.created > get_stat("match_start"): # exclude bets placed after game started continue better_points.append( Casino.calculate_better_points( better.amount, did_win, better.prediction, GameMode.UNDEFINED, ) ) player_bonus = Casino.calculate_player_bonus( player_points, sum(better_points) ) add_lol_user_points(user, int(player_bonus + player_points)) player_result_message = f"<@{user.discord_id}> won {int(player_bonus + player_points)} points" betting_results_message = "" for better in betters: if better.created > get_stat("match_start"): # exclude bets placed after game started continue better_user = get_lol_user_by_discord_id(better.better) if better_user is None: continue better_point = Casino.calculate_better_points( better.amount, did_win, better.prediction, GameMode.UNDEFINED ) better_bonus = Casino.calculate_better_bonus( player_points, better_point ) add_lol_user_points(better_user, int(better_bonus + better_point)) betting_results_message += f'<@{better.better}> {"won" if better.prediction == did_win else "lost"} their bet of {better.amount} and won a total of {int(better_bonus + better_point)}\n' remove_bet(better) send_discord_message( f"<@{user.discord_id}> {'won' if did_win else 'lost'} their game of League which means that \n{betting_results_message}\n and finally\n {player_result_message}" ) remove_lol_game(get_stat("game_id"), user.discord_id)