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
|
ALLIANCE_ID = 10177
|
||||||
GUILD = 943540698492334120
|
GUILD = 943540698492334120
|
||||||
CATEGORY = 1017442427537215619
|
CATEGORY = 1017442427537215619
|
||||||
|
WAR_LOG_CHANNEL = 1359571584574029925
|
||||||
|
MONITORED_ALLIANCES = [10177,10198]
|
||||||
|
|
||||||
class WarMonitor(commands.Cog):
|
class WarMonitor(commands.Cog):
|
||||||
def __init__(self, bot: Brahmos):
|
def __init__(self, bot: Brahmos):
|
||||||
@@ -39,66 +41,150 @@ class WarMonitor(commands.Cog):
|
|||||||
)
|
)
|
||||||
self.war_check.start()
|
self.war_check.start()
|
||||||
|
|
||||||
@tasks.loop(minutes=2)
|
@commands.Cog.listener()
|
||||||
async def war_check(self):
|
async def on_ready(self):
|
||||||
wars = await self.kit.query(
|
sub = pnwkit.Subscription(
|
||||||
"wars",
|
kit=self.kit,
|
||||||
{"alliance_id": ALLIANCE_ID},
|
model="war",
|
||||||
(
|
event="create",
|
||||||
"id,"
|
callback=self.alliance_callback,
|
||||||
"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 }"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def alliance_callback(self, war: pnwkit.War):
|
||||||
|
# offensive wars
|
||||||
|
|
||||||
wars = wars.wars
|
def url_button_view(war: pnwkit.War):
|
||||||
war1 = wars[0]
|
class UrlButton(discord.ui.Button):
|
||||||
guild = await self.bot.fetch_guild(GUILD)
|
def __init__(self, war: pnwkit.War):
|
||||||
# category = discord.utils.get(guild.categories, id=CATEGORY)
|
super().__init__(
|
||||||
# if war1.attacker.nation_name in [c.name for c in category.channels]:
|
label="War Timeline",
|
||||||
# return
|
url=f"https://politicsandwar.com/nation/war/timeline/war={war.id}",
|
||||||
# ch = await guild.create_text_channel(name=war1.attacker.nation_name, category=category)
|
style=discord.ButtonStyle.url,
|
||||||
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}")
|
view = BasicView()
|
||||||
await ch.send(f"Defender: {war1.defender.nation_name} {war1.defender.score} {war1.defender.flag}")
|
view.add_item(UrlButton(war))
|
||||||
await ch.send(f"Attacker: {war1.attacker.soldiers} {war1.attacker.tanks} {war1.attacker.aircraft} {war1.attacker.ships} {war1.attacker.missiles}")
|
return view
|
||||||
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}")
|
def format_count(num):
|
||||||
await ch.send(f"Defender: {war1.defender.nukes} {war1.defender.ground_control} {war1.defender.air_superiority} {war1.defender.naval_blockade} {war1.defender.war_type}")
|
if num >= 1000:
|
||||||
await ch.send(f"Reason: {war1.reason}")
|
return f"{num/1000:,.1f}"
|
||||||
await ch.send(f"Turns left: {war1.turns_left}")
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,3 +15,11 @@ class Emojis:
|
|||||||
coal = "<:coal:1220371877013229619>"
|
coal = "<:coal:1220371877013229619>"
|
||||||
money = "<:dollarsym:1220378339970252841>"
|
money = "<:dollarsym:1220378339970252841>"
|
||||||
credits = "<:credits:1280578712286269581>"
|
credits = "<:credits:1280578712286269581>"
|
||||||
|
tank = "<:tank:1362095745846481038>"
|
||||||
|
ship = "<:ship:1362095796610400277>"
|
||||||
|
soldiers = "<:soldiers:1362095846497452052>"
|
||||||
|
planes = "<:plane:1362095773172633630>"
|
||||||
|
nuke = "<:nuke:1362095819846844606>"
|
||||||
|
missile = "<:missile:1362095960611881190>"
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user