add war monitor
This commit is contained in:
1 parent
39220fc3a7
commit
e410da6470
2 files changed
+109
No files matched your search
@@ -0,0 +1,108 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import pprint
|
||||
import random
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
import pnwkit
|
||||
from discord.ext import commands, tasks
|
||||
from discord.utils import format_dt
|
||||
|
||||
from botclass import Brahmos, CustomCtx
|
||||
from utils.base import BasicView
|
||||
from utils.emojis import Emojis
|
||||
from utils.paginator import Paginator
|
||||
|
||||
ALLIANCE_ID = 10177
|
||||
GUILD = 943540698492334120
|
||||
CATEGORY = 1017442427537215619
|
||||
|
||||
class WarMonitor(commands.Cog):
|
||||
def __init__(self, bot: Brahmos):
|
||||
self.bot = bot
|
||||
self.kit = pnwkit.QueryKit(
|
||||
api_key=os.getenv("pnwAPIKEY"),
|
||||
bot_key=os.getenv("pnwBOTKEY"),
|
||||
bot_key_api_key=os.getenv("pnwACCKEY"),
|
||||
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
||||
)
|
||||
self.dkit = pnwkit.QueryKit(
|
||||
api_key=os.getenv("pnwDILFKEY"),
|
||||
bot_key=os.getenv("pnwBOTKEY"),
|
||||
bot_key_api_key=os.getenv("pnwACCKEY"),
|
||||
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
|
||||
)
|
||||
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 }"
|
||||
)
|
||||
)
|
||||
|
||||
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}")
|
||||
|
||||
|
||||
|
||||
async def setup(bot: Brahmos):
|
||||
await bot.add_cog(WarMonitor(bot))
|
||||
|
||||
|
||||
Reference in new issue
Block a user