add war log
This commit is contained in:
1 parent
1035ad2d32
commit
c6faf273ac
2 files changed
+152
-58
No files matched your search
+144
-58
@@ -21,6 +21,8 @@ from utils.paginator import Paginator
|
||||
ALLIANCE_ID = 10177
|
||||
GUILD = 943540698492334120
|
||||
CATEGORY = 1017442427537215619
|
||||
WAR_LOG_CHANNEL = 1359571584574029925
|
||||
MONITORED_ALLIANCES = [10177,10198]
|
||||
|
||||
class WarMonitor(commands.Cog):
|
||||
def __init__(self, bot: Brahmos):
|
||||
@@ -39,66 +41,150 @@ class WarMonitor(commands.Cog):
|
||||
)
|
||||
self.war_check.start()
|
||||
|
||||
@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 }"
|
||||
)
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
sub = pnwkit.Subscription(
|
||||
kit=self.kit,
|
||||
model="war",
|
||||
event="create",
|
||||
callback=self.alliance_callback,
|
||||
)
|
||||
|
||||
async def alliance_callback(self, war: pnwkit.War):
|
||||
# offensive wars
|
||||
|
||||
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)
|
||||
ch = await guild.fetch_channel(1005142844475981834)
|
||||
await ch.send(f"War started between {war1.attacker.nation_name} and {war1.defender.nation_name} at {format_dt(war1.date, 'R')}")
|
||||
await ch.send(f"Attacker: {war1.attacker.nation_name} {war1.attacker.score} {war1.attacker.flag}")
|
||||
await ch.send(f"Defender: {war1.defender.nation_name} {war1.defender.score} {war1.defender.flag}")
|
||||
await ch.send(f"Attacker: {war1.attacker.soldiers} {war1.attacker.tanks} {war1.attacker.aircraft} {war1.attacker.ships} {war1.attacker.missiles}")
|
||||
await ch.send(f"Defender: {war1.defender.soldiers} {war1.defender.tanks} {war1.defender.aircraft} {war1.defender.ships} {war1.defender.missiles}")
|
||||
await ch.send(f"Attacker: {war1.attacker.nukes} {war1.attacker.ground_control} {war1.attacker.air_superiority} {war1.attacker.naval_blockade} {war1.attacker.war_type}")
|
||||
await ch.send(f"Defender: {war1.defender.nukes} {war1.defender.ground_control} {war1.defender.air_superiority} {war1.defender.naval_blockade} {war1.defender.war_type}")
|
||||
await ch.send(f"Reason: {war1.reason}")
|
||||
await ch.send(f"Turns left: {war1.turns_left}")
|
||||
def url_button_view(war: pnwkit.War):
|
||||
class UrlButton(discord.ui.Button):
|
||||
def __init__(self, war: pnwkit.War):
|
||||
super().__init__(
|
||||
label="War Timeline",
|
||||
url=f"https://politicsandwar.com/nation/war/timeline/war={war.id}",
|
||||
style=discord.ButtonStyle.url,
|
||||
)
|
||||
|
||||
view = BasicView()
|
||||
view.add_item(UrlButton(war))
|
||||
return view
|
||||
|
||||
def format_count(num):
|
||||
if num >= 1000:
|
||||
return f"{num/1000:,.1f}"
|
||||
else:
|
||||
return num
|
||||
def build_embed(nation: pnwkit.Nation, color: discord.Color):
|
||||
em = discord.Embed(
|
||||
title=f"{nation.nation_name} c({nation.city_count})",
|
||||
color=color,
|
||||
url = f"https://politicsandwar.com/nation/id={nation.id}"
|
||||
).set_thumbnail(url=nation.flag)
|
||||
|
||||
em.description = (
|
||||
f"{Emojis.soldiers} {format_count(nation.soldiers)}\t\t\t"
|
||||
f"{Emojis.tanks} {format_count(nation.tanks)}\n"
|
||||
f"{Emojis.aircraft} {format_count(nation.aircraft)}\t\t\t"
|
||||
f"{Emojis.ships} {format_count(nation.ships)}\n"
|
||||
f"{Emojis.missiles} {format_count(nation.missiles)}\t\t\t"
|
||||
f"{Emojis.nukes} {format_count(nation.nukes)}\n"
|
||||
)
|
||||
return em
|
||||
|
||||
channel = await self.bot.fetch_channel(WAR_LOG_CHANNEL)
|
||||
|
||||
if war.att_alliance_id: # in MONITORED_ALLIANCES:
|
||||
attacker = await self.kit.query(
|
||||
"nation",
|
||||
{"id": war.att_id, "first": 1},
|
||||
"nation_name, flag, num_cities, soldiers, tanks, aircraft, ships, missiles, score, nukes"
|
||||
)
|
||||
attacker = attacker.nations[0]
|
||||
defender = await self.kit.query(
|
||||
"nation",
|
||||
{"id": war.def_id, "first": 1},
|
||||
"nation_name, flag, num_cities, soldiers, tanks, aircraft, ships, missiles, score, nukes"
|
||||
)
|
||||
defender = defender.nations[0]
|
||||
|
||||
embed1 = build_embed(attacker, discord.Color.green())
|
||||
embed2 = build_embed(defender, discord.Color.green())
|
||||
embed2.timestamp = datetime.datetime.now()
|
||||
|
||||
view = url_button_view(war)
|
||||
|
||||
await channel.send(embeds=[embed1, embed2], view=view, content="> WAR (OFFENSIVE)")
|
||||
|
||||
if war.def_alliance_id: #in MONITORED_ALLIANCES:
|
||||
attacker = await self.kit.query(
|
||||
"nation",
|
||||
{"id": war.att_id, "first": 1},
|
||||
"nation_name, flag, num_cities, soldiers, tanks, aircraft, ships, missiles, score, nukes"
|
||||
)
|
||||
attacker = attacker.nations[0]
|
||||
defender = await self.kit.query(
|
||||
"nation",
|
||||
{"id": war.def_id, "first": 1},
|
||||
"nation_name, flag, num_cities, soldiers, tanks, aircraft, ships, missiles, score, nukes"
|
||||
)
|
||||
defender = defender.nations[0]
|
||||
|
||||
embed1 = build_embed(attacker, discord.Color.green())
|
||||
embed2 = build_embed(defender, discord.Color.green())
|
||||
embed2.timestamp = datetime.datetime.now()
|
||||
|
||||
view = url_button_view(war)
|
||||
|
||||
await channel.send(embeds=[embed1, embed2], view=view, content="> WAR (DEFENSIVE)")
|
||||
|
||||
|
||||
# @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)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user