fix bug in war attack logger
This commit is contained in:
1 parent
b5682d7070
commit
9bf35bef61
2 files changed
+15
-13
No files matched your search
+4
-4
@@ -454,9 +454,9 @@ class WarMonitor(commands.Cog):
|
|||||||
return msg
|
return msg
|
||||||
|
|
||||||
@log_errors
|
@log_errors
|
||||||
async def warattack_logger(self, warattack: pnwkit.WarAttack):
|
async def warattack_logger(self, warattack: pnwkit.data.WarAttack):
|
||||||
await self.log_ally_attacks(warattack)
|
await self.log_ally_attacks(warattack)
|
||||||
if not warattack.war_id in self.monitored_wars:
|
if warattack.war_id not in self.monitored_wars:
|
||||||
return
|
return
|
||||||
war = await get_war(self.kit, warattack.war_id)
|
war = await get_war(self.kit, warattack.war_id)
|
||||||
channel = await self.get_war_channel(war.id)
|
channel = await self.get_war_channel(war.id)
|
||||||
@@ -469,8 +469,8 @@ class WarMonitor(commands.Cog):
|
|||||||
msg = self.construct_message(warattack, attacker, defender)
|
msg = self.construct_message(warattack, attacker, defender)
|
||||||
await channel.send(msg)
|
await channel.send(msg)
|
||||||
|
|
||||||
async def log_ally_attacks(self, warattack: pnwkit.WarAttack):
|
async def log_ally_attacks(self, warattack: pnwkit.data.WarAttack):
|
||||||
if not warattack.att_id in self.allied_nations:
|
if warattack.att_id not in self.allied_nations:
|
||||||
return
|
return
|
||||||
channel = await self.bot.fetch_channel(ALLIANCE_ATK_CH)
|
channel = await self.bot.fetch_channel(ALLIANCE_ATK_CH)
|
||||||
attacker, defender = await get_nation(
|
attacker, defender = await get_nation(
|
||||||
|
|||||||
+11
-9
@@ -51,8 +51,8 @@ def timeline_button(id: int):
|
|||||||
|
|
||||||
async def get_nation(
|
async def get_nation(
|
||||||
kit: pnwkit.QueryKit, id: Union[List[int], int]
|
kit: pnwkit.QueryKit, id: Union[List[int], int]
|
||||||
) -> Union[pnwkit.Nation, List[pnwkit.Nation]]:
|
) -> Union[pnwkit.data.Nation, List[pnwkit.data.Nation]]:
|
||||||
nation = await kit.query(
|
query_result = await kit.query(
|
||||||
"nations",
|
"nations",
|
||||||
{"id": id},
|
{"id": id},
|
||||||
"nation_name, flag, num_cities, soldiers, tanks, aircraft, ships, missiles, score, nukes, id, alliance {name, id, flag}, discord, vacation_mode_turns, color, alliance_position, leader_name",
|
"nation_name, flag, num_cities, soldiers, tanks, aircraft, ships, missiles, score, nukes, id, alliance {name, id, flag}, discord, vacation_mode_turns, color, alliance_position, leader_name",
|
||||||
@@ -60,18 +60,18 @@ async def get_nation(
|
|||||||
if isinstance(id, list):
|
if isinstance(id, list):
|
||||||
result = []
|
result = []
|
||||||
result.extend(id)
|
result.extend(id)
|
||||||
for nation in nation.nations:
|
for n in query_result.nations:
|
||||||
result[result.index(nation.id)] = nation
|
result[result.index(n.id)] = n
|
||||||
return result
|
return result
|
||||||
return nation.nations[0]
|
return query_result.nations[0]
|
||||||
|
|
||||||
|
|
||||||
async def get_war(
|
async def get_war(
|
||||||
kit: pnwkit.QueryKit, id: Union[int, List[int]]
|
kit: pnwkit.QueryKit, id: int | List[int]
|
||||||
) -> Union[pnwkit.War, List[pnwkit.War]]:
|
) -> pnwkit.data.War | List[pnwkit.War] | None:
|
||||||
war = await kit.query(
|
war = await kit.query(
|
||||||
"wars",
|
"wars",
|
||||||
{"id": id},
|
{"id": id, "active": False},
|
||||||
"att_alliance_id, def_alliance_id, id, att_id, def_id, turns_left, winner_id, war_type, att_infra_destroyed, att_infra_destroyed_value, def_infra_destroyed, def_infra_destroyed_value, air_superiority, ground_control, naval_blockade, att_points, def_points, att_resistance, def_resistance",
|
"att_alliance_id, def_alliance_id, id, att_id, def_id, turns_left, winner_id, war_type, att_infra_destroyed, att_infra_destroyed_value, def_infra_destroyed, def_infra_destroyed_value, air_superiority, ground_control, naval_blockade, att_points, def_points, att_resistance, def_resistance",
|
||||||
)
|
)
|
||||||
if isinstance(id, list):
|
if isinstance(id, list):
|
||||||
@@ -80,4 +80,6 @@ async def get_war(
|
|||||||
for war in war.wars:
|
for war in war.wars:
|
||||||
result[result.index(war.id)] = war
|
result[result.index(war.id)] = war
|
||||||
return result
|
return result
|
||||||
return war.wars[0]
|
if war.wars:
|
||||||
|
return war.wars[0]
|
||||||
|
return None
|
||||||
Reference in new issue
Block a user