This commit is contained in:
un1xx committed 2025-04-18 17:54:12 +05:30
1 parent 76d148408a
commit 0f38b7b45c
2 files changed
+37 -68

No files matched your search

+31 -68
View File
@@ -17,6 +17,7 @@ from botclass import Brahmos, CustomCtx
from utils.base import BasicView from utils.base import BasicView
from utils.emojis import Emojis from utils.emojis import Emojis
from utils.paginator import Paginator from utils.paginator import Paginator
from utils.funcs import format_count
ALLIANCE_ID = 10177 ALLIANCE_ID = 10177
GUILD = 943540698492334120 GUILD = 943540698492334120
@@ -88,12 +89,6 @@ class WarMonitor(commands.Cog):
self.war_update_task.cancel() self.war_update_task.cancel()
async def war_logger(self, war: pnwkit.War): async def war_logger(self, war: pnwkit.War):
def format_count(num):
if num >= 1000:
return f"{num/1000:,.1f}K"
else:
return num
async def build_embed(nation_id: int, color: discord.Color): async def build_embed(nation_id: int, color: discord.Color):
nation = await self.get_nation(nation_id) nation = await self.get_nation(nation_id)
@@ -145,20 +140,16 @@ class WarMonitor(commands.Cog):
channel = discord.utils.get(category.text_channels, name=f"{attacker.nation_name.replace(' ', '-')}-{war.id}") channel = discord.utils.get(category.text_channels, name=f"{attacker.nation_name.replace(' ', '-')}-{war.id}")
return channel return channel
async def build_nation_card(self, nation: pnwkit.Nation) -> discord.Embed: async def build_nation_card(self, nation: pnwkit.Nation, color: discord.Color) -> discord.Embed:
def format_count(num):
if num >= 1000:
return f"{num/1000:,.1f}K"
else:
return num
em = discord.Embed( em = discord.Embed(
title=f"{nation.nation_name}", title=f"{nation.nation_name}",
url=f"https://politicsandwar.com/nation/id={nation.id}", url=f"https://politicsandwar.com/nation/id={nation.id}",
color=discord.Color.blurple(), color=color,
timestamp=datetime.datetime.now() timestamp=datetime.datetime.now()
) )
em.set_thumbnail(url=nation.flag) em.set_thumbnail(url=nation.flag)
em.set_author(name=nation.alliance.name, icon_url=nation.alliance.flag, url=f"https://politicsandwar.com/alliance/id={nation.alliance.id}") if nation.alliance:
em.set_author(name=nation.alliance.name, icon_url=nation.alliance.flag, url=f"https://politicsandwar.com/alliance/id={nation.alliance.id}")
em.add_field(name="Score", value=f"{nation.score}") em.add_field(name="Score", value=f"{nation.score}")
em.add_field(name="Cities", value=f"{nation.num_cities}") em.add_field(name="Cities", value=f"{nation.num_cities}")
em.add_field( em.add_field(
@@ -187,7 +178,7 @@ class WarMonitor(commands.Cog):
em.add_field(name="Defender MAPs", value=war.def_points) em.add_field(name="Defender MAPs", value=war.def_points)
em.add_field(name="Attacker Resistance", value=war.att_resistance) em.add_field(name="Attacker Resistance", value=war.att_resistance)
em.add_field(name="Defender Resistance", value=war.def_resistance) em.add_field(name="Defender Resistance", value=war.def_resistance)
em.add_field(name="War Type", value=war.war_type) em.add_field(name="War Type", value=war.war_type.name)
if not war.ground_control: if not war.ground_control:
value = attacker.nation_name if war.ground_control == war.att_id else defender.nation_name value = attacker.nation_name if war.ground_control == war.att_id else defender.nation_name
em.add_field(name="Ground Control", value=value, inline=False) em.add_field(name="Ground Control", value=value, inline=False)
@@ -200,70 +191,42 @@ class WarMonitor(commands.Cog):
return em return em
async def calc_inrange(self, war: pnwkit.War, channel: discord.TextChannel):
alliances = self.kit.query(
"alliances",
{"id": MONITORED_ALLIANCES},
"id, name, flag, nations {id, name, score, soldiers, tanks, aircraft, ships, missiles, nukes, num_cities}"
)
nations = alliances.alliances[0].nations + alliances.alliances[1].nations
attacker = await self.get_nation(war.att_id)
score = attacker.score
in_range = []
for nation in nations:
min_score = nation.score*0.75
max_score = nation.score*2.50
if min_score <= score <= max_score:
in_range.append(nation)
if not in_range:
await channel.send("> No allied nations in range")
else:
for n in range(0, len(in_range), 10):
message = "\n".join([f"[{n.nation_name}](https://politicsandwar.com/nation/id={n.id}) {Emojis.soldiers} {format_count(n.soldiers)} {Emojis.tanks} {format_count(n.tanks)} {Emojis.planes} {format_count(n.aircraft)} {Emojis.ships} {format_count(n.ships)} {Emojis.missiles} {format_count(n.missiles)} {Emojis.nukes} {format_count(n.nukes)}" for n in in_range[n:n+10]])
await channel.send(message)
async def defense_handler(self, war: pnwkit.War): async def defense_handler(self, war: pnwkit.War):
category = await self.bot.fetch_channel(CATEGORY) category = await self.bot.fetch_channel(CATEGORY)
attacker = await self.get_nation(war.att_id) attacker = await self.get_nation(war.att_id)
defender = await self.get_nation(war.def_id) defender = await self.get_nation(war.def_id)
channel = await category.create_text_channel(name=f"{attacker.nation_name}-{war.id}") channel = await category.create_text_channel(name=f"{attacker.nation_name}-{war.id}")
atk_card = await self.build_nation_card(attacker) atk_card = await self.build_nation_card(attacker, discord.Color.red())
def_card = await self.build_nation_card(defender) def_card = await self.build_nation_card(defender, discord.Color.green())
war_card = await self.build_war_card(war) war_card = await self.build_war_card(war)
await channel.send(embeds=[atk_card, def_card]) await channel.send(embeds=[atk_card, def_card])
button = self.timeline_button(war) button = self.timeline_button(war)
await channel.send(embeds=[war_card], view=button) await channel.send(embeds=[war_card], view=button)
await self.calc_inrange(war, channel)
# @tasks.loop(minutes=2)
# async def war_check(self):
# wars = await self.kit.query(
# "wars",
# {"alliance_id": ALLIANCE_ID},
# (
# "id,"
# "date,"
# "att_points,"
# "def_points,"
# "att_resistance,"
# "def_resistance,"
# "reason,"
# "ground_control,"
# "war_type,"
# "air_superiority,"
# "naval_blockade,"
# "turns_left,"
# "att_alliance_id,"
# "def_alliance_id,"
# "attacker {"
# "nation_name,"
# "soldiers,"
# "tanks,"
# "aircraft,"
# "ships,"
# "missiles,"
# "score,"
# "flag,"
# "nukes },"
# "defender {"
# "nation_name,"
# "soldiers,"
# "tanks,"
# "aircraft,"
# "ships,"
# "missiles,"
# "flag,"
# "score,"
# "nukes }"
# )
# )
# wars = wars.wars
# war1 = wars[0]
# guild = await self.bot.fetch_guild(GUILD)
# # category = discord.utils.get(guild.categories, id=CATEGORY)
# # if war1.attacker.nation_name in [c.name for c in category.channels]:
# # return
# # ch = await guild.create_text_channel(name=war1.attacker.nation_name, category=category)
async def setup(bot: Brahmos): async def setup(bot: Brahmos):
+6
View File
@@ -23,3 +23,9 @@ async def get_webhook(
def discord_bg_embed(desc: str = "\u200b") -> discord.Embed: def discord_bg_embed(desc: str = "\u200b") -> discord.Embed:
return discord.Embed(color=0x36393E, description=desc) return discord.Embed(color=0x36393E, description=desc)
def format_count(num):
if num >= 1000:
return f"{num/1000:,.1f}K"
else:
return num