Notification parsing and deleting
This commit is contained in:
parent
07ba1795d3
commit
b7211b7c75
@ -243,7 +243,7 @@ class ErepublikCompanyAPI(CitizenBaseAPI):
|
|||||||
data = dict(action_type="workOvertime", _token=self.token)
|
data = dict(action_type="workOvertime", _token=self.token)
|
||||||
return self.post("{}/economy/workOvertime".format(self.url), data=data)
|
return self.post("{}/economy/workOvertime".format(self.url), data=data)
|
||||||
|
|
||||||
def _post_economy_job_market_apply(self, citizen: int, salary: int) -> Response:
|
def _post_economy_job_market_apply(self, citizen: int, salary: float) -> Response:
|
||||||
data = dict(_token=self.token, citizenId=citizen, salary=salary)
|
data = dict(_token=self.token, citizenId=citizen, salary=salary)
|
||||||
return self.post("{}/economy/job-market-apply".format(self.url), data=data)
|
return self.post("{}/economy/job-market-apply".format(self.url), data=data)
|
||||||
|
|
||||||
@ -424,6 +424,10 @@ class ErepublikMilitaryAPI(CitizenBaseAPI):
|
|||||||
data = dict(sideId=side_id, battleId=battle_id, _token=self.token, battleZoneId=zone_id)
|
data = dict(sideId=side_id, battleId=battle_id, _token=self.token, battleZoneId=zone_id)
|
||||||
return self.post("{}/military/fight-shooot/{}".format(self.url, battle_id), data=data)
|
return self.post("{}/military/fight-shooot/{}".format(self.url, battle_id), data=data)
|
||||||
|
|
||||||
|
def _post_fight_deploy_deploy_report_data(self, deployment_id: int):
|
||||||
|
data = dict(_token=self.token, deploymentId=deployment_id)
|
||||||
|
return self.post(f"{self.url}/military/fightDeploy-deployReportData", json=data)
|
||||||
|
|
||||||
|
|
||||||
class ErepublikPoliticsAPI(CitizenBaseAPI):
|
class ErepublikPoliticsAPI(CitizenBaseAPI):
|
||||||
def _get_candidate_party(self, party_slug: str) -> Response:
|
def _get_candidate_party(self, party_slug: str) -> Response:
|
||||||
@ -528,6 +532,18 @@ class ErepublikProfileAPI(CitizenBaseAPI):
|
|||||||
data = {"_token": self.token, "delete_alerts[]": notification_ids, "deleteAllAlerts": "1", "delete": "Delete"}
|
data = {"_token": self.token, "delete_alerts[]": notification_ids, "deleteAllAlerts": "1", "delete": "Delete"}
|
||||||
return self.post("{}/main/messages-alerts/1".format(self.url), data=data)
|
return self.post("{}/main/messages-alerts/1".format(self.url), data=data)
|
||||||
|
|
||||||
|
def _post_main_notifications_ajax_community(self, notification_ids: List[int], page: int = 1) -> Response:
|
||||||
|
data = {"_token": self.token, "delete_alerts[]": notification_ids}
|
||||||
|
return self.post("{}/main/notificationsAjax/community/{}".format(self.url, page), data=data)
|
||||||
|
|
||||||
|
def _post_main_notifications_ajax_system(self, notification_ids: List[int], page: int = 1) -> Response:
|
||||||
|
data = {"_token": self.token, "delete_alerts[]": notification_ids}
|
||||||
|
return self.post("{}/main/notificationsAjax/system/{}".format(self.url, page), data=data)
|
||||||
|
|
||||||
|
def _post_main_notifications_ajax_report(self, notification_ids: List[int], page: int = 1) -> Response:
|
||||||
|
data = {"_token": self.token, "delete_alerts[]": notification_ids}
|
||||||
|
return self.post("{}/main/notificationsAjax/report/{}".format(self.url, page), data=data)
|
||||||
|
|
||||||
def _post_main_messages_compose(self, subject: str, body: str, citizens: List[int]) -> Response:
|
def _post_main_messages_compose(self, subject: str, body: str, citizens: List[int]) -> Response:
|
||||||
url_pk = 0 if len(citizens) > 1 else str(citizens[0])
|
url_pk = 0 if len(citizens) > 1 else str(citizens[0])
|
||||||
data = dict(citizen_name=",".join([str(x) for x in citizens]),
|
data = dict(citizen_name=",".join([str(x) for x in citizens]),
|
||||||
|
@ -2067,6 +2067,47 @@ class CitizenSocial(BaseCitizen):
|
|||||||
for resident in resp["widgets"]["residents"]["residents"]:
|
for resident in resp["widgets"]["residents"]["residents"]:
|
||||||
self.add_friend(resident["citizenId"])
|
self.add_friend(resident["citizenId"])
|
||||||
|
|
||||||
|
def get_community_notifications(self, page: int = 1) -> List[Dict[str, Any]]:
|
||||||
|
return self._get_main_notifications_ajax_community(page).json().get('alertsList', [])
|
||||||
|
|
||||||
|
def get_system_notifications(self, page: int = 1) -> List[Dict[str, Any]]:
|
||||||
|
return self._get_main_notifications_ajax_system(page).json().get('alertsList', [])
|
||||||
|
|
||||||
|
def get_report_notifications(self, page: int = 1) -> List[Dict[str, Any]]:
|
||||||
|
return self._get_main_notifications_ajax_report(page).json().get('alertsList', [])
|
||||||
|
|
||||||
|
def delete_community_notification(self, notification_id: Union[int, List[int]]):
|
||||||
|
if not isinstance(notification_id, list):
|
||||||
|
notification_id = [notification_id]
|
||||||
|
self._post_main_notifications_ajax_community(notification_id)
|
||||||
|
|
||||||
|
def delete_system_notification(self, notification_id: Union[int, List[int]]):
|
||||||
|
if not isinstance(notification_id, list):
|
||||||
|
notification_id = [notification_id]
|
||||||
|
self._post_main_notifications_ajax_system(notification_id)
|
||||||
|
|
||||||
|
def delete_report_notification(self, notification_id: Union[int, List[int]]):
|
||||||
|
if not isinstance(notification_id, list):
|
||||||
|
notification_id = [notification_id]
|
||||||
|
self._post_main_notifications_ajax_report(notification_id)
|
||||||
|
|
||||||
|
def get_all_notifications(self, page: int = 1) -> Dict[str, List[Dict[str, Any]]]:
|
||||||
|
return dict(community=self.get_community_notifications(),
|
||||||
|
system=self.get_system_notifications(page),
|
||||||
|
report=self.get_report_notifications(page))
|
||||||
|
|
||||||
|
def delete_all_notifications(self):
|
||||||
|
for kind, notifications in self.get_all_notifications():
|
||||||
|
if notifications:
|
||||||
|
if kind == "community":
|
||||||
|
self.delete_community_notification([n['id'] for n in notifications])
|
||||||
|
elif kind == "report":
|
||||||
|
self.delete_report_notification([n['id'] for n in notifications])
|
||||||
|
elif kind == "system":
|
||||||
|
self.delete_system_notification([n['id'] for n in notifications])
|
||||||
|
else:
|
||||||
|
self.report_error(f"Unsupported notification kind: \"{kind}\"!")
|
||||||
|
|
||||||
|
|
||||||
class Citizen(CitizenMilitary, CitizenAnniversary, CitizenEconomy, CitizenSocial, CitizenPolitics):
|
class Citizen(CitizenMilitary, CitizenAnniversary, CitizenEconomy, CitizenSocial, CitizenPolitics):
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
@ -2208,21 +2249,8 @@ class Citizen(CitizenMilitary, CitizenAnniversary, CitizenEconomy, CitizenSocial
|
|||||||
if pps:
|
if pps:
|
||||||
self.details.next_pp.append(int(pps.group(1)))
|
self.details.next_pp.append(int(pps.group(1)))
|
||||||
|
|
||||||
def parse_notifications(self, page: int = 1) -> list:
|
|
||||||
community = self._get_main_notifications_ajax_community(page).json()
|
|
||||||
system = self._get_main_notifications_ajax_system(page).json()
|
|
||||||
return community['alertsList'] + system['alertsList']
|
|
||||||
|
|
||||||
def delete_notifications(self):
|
|
||||||
response = self._get_main_notifications_ajax_community().json()
|
|
||||||
while response['totalAlerts']:
|
|
||||||
self._post_main_messages_alert([_['id'] for _ in response['alertList']])
|
|
||||||
response = self._get_main_notifications_ajax_community().json()
|
|
||||||
|
|
||||||
response = self._get_main_notifications_ajax_system().json()
|
|
||||||
while response['totalAlerts']:
|
|
||||||
self._post_main_messages_alert([_['id'] for _ in response['alertList']])
|
|
||||||
response = self._get_main_notifications_ajax_system().json()
|
|
||||||
|
|
||||||
def collect_weekly_reward(self):
|
def collect_weekly_reward(self):
|
||||||
self.update_weekly_challenge()
|
self.update_weekly_challenge()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user