This commit is contained in:
un1xx committed 2025-04-21 21:58:07 +05:30
1 parent 743f1f650a
commit 73f97cfb20
3 files changed
+44 -25

No files matched your search

+30 -19
View File
@@ -118,7 +118,7 @@ class WarMonitor(commands.Cog):
@log_errors
async def war_logger(self, war: pnwkit.War):
async def build_embed(nation_id: int, color: discord.Color):
nation = await get_nation(nation_id)
nation = await get_nation(self.kit, nation_id)
em = discord.Embed(
title=f"{nation.nation_name} c{nation.num_cities}",
@@ -216,7 +216,7 @@ class WarMonitor(commands.Cog):
color=discord.Color.blurple(),
timestamp=datetime.datetime.now(),
)
attacker, defender = await get_nation([warattack.att_id, warattack.def_id])
attacker, defender = await get_nation(self.kit, [war.att_id, war.def_id])
em.add_field(name="Turns Left", value=war.turns_left)
em.add_field(name="Attacker MAPs", value=war.att_points)
em.add_field(name="Defender MAPs", value=war.def_points)
@@ -247,17 +247,19 @@ class WarMonitor(commands.Cog):
return em
async def calc_inrange(self, war: pnwkit.War, channel: discord.TextChannel):
async def calc_inrange(self, attacker_id: int, channel: discord.TextChannel):
alliances = await self.kit.query(
"alliances",
{"id": MONITORED_ALLIANCES},
"id, name, flag, nations {id, nation_name, score, soldiers, tanks, aircraft, ships, missiles, nukes, num_cities}",
"id, name, flag, nations {id, nation_name, score, soldiers, tanks, aircraft, ships, missiles, nukes, num_cities, vacation_mode_turns}",
)
nations = alliances.alliances[0].nations + alliances.alliances[1].nations
attacker = await get_nation(war.att_id)
attacker = await get_nation(self.kit, attacker_id)
score = attacker.score
in_range = []
for nation in nations:
if nation.vacation_mode_turns != 0:
continue
min_score = nation.score * 0.75
max_score = nation.score * 2.50
if min_score <= score <= max_score:
@@ -277,14 +279,14 @@ class WarMonitor(commands.Cog):
@log_errors
async def defense_handler(self, war: pnwkit.War):
channel = await get_war_channel(war.id)
channel = await self.get_war_channel(war.id)
if channel:
await self.war_update_handler(war)
return
if war.id not in self.monitored_wars:
self.monitored_wars.append(war.id)
category = await self.bot.fetch_channel(CATEGORY)
attacker, defender = await get_nation([warattack.att_id, warattack.def_id])
attacker, defender = await get_nation(self.kit, [war.att_id, war.def_id])
channel = await category.create_text_channel(
name=f"{attacker.nation_name.lower()}-{war.id}"
)
@@ -294,7 +296,7 @@ class WarMonitor(commands.Cog):
await channel.send(embeds=[atk_card, def_card])
button = timeline_button(war.id)
await channel.send(embeds=[war_card], view=button)
await self.calc_inrange(war, channel)
await self.calc_inrange(war.id, channel)
# try to add defender discord user to the channel
guild = await self.bot.fetch_guild(GUILD)
member = discord.utils.get(guild.members, name=defender.discord)
@@ -304,7 +306,7 @@ class WarMonitor(commands.Cog):
@log_errors
async def war_update_handler(self, war: pnwkit.War):
if war.id in self.monitored_wars:
channel = await get_war_channel(war.id)
channel = await self.get_war_channel(war.id)
if not channel:
return
war_card = await self.build_war_card(war)
@@ -317,7 +319,7 @@ class WarMonitor(commands.Cog):
await channel.send(embeds=[war_card], view=button)
if war.turns_left <= 0 or war.winner_id:
if war.winner_id:
nation = await get_nation(war.winner_id)
nation = await get_nation(self.kit, war.winner_id)
await channel.send(
f"> War has Ended."
f" {nation.nation_name} has won the war.\n"
@@ -387,7 +389,7 @@ class WarMonitor(commands.Cog):
if warattack.type.value == 12:
msg = f"[{attacker.nation_name}](<https://politicsandwar.com/nation/id={attacker.id}>) fortified their nation."
if warattack.type.value == 13:
msg = f"[{attacker.nation_name}](<https://politicsandwar.com/nation/id={attacker.id}>) offered/cancelled peace."
msg = f"[{attacker.nation_name}](<https://politicsandwar.com/nation/id={attacker.id}>) offered/cancelled peace with [{defender.nation_name}](<https://politicsandwar.com/nation/id={defender.id}>)."
if warattack.type.value in [14, 15]:
msg = warattack.loot_info
@@ -399,9 +401,9 @@ class WarMonitor(commands.Cog):
await self.log_ally_attacks(warattack)
if not warattack.war_id in self.monitored_wars:
return
war = await get_war(warattack.war_id)
channel = await get_war_channel(war.id)
attacker, defender = await get_nation([warattack.att_id, warattack.def_id])
war = await get_war(self.kit, warattack.war_id)
channel = await self.get_war_channel(war.id)
attacker, defender = await get_nation(self.kit, [warattack.att_id, warattack.def_id])
if not channel:
return
@@ -412,9 +414,9 @@ class WarMonitor(commands.Cog):
if not warattack.att_id in REFILL_LIST:
return
channel = await self.bot.fetch_channel(ALLIANCE_ATK_CH)
attacker, defender = await get_nation([warattack.att_id, warattack.def_id])
attacker, defender = await get_nation(self.kit, [warattack.att_id, warattack.def_id])
msg = self.construct_message(warattack, attacker, defender)
button = timeline_button(war.id)
button = timeline_button(warattack.war_id)
await channel.send(msg, view=button)
@@ -423,7 +425,7 @@ class WarMonitor(commands.Cog):
@commands.has_permissions(administrator=True)
async def sync_wars(self, ctx: CustomCtx):
# get all alliance active wars
await ctx.send("> syncing wars...")
m = await ctx.send("> <a:load:1275839759192686654> syncing wars")
wars = await self.kit.query(
"wars",
{"alliance_id": MONITORED_ALLIANCES, "status": pnwkit.WarActivity.ACTIVE},
@@ -443,6 +445,7 @@ class WarMonitor(commands.Cog):
finished_wars = finished_wars.wars
for war in finished_wars:
await self.defense_handler(war)
await m.edit(content="> \u2705 synced wars")
@commands.command()
@@ -487,8 +490,16 @@ class WarMonitor(commands.Cog):
async def monitor(self, ctx: CustomCtx, id: int):
self.monitored_wars.append(id)
await ctx.send(f"added war {id} to monitored wars")
await self.defense_handler(await get_war(id))
await self.defense_handler(await get_war(self.kit, id))
@commands.command()
async def inrange(self, ctx: CustomCtx):
category = await self.bot.fetch_channel(CATEGORY)
if ctx.channel not in category.text_channels:
await ctx.send(f"this command only works inside {category.name}")
return
id = int(ctx.channel.name.split("-")[-1])
await self.calc_inrange(id, ctx.channel)
async def setup(bot: Brahmos):
await bot.add_cog(WarMonitor(bot))