Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
8445b556e7 | |||
d02c5c2969 | |||
bff4183cb6 | |||
47f5142837 | |||
a32fd039dd | |||
311e684c0c | |||
52038a86d5 | |||
c35a107641 | |||
b53b2f0fae | |||
8da9b6221a | |||
caa41c85f6 | |||
da3b5d5768 | |||
f96d0233f9 | |||
c693a5182e | |||
0dfba6a9ff | |||
ee3eca9658 | |||
0e8680daca | |||
8e3606f1a3 |
@ -36,6 +36,14 @@ erepublik.constants module
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
erepublik.types module
|
||||
----------------------
|
||||
|
||||
.. automodule:: erepublik.types
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
erepublik.utils module
|
||||
----------------------
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
__author__ = """Eriks Karls"""
|
||||
__email__ = 'eriks@72.lv'
|
||||
__version__ = '0.23.4.3'
|
||||
__version__ = '0.23.4.8'
|
||||
|
||||
from erepublik import classes, constants, utils
|
||||
from erepublik.citizen import Citizen
|
||||
|
@ -305,11 +305,11 @@ class ErepublikEconomyAPI(CitizenBaseAPI):
|
||||
return self.post(f"{self.url}/main/buyGoldItems", data=data)
|
||||
|
||||
def _post_economy_activate_booster(self, quality: int, duration: int, kind: str) -> Response:
|
||||
data = dict(type=kind, quality=quality, duration=duration, fromInventory=True)
|
||||
data = dict(type=kind, quality=quality, duration=duration, fromInventory=True, _token=self.token)
|
||||
return self.post(f"{self.url}/economy/activateBooster", data=data)
|
||||
|
||||
def _post_economy_activate_house(self, quality: int) -> Response:
|
||||
data = {"action": "activate", "quality": quality, "type": "house", "_token": self.token}
|
||||
data = dict(action="activate", quality=quality, type="house", _token=self.token)
|
||||
return self.post(f"{self.url}/economy/activateHouse", data=data)
|
||||
|
||||
def _post_economy_donate_items_action(self, citizen_id: int, amount: int, industry: int,
|
||||
|
@ -238,10 +238,7 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
|
||||
def update_inventory(self):
|
||||
"""
|
||||
Updates class properties and returns structured inventory.
|
||||
Return structure: {status: {used: int, total: int}, items: {active/final/raw: {item_token:{quality: data}}}
|
||||
If item kind is damageBoosters or aircraftDamageBoosters then kind is renamed to kind+quality and duration is
|
||||
used as quality.
|
||||
Updates citizen inventory
|
||||
"""
|
||||
self._update_inventory_data(self._get_economy_inventory_items().json())
|
||||
|
||||
@ -291,8 +288,9 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
if item_data.get('attributes').get('expirationInfo'):
|
||||
expire_info = item_data.get('attributes').get('expirationInfo')
|
||||
expiration_info = [_expire_value_to_python(v) for v in expire_info['value']]
|
||||
icon = item_data['icon'] if item_data[
|
||||
'icon'] else "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
||||
if not item_data.get('icon') and item_data.get('isPackBooster'):
|
||||
item_data['icon'] = f"//www.erepublik.com/images/icons/boosters/52px/{item_data.get('type')}.png"
|
||||
icon = item_data['icon'] if item_data['icon'] else "//www.erepublik.net/images/modules/manager/tab_storage.png"
|
||||
inv_item: types.InvFinalItem = dict(
|
||||
name=item_data.get("name"), time_left=item_data['active']['time_left'], icon=icon,
|
||||
kind=kind, expiration=expiration_info, quality=item_data.get("quality", 0)
|
||||
@ -312,7 +310,7 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
|
||||
if item_data.get('type'):
|
||||
# in ['damageBoosters', "aircraftDamageBoosters", 'prestigePointsBoosters']
|
||||
if item_data.get('type').endswith('Boosters'):
|
||||
if item_data.get('isBooster'):
|
||||
is_booster = True
|
||||
kind = item_data['type']
|
||||
|
||||
@ -343,6 +341,9 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
elif q == 15:
|
||||
self.eb_small += amount
|
||||
item_data.update(token='energy_bar')
|
||||
elif q == 16:
|
||||
self.eb_small += amount
|
||||
item_data.update(token='energy_bar')
|
||||
kind = re.sub(r'_q\d\d*', "", item_data.get('token'))
|
||||
|
||||
if item_data.get('token', "") == "house_q100":
|
||||
@ -692,6 +693,10 @@ class BaseCitizen(access_points.CitizenAPI):
|
||||
self.eb_double -= amount
|
||||
elif q == "12":
|
||||
self.eb_small -= amount
|
||||
elif q == "15":
|
||||
self.eb_small -= amount
|
||||
elif q == "16":
|
||||
self.eb_small -= amount
|
||||
next_recovery = r_json.get("food_remaining_reset").split(":")
|
||||
self.energy.set_reference_time(
|
||||
utils.good_timedelta(self.now, timedelta(seconds=int(next_recovery[1]) * 60 + int(next_recovery[2])))
|
||||
@ -1207,7 +1212,7 @@ class CitizenEconomy(CitizenTravel):
|
||||
items = (self.inventory.final if final_kind else self.inventory.raw).get(constants.INDUSTRIES[industry],
|
||||
{_inv_qlt: {'amount': 0}})
|
||||
if items[_inv_qlt]['amount'] < amount:
|
||||
self.get_inventory(True)
|
||||
self.update_inventory()
|
||||
items = (self.inventory.final if final_kind else self.inventory.raw).get(constants.INDUSTRIES[industry],
|
||||
{_inv_qlt: {'amount': 0}})
|
||||
if items[_inv_qlt]['amount'] < amount:
|
||||
@ -1366,7 +1371,7 @@ class CitizenEconomy(CitizenTravel):
|
||||
self.update_money()
|
||||
cur = "g" if currency == 62 else "cc"
|
||||
if success:
|
||||
self._report_action("DONATE_MONEY", f"Successfully donated {amount}{cur} to citizen with id {citizen_id}!")
|
||||
self.report_money_donation(citizen_id, amount, currency == 1)
|
||||
else:
|
||||
self._report_action("DONATE_MONEY", f"Unable to donate {amount}{cur}!")
|
||||
return success
|
||||
@ -1450,6 +1455,16 @@ class CitizenEconomy(CitizenTravel):
|
||||
f" treasury", kwargs=r.json())
|
||||
return False
|
||||
|
||||
def report_money_donation(self, citizen_id: int, amount: float, is_currency: bool = True):
|
||||
self.reporter.report_money_donation(citizen_id, amount, is_currency)
|
||||
if self.config.telegram:
|
||||
self.telegram.report_money_donation(citizen_id, amount, is_currency)
|
||||
|
||||
def report_item_donation(self, citizen_id: int, amount: float, quality: int, industry: str):
|
||||
self.reporter.report_item_donation(citizen_id, amount, quality, industry)
|
||||
if self.config.telegram:
|
||||
self.telegram.report_item_donation(citizen_id, amount, f"{industry} q{quality}")
|
||||
|
||||
|
||||
class CitizenLeaderBoard(BaseCitizen):
|
||||
def get_aircraft_damage_rankings(self, country: int, weeks: int = 0, mu: int = 0) -> Dict[str, any]:
|
||||
@ -1775,7 +1790,8 @@ class CitizenMilitary(CitizenTravel):
|
||||
yield battle, battle_zone, side
|
||||
|
||||
def find_battle_and_fight(self):
|
||||
if self.should_fight()[0]:
|
||||
count = self.should_fight()[0]
|
||||
if count:
|
||||
self.write_log("Checking for battles to fight in...")
|
||||
for battle, division, side in self.find_battle_to_fight():
|
||||
|
||||
@ -1802,25 +1818,27 @@ class CitizenMilitary(CitizenTravel):
|
||||
|
||||
if self.change_division(battle, division):
|
||||
self.set_default_weapon(battle, division)
|
||||
self.fight(battle, division, side)
|
||||
self.fight(battle, division, side, count)
|
||||
self.travel_to_residence()
|
||||
break
|
||||
|
||||
@utils.wait_for_lock
|
||||
def fight(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide = None,
|
||||
count: int = None) -> Optional[int]:
|
||||
count: int = None, use_ebs: bool = False) -> Optional[int]:
|
||||
"""Fight in a battle.
|
||||
|
||||
Will auto activate booster and travel if allowed to do it.
|
||||
:param battle: Battle battle to fight in
|
||||
:type battle: Battle
|
||||
:param division: Division number to fight in available choices
|
||||
:type division: BattleDivision
|
||||
:param side: BattleSide or None. Battle side to fight in, If side not == invader id or not in invader deployed
|
||||
allies list, then defender's side is chosen
|
||||
:type side: BattleSide
|
||||
:param count: How many hits to do, if not specified self.should_fight() is called.
|
||||
:type count: int
|
||||
:param division: Division number to fight in available choices
|
||||
:type division: BattleDivision
|
||||
:param use_ebs: Should use energy bars if count > 0 and not enough food_fights
|
||||
:type use_ebs: bool
|
||||
:return: None if no errors while fighting, otherwise error count.
|
||||
:rtype: int
|
||||
"""
|
||||
@ -1850,15 +1868,13 @@ class CitizenMilitary(CitizenTravel):
|
||||
error_count += error
|
||||
else:
|
||||
self._eat('blue')
|
||||
if count > 0 and self.energy.recovered < 50 and use_ebs:
|
||||
self._eat('orange')
|
||||
if self.energy.recovered < 50 or error_count >= 10 or count <= 0:
|
||||
self.write_log(f"Hits: {total_hits:>4} | Damage: {total_damage}")
|
||||
ok_to_fight = False
|
||||
if total_damage:
|
||||
self.reporter.report_fighting(battle, not side.is_defender, division, total_damage, total_hits)
|
||||
# self.reporter.report_action('FIGHT', dict(battle_id=battle.id, side=side, dmg=total_damage,
|
||||
# air=battle.has_air, hits=total_hits,
|
||||
# round=battle.zone_id,
|
||||
# extra=dict(battle=battle, side=side)))
|
||||
self.report_fighting(battle, not side.is_defender, division, total_damage, total_hits)
|
||||
return error_count
|
||||
|
||||
def _shoot(self, battle: classes.Battle, division: classes.BattleDivision, side: classes.BattleSide):
|
||||
@ -2020,7 +2036,7 @@ class CitizenMilitary(CitizenTravel):
|
||||
|
||||
return utils.calculate_hit(0, rang, True, elite, ne, 0, 20 if weapon else 0)
|
||||
|
||||
def activate_damage_booster(self, ground: bool = True):
|
||||
def activate_damage_booster(self, ground: bool = True) -> int:
|
||||
kind = 'damageBoosters' if ground else 'aircraftDamageBoosters'
|
||||
if self.config.boosters and not self.get_active_damage_booster(ground):
|
||||
booster: Optional[types.InvFinalItem] = None
|
||||
@ -2032,9 +2048,11 @@ class CitizenMilitary(CitizenTravel):
|
||||
break
|
||||
break
|
||||
if booster:
|
||||
kind = 'damage' if ground else 'air_damage'
|
||||
self._report_action("MILITARY_BOOSTER", f"Activated {booster['name']}")
|
||||
self._post_economy_activate_booster(booster['quality'], booster['durability'],
|
||||
'damage' if ground else 'air_damage')
|
||||
resp = self._post_economy_activate_booster(booster['quality'], booster['durability'], kind).json()
|
||||
self._update_inventory_data(resp)
|
||||
return self.get_active_damage_booster(ground)
|
||||
|
||||
def get_active_damage_booster(self, ground: bool = True) -> int:
|
||||
kind = 'damageBoosters' if ground else 'aircraftDamageBoosters'
|
||||
@ -2051,13 +2069,16 @@ class CitizenMilitary(CitizenTravel):
|
||||
def get_active_air_damage_booster(self) -> int:
|
||||
return self.get_active_damage_booster(False)
|
||||
|
||||
def activate_battle_effect(self, battle_id: int, kind: str) -> Response:
|
||||
def activate_battle_effect(self, battle_id: int, kind: str) -> bool:
|
||||
self._report_action('MILITARY_BOOSTER', f'Activated {kind} booster')
|
||||
return self._post_main_activate_battle_effect(battle_id, kind, self.details.citizen_id)
|
||||
resp = self._post_main_activate_battle_effect(battle_id, kind, self.details.citizen_id).json()
|
||||
return not resp.get('error')
|
||||
|
||||
def activate_pp_booster(self, pp_item: types.InvFinalItem) -> Response:
|
||||
def activate_pp_booster(self, pp_item: types.InvFinalItem) -> bool:
|
||||
self._report_action('MILITARY_BOOSTER', f'Activated {pp_item["name"]}')
|
||||
return self._post_economy_activate_booster(pp_item['quality'], pp_item['durability'], 'prestige_points')
|
||||
resp = self._post_economy_activate_booster(pp_item['quality'], pp_item['durability'], 'prestige_points').json()
|
||||
self._update_inventory_data(resp)
|
||||
return pp_item.get('kind') in self.inventory.active
|
||||
|
||||
def _rw_choose_side(self, battle: classes.Battle, side: classes.BattleSide) -> Response:
|
||||
return self._post_main_battlefield_travel(side.id, battle.id)
|
||||
@ -2218,6 +2239,11 @@ class CitizenMilitary(CitizenTravel):
|
||||
if division.wall['dom'] == 50 or division.wall['dom'] > 98:
|
||||
yield division, division.wall['for'] == battle.invader.country.id
|
||||
|
||||
def report_fighting(self, battle: classes.Battle, invader: bool, division: classes.BattleDivision, damage: float, hits: int):
|
||||
self.reporter.report_fighting(battle, invader, division, damage, hits)
|
||||
if self.config.telegram:
|
||||
self.telegram.report_fight(battle, invader, division, damage, hits)
|
||||
|
||||
|
||||
class CitizenPolitics(BaseCitizen):
|
||||
def get_country_parties(self, country: constants.Country = None) -> dict:
|
||||
@ -2674,10 +2700,12 @@ class Citizen(CitizenAnniversary, CitizenCompanies, CitizenLeaderBoard,
|
||||
else:
|
||||
start_time = utils.good_timedelta(start_time.replace(minute=0), timedelta(hours=1))
|
||||
while not self.stop_threads.is_set():
|
||||
self.update_citizen_info()
|
||||
start_time = utils.good_timedelta(start_time, timedelta(minutes=30))
|
||||
self.update_citizen_info()
|
||||
self.update_weekly_challenge()
|
||||
self.send_state_update()
|
||||
self.send_inventory_update()
|
||||
self.update_companies()
|
||||
self.send_my_companies_update()
|
||||
sleep_seconds = (start_time - self.now).total_seconds()
|
||||
self.stop_threads.wait(sleep_seconds if sleep_seconds > 0 else 0)
|
||||
|
@ -650,6 +650,16 @@ class Reporter:
|
||||
air=battle.has_air, hits=hits,
|
||||
round=battle.zone_id, extra=dict(battle=battle, side=side, division=division)))
|
||||
|
||||
def report_money_donation(self, citizen_id: int, amount: float, is_currency: bool = True):
|
||||
cur = 'cc' if is_currency else 'gold'
|
||||
self.report_action('DONATE_MONEY', dict(citizen_id=citizen_id, amount=amount, currency=cur),
|
||||
f"Successfully donated {amount}{cur} to citizen with id {citizen_id}!")
|
||||
|
||||
def report_item_donation(self, citizen_id: int, amount: float, quality: int, industry: str):
|
||||
self.report_action('DONATE_ITEMS',
|
||||
dict(citizen_id=citizen_id, amount=amount, quality=quality, industry=industry),
|
||||
f"Successfully donated {amount} x {industry} q{quality} to citizen with id {citizen_id}!")
|
||||
|
||||
def report_promo(self, kind: str, time_until: datetime.datetime):
|
||||
self._req.post(f"{self.url}/promos/add/", data=dict(kind=kind, time_untill=time_until))
|
||||
|
||||
@ -974,7 +984,7 @@ class TelegramReporter:
|
||||
self._last_time = utils.good_timedelta(utils.now(), datetime.timedelta(minutes=-5))
|
||||
self._last_full_energy_report = utils.good_timedelta(utils.now(), datetime.timedelta(minutes=-30))
|
||||
if self.__queue:
|
||||
self.send_message("\n\n––––––––––––––––––––––\n\n".join(self.__queue))
|
||||
self.send_message("Telegram initialized")
|
||||
|
||||
def send_message(self, message: str) -> bool:
|
||||
self.__queue.append(message)
|
||||
@ -1002,15 +1012,29 @@ class TelegramReporter:
|
||||
new_line = '\n' if multiple else ''
|
||||
self.send_message(f"New award: {new_line}*{msg}*")
|
||||
|
||||
def report_fight(self, battle: "Battle", invader: bool, division: "BattleDivision", damage: float, hits: int):
|
||||
side_txt = (battle.invader if invader else battle.defender).country.iso
|
||||
self.send_message(f"*Fight report*:\n{int(damage):,d} dmg ({hits} hits) in"
|
||||
f" [battle {battle.id} for {battle.region_name[:16]}]({battle.link}) in d{division.div} on "
|
||||
f"{side_txt} side")
|
||||
|
||||
def report_item_donation(self, citizen_id: int, amount: float, product: str):
|
||||
self.send_message(f"*Donation*: {amount} x {product} to citizen "
|
||||
f"[{citizen_id}](https://www.erepublik.com/en/citizen/profile/{citizen_id})")
|
||||
|
||||
def report_money_donation(self, citizen_id: int, amount: float, is_currency: bool = True):
|
||||
self.send_message(f"*Donation*: {amount}{'cc' if is_currency else 'gold'} to citizen "
|
||||
f"[{citizen_id}](https://www.erepublik.com/en/citizen/profile/{citizen_id})")
|
||||
|
||||
def __send_messages(self):
|
||||
while self._next_time > utils.now():
|
||||
if self.__thread_stopper.is_set():
|
||||
break
|
||||
self.__thread_stopper.wait(utils.get_sleep_seconds(self._next_time))
|
||||
|
||||
message = "\n\n––––––––––––––––––––––\n\n".join(self.__queue)
|
||||
message = "\n\n".join(self.__queue)
|
||||
if self.player_name:
|
||||
message = f"Player *{self.player_name}*\n" + message
|
||||
message = f"Player *{self.player_name}*\n\n" + message
|
||||
response = post(self.api_url, json=dict(chat_id=self.chat_id, text=message, parse_mode="Markdown"))
|
||||
self._last_time = utils.now()
|
||||
if response.json().get('ok'):
|
||||
|
@ -13,7 +13,7 @@ pytest==6.2.1
|
||||
pytz>=2020.5
|
||||
requests>=2.25.1
|
||||
responses==0.12.1
|
||||
setuptools==51.1.1
|
||||
Sphinx==3.4.2
|
||||
setuptools==51.1.2
|
||||
Sphinx==3.4.3
|
||||
twine==3.3.0
|
||||
wheel==0.36.2
|
||||
|
@ -1,5 +1,5 @@
|
||||
[bumpversion]
|
||||
current_version = 0.23.4.3
|
||||
current_version = 0.23.4.8
|
||||
commit = True
|
||||
tag = True
|
||||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?
|
||||
|
Reference in New Issue
Block a user