Some TelegramBot tweaks

This commit is contained in:
Eriks Karls 2020-01-16 13:49:24 +02:00
parent 00b87dc832
commit a2cf479135
2 changed files with 27 additions and 25 deletions

View File

@ -1242,11 +1242,11 @@ class EnergyToFight:
class TelegramBot: class TelegramBot:
__initialized = False __initialized: bool = False
__queue: List[str] __queue: List[str]
chat_id = 0 chat_id: int = 0
api_url = "" api_url: str = ""
player_name = "" player_name: str = ""
__thread_stopper: threading.Event __thread_stopper: threading.Event
_last_time: datetime.datetime _last_time: datetime.datetime
_last_full_energy_report: datetime.datetime _last_full_energy_report: datetime.datetime
@ -1257,13 +1257,13 @@ class TelegramBot:
self._threads = [] self._threads = []
self.__queue = [] self.__queue = []
self.__thread_stopper = threading.Event() if stop_event is None else stop_event self.__thread_stopper = threading.Event() if stop_event is None else stop_event
self._last_time = self._last_full_energy_report = utils.now().min self._last_full_energy_report = self._next_time = self._last_time = utils.good_timedelta(utils.now(), datetime.timedelta(hours=1))
@property @property
def __dict__(self): def __dict__(self):
return dict(chat_id=self.chat_id, api_url=self.api_url, player=self.player_name, last_time=self._last_time, return {'chat_id': self.chat_id, 'api_url': self.api_url, 'player': self.player_name,
next_time=self._next_time, queue=self.__queue, initialized=self.__initialized, 'last_time': self._last_time, 'next_time': self._next_time, 'queue': self.__queue,
has_threads=bool(len(self._threads))) 'initialized': self.__initialized, 'has_threads': bool(len(self._threads))}
def do_init(self, chat_id: int, token: str, player_name: str = ""): def do_init(self, chat_id: int, token: str, player_name: str = ""):
self.chat_id = chat_id self.chat_id = chat_id

View File

@ -6,6 +6,7 @@ import sys
import time import time
import traceback import traceback
import unicodedata import unicodedata
from decimal import Decimal
from pathlib import Path from pathlib import Path
from typing import Any, List, Mapping, NoReturn, Optional, Union from typing import Any, List, Mapping, NoReturn, Optional, Union
@ -393,27 +394,28 @@ def slugify(value, allow_unicode=False) -> str:
def calculate_hit(strength: float, rang: int, tp: bool, elite: bool, ne: bool, booster: int = 0, def calculate_hit(strength: float, rang: int, tp: bool, elite: bool, ne: bool, booster: int = 0,
weapon: int = 200) -> float: weapon: int = 200, is_deploy: bool = False) -> Decimal:
base_dmg = 10 * (1 + strength / 400) * (1 + rang / 5) * (1 + weapon / 100) dec = 3 if is_deploy else 0
dmg = int(base_dmg * 10 + 5) // 10 base_str = (1 + Decimal(str(round(strength, 3))) / 400)
base_rnk = (1 + Decimal(str(rang / 5)))
base_wpn = (1 + Decimal(str(weapon / 100)))
dmg = 10 * base_str * base_rnk * base_wpn
booster_multiplier = (100 + booster) / 100 if elite:
booster_dmg = dmg * booster_multiplier dmg = dmg * 11 / 10
dmg = int(booster_dmg * 10 + 5) // 10
elite = 1.1 if elite else 1 if tp and rang >= 70:
elite_dmg = dmg * elite dmg = dmg * (1 + Decimal((rang - 69) / 10))
dmg = int(elite_dmg)
legend = 1 if (not tp or rang < 70) else 1 + (rang - 69) / 10 dmg = dmg * (100 + booster) / 100
legend_dmg = dmg * legend
dmg = int(legend_dmg)
return dmg * (1.1 if ne else 1) if ne:
dmg = dmg * 11 / 10
return round(dmg, dec)
def ground_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patriot: bool = False, def get_ground_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patriot: bool = False,
booster: int = 0, weapon_power: int = 200) -> float: booster: int = 0, weapon_power: int = 200) -> Decimal:
r = requests.get(f"https://www.erepublik.com/en/main/citizen-profile-json/{citizen_id}").json() r = requests.get(f"https://www.erepublik.com/en/main/citizen-profile-json/{citizen_id}").json()
rang = r['military']['militaryData']['ground']['rankNumber'] rang = r['military']['militaryData']['ground']['rankNumber']
strength = r['military']['militaryData']['ground']['strength'] strength = r['military']['militaryData']['ground']['strength']
@ -424,8 +426,8 @@ def ground_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patr
return calculate_hit(strength, rang, true_patriot, elite, natural_enemy, booster, weapon_power) return calculate_hit(strength, rang, true_patriot, elite, natural_enemy, booster, weapon_power)
def air_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patriot: bool = False, booster: int = 0, def get_air_hit_dmg_value(citizen_id: int, natural_enemy: bool = False, true_patriot: bool = False, booster: int = 0,
weapon_power: int = 0) -> float: weapon_power: int = 0) -> Decimal:
r = requests.get(f"https://www.erepublik.com/en/main/citizen-profile-json/{citizen_id}").json() r = requests.get(f"https://www.erepublik.com/en/main/citizen-profile-json/{citizen_id}").json()
rang = r['military']['militaryData']['aircraft']['rankNumber'] rang = r['military']['militaryData']['aircraft']['rankNumber']
elite = r['citizenAttributes']['level'] > 100 elite = r['citizenAttributes']['level'] > 100