update
This commit is contained in:
1 parent
6dc779793c
commit
3939492930
1 file changed
+58
-25
+58
-25
@@ -24,7 +24,8 @@ GUILD = 943540698492334120
|
|||||||
CATEGORY = 1017442427537215619
|
CATEGORY = 1017442427537215619
|
||||||
OFFENSIVE_LOG_CHANNEL = 1359571584574029925
|
OFFENSIVE_LOG_CHANNEL = 1359571584574029925
|
||||||
DEFENSIVE_LOG_CHANNEL = 1362303245598457856
|
DEFENSIVE_LOG_CHANNEL = 1362303245598457856
|
||||||
MONITORED_ALLIANCES = [10177,10198]
|
MONITORED_ALLIANCES = [10177, 10198]
|
||||||
|
|
||||||
|
|
||||||
class WarMonitor(commands.Cog):
|
class WarMonitor(commands.Cog):
|
||||||
def __init__(self, bot: Brahmos):
|
def __init__(self, bot: Brahmos):
|
||||||
@@ -69,7 +70,7 @@ class WarMonitor(commands.Cog):
|
|||||||
nation = await self.kit.query(
|
nation = await self.kit.query(
|
||||||
"nations",
|
"nations",
|
||||||
{"id": id, "first": 1},
|
{"id": id, "first": 1},
|
||||||
"nation_name, flag, num_cities, soldiers, tanks, aircraft, ships, missiles, score, nukes, id, alliance {name, id, flag}"
|
"nation_name, flag, num_cities, soldiers, tanks, aircraft, ships, missiles, score, nukes, id, alliance {name, id, flag}",
|
||||||
)
|
)
|
||||||
return nation.nations[0]
|
return nation.nations[0]
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ class WarMonitor(commands.Cog):
|
|||||||
em = discord.Embed(
|
em = discord.Embed(
|
||||||
title=f"{nation.nation_name} c{nation.num_cities}",
|
title=f"{nation.nation_name} c{nation.num_cities}",
|
||||||
color=color,
|
color=color,
|
||||||
url = f"https://politicsandwar.com/nation/id={nation.id}"
|
url=f"https://politicsandwar.com/nation/id={nation.id}",
|
||||||
).set_thumbnail(url=nation.flag)
|
).set_thumbnail(url=nation.flag)
|
||||||
|
|
||||||
em.description = (
|
em.description = (
|
||||||
@@ -119,7 +120,9 @@ class WarMonitor(commands.Cog):
|
|||||||
|
|
||||||
view = self.timeline_button(war)
|
view = self.timeline_button(war)
|
||||||
|
|
||||||
await off_channel.send(embeds=[embed1, embed2], view=view, content="> WAR (OFFENSIVE)")
|
await off_channel.send(
|
||||||
|
embeds=[embed1, embed2], view=view, content="> WAR (OFFENSIVE)"
|
||||||
|
)
|
||||||
|
|
||||||
if war.def_alliance_id in MONITORED_ALLIANCES:
|
if war.def_alliance_id in MONITORED_ALLIANCES:
|
||||||
|
|
||||||
@@ -129,45 +132,56 @@ class WarMonitor(commands.Cog):
|
|||||||
|
|
||||||
view = self.timeline_button(war)
|
view = self.timeline_button(war)
|
||||||
|
|
||||||
await def_channel.send(embeds=[embed1, embed2], view=view, content="> WAR (DEFENSIVE)")
|
await def_channel.send(
|
||||||
|
embeds=[embed1, embed2], view=view, content="> WAR (DEFENSIVE)"
|
||||||
|
)
|
||||||
|
|
||||||
# create war channel
|
# create war channel
|
||||||
|
|
||||||
|
|
||||||
async def get_war_channel(self, war: pnwkit.War):
|
async def get_war_channel(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)
|
||||||
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, color: discord.Color) -> discord.Embed:
|
async def build_nation_card(
|
||||||
|
self, nation: pnwkit.Nation, color: discord.Color
|
||||||
|
) -> discord.Embed:
|
||||||
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=color,
|
color=color,
|
||||||
timestamp=datetime.datetime.now()
|
timestamp=datetime.datetime.now(),
|
||||||
)
|
)
|
||||||
em.set_thumbnail(url=nation.flag)
|
em.set_thumbnail(url=nation.flag)
|
||||||
if nation.alliance:
|
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.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(
|
||||||
name="Military",
|
name="Military",
|
||||||
value=(f"{Emojis.soldiers} {format_count(nation.soldiers)} "
|
value=(
|
||||||
|
f"{Emojis.soldiers} {format_count(nation.soldiers)} "
|
||||||
f"{Emojis.tanks} {format_count(nation.tanks)} "
|
f"{Emojis.tanks} {format_count(nation.tanks)} "
|
||||||
f"{Emojis.planes} {format_count(nation.aircraft)} "
|
f"{Emojis.planes} {format_count(nation.aircraft)} "
|
||||||
f"{Emojis.ships} {format_count(nation.ships)} "
|
f"{Emojis.ships} {format_count(nation.ships)} "
|
||||||
f"{Emojis.missiles} {format_count(nation.missiles)} "
|
f"{Emojis.missiles} {format_count(nation.missiles)} "
|
||||||
f"{Emojis.nukes} {format_count(nation.nukes)}"
|
f"{Emojis.nukes} {format_count(nation.nukes)}"
|
||||||
),
|
),
|
||||||
inline=False
|
inline=False,
|
||||||
)
|
)
|
||||||
return em
|
return em
|
||||||
|
|
||||||
async def build_war_card(self, war: pnwkit.War) -> discord.Embed:
|
async def build_war_card(self, war: pnwkit.War) -> discord.Embed:
|
||||||
em = discord.Embed(
|
em = discord.Embed(
|
||||||
title = "War Info",
|
title="War Info",
|
||||||
color=discord.Color.blurple(),
|
color=discord.Color.blurple(),
|
||||||
timestamp=datetime.datetime.now(),
|
timestamp=datetime.datetime.now(),
|
||||||
)
|
)
|
||||||
@@ -180,13 +194,25 @@ class WarMonitor(commands.Cog):
|
|||||||
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.name)
|
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)
|
||||||
if not war.air_superiority:
|
if not war.air_superiority:
|
||||||
value = attacker.nation_name if war.air_superiority == war.att_id else defender.nation_name
|
value = (
|
||||||
|
attacker.nation_name
|
||||||
|
if war.air_superiority == war.att_id
|
||||||
|
else defender.nation_name
|
||||||
|
)
|
||||||
em.add_field(name="Air Superiority", value=value, inline=False)
|
em.add_field(name="Air Superiority", value=value, inline=False)
|
||||||
if not war.naval_blockade:
|
if not war.naval_blockade:
|
||||||
value = attacker.nation_name if war.naval_blockade == war.att_id else defender.nation_name
|
value = (
|
||||||
|
attacker.nation_name
|
||||||
|
if war.naval_blockade == war.att_id
|
||||||
|
else defender.nation_name
|
||||||
|
)
|
||||||
em.add_field(name="Naval Blockade", value=value, inline=False)
|
em.add_field(name="Naval Blockade", value=value, inline=False)
|
||||||
|
|
||||||
return em
|
return em
|
||||||
@@ -195,29 +221,40 @@ class WarMonitor(commands.Cog):
|
|||||||
alliances = await self.kit.query(
|
alliances = await self.kit.query(
|
||||||
"alliances",
|
"alliances",
|
||||||
{"id": MONITORED_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}",
|
||||||
)
|
)
|
||||||
nations = alliances.alliances[0].nations + alliances.alliances[1].nations
|
nations = alliances.alliances[0].nations + alliances.alliances[1].nations
|
||||||
attacker = await self.get_nation(war.att_id)
|
attacker = await self.get_nation(war.att_id)
|
||||||
score = attacker.score
|
score = attacker.score
|
||||||
in_range = []
|
in_range = []
|
||||||
for nation in nations:
|
for nation in nations:
|
||||||
min_score = nation.score*0.75
|
min_score = nation.score * 0.75
|
||||||
max_score = nation.score*2.50
|
max_score = nation.score * 2.50
|
||||||
if min_score <= score <= max_score:
|
if min_score <= score <= max_score:
|
||||||
in_range.append(nation)
|
in_range.append(nation)
|
||||||
if not in_range:
|
if not in_range:
|
||||||
await channel.send("> No allied nations in range")
|
await channel.send("> No allied nations in range")
|
||||||
else:
|
else:
|
||||||
for n in range(0, len(in_range), 10):
|
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]])
|
name = f"[{n.nation_name}](<https://politicsandwar.com/nation/id={nation.id}>)"
|
||||||
|
message = "\n".join(
|
||||||
|
[
|
||||||
|
f"{name:<25} | \
|
||||||
|
{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)
|
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, discord.Color.red())
|
atk_card = await self.build_nation_card(attacker, discord.Color.red())
|
||||||
def_card = await self.build_nation_card(defender, discord.Color.green())
|
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)
|
||||||
@@ -227,9 +264,5 @@ class WarMonitor(commands.Cog):
|
|||||||
await self.calc_inrange(war, channel)
|
await self.calc_inrange(war, channel)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot: Brahmos):
|
async def setup(bot: Brahmos):
|
||||||
await bot.add_cog(WarMonitor(bot))
|
await bot.add_cog(WarMonitor(bot))
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user