This commit is contained in:
un1xx committed 2025-05-09 15:57:25 +05:30
1 parent 799dc4f7cb
commit 43ca775fb0
8 files changed
+65 -44

No files matched your search

+1
View File
@@ -60,6 +60,7 @@ class REPL(commands.Cog):
"message": ctx.message,
"_": self._last_result,
"session": self.session,
"kit" : self.kit
}
env.update(globals())
body = self.cleanup_code(body)
+20 -8
View File
@@ -9,6 +9,7 @@ from typing import List, Literal, Optional
import aiohttp
import discord
import asyncpg
import pnwkit
from discord.ext import commands
from discord.utils import format_dt
@@ -20,8 +21,6 @@ from utils.emojis import Emojis
from utils.paginator import Paginator
FILL: list = json.load(open("refill.json"))
class BaseMul:
money = 1000000
@@ -75,6 +74,23 @@ class Banking(commands.Cog):
bot_key_api_key=os.getenv("pnwACCKEY"),
aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop),
)
self.FILL = None
async def cog_load(self):
"""Called when the cog is loaded."""
await self.fetch_refill_ids()
async def fetch_refill_ids(self):
"""Fetch nation IDs from the refill table."""
try:
async with self.bot.db_pool.acquire() as conn:
query = "SELECT id FROM refill"
rows = await conn.fetch(query)
self.FILL = [row[0] for row in rows]
except Exception as e:
self.FILL = []
@commands.has_any_role("Government", "The Croak Council")
@commands.command()
@@ -184,7 +200,7 @@ class Banking(commands.Cog):
nations.append(gator)
for nation in nations:
if nation.id not in FILL:
if nation.id not in self.FILL:
continue
cities = len(nation.cities)
delta = BaseMul.calc(cities, nation)
@@ -401,7 +417,7 @@ class Banking(commands.Cog):
for nation in result.nations:
ids.append(nation.id)
if not ids:
ids = FILL
ids = self.FILL
nations = []
if 103764 in ids:
ids.remove(103764)
@@ -809,10 +825,6 @@ class Banking(commands.Cog):
v.author = ctx.message.author
m = await ctx.send(embed=e, view=v)
v.message = m
# @commands.has_role(987770837627187250)
# @commands.command()
# async def refill(self, ctx: CustomCtx, option: str, commands.Greedy[Int] = None, *, names: str = None):
+18 -3
View File
@@ -27,10 +27,9 @@ CATEGORY = 1356240812861821048
ARCHIVE_CATEGORY = 1367458846708334703
OFFENSIVE_LOG_CHANNEL = 1353940560771027034
DEFENSIVE_LOG_CHANNEL = 1353940670246686843
MONITORED_ALLIANCES = [10177, 10198]
MONITORED_ALLIANCES = [10177, 10198, 11965]
ALLIANCE_ATK_CH = 1367461291685318686
REFILL_LIST = json.load(open("refill.json"))
logger = logging.getLogger("discord")
# decorator to log errors for a function manually
@@ -73,6 +72,7 @@ class WarMonitor(commands.Cog):
self.war_update_task = None
self.war_attacks_task = None
self.monitored_wars = []
self.allied_nations = []
@commands.Cog.listener()
async def on_ready(self):
@@ -80,6 +80,21 @@ class WarMonitor(commands.Cog):
war_ids = [ch.name.split("-")[-1] for ch in category.text_channels]
war_ids = [int(x) for x in war_ids if x.isdigit()]
self.monitored_wars.extend(war_ids)
await self.set_allied_nations()
async def set_allied_nations(self):
"""Fetch allied nations."""
result = await self.kit.query(
"nation",
{"alliance_id": [10177, 10198, 11965]},
"id"
)
if not result:
logger.warning("Failed to fetch allied nations")
self.allied_nations.extend(
[nation.id for nation in result.nations]
)
async def cog_load(self):
self.war_create_task = self.bot.loop.create_task(self.war_create_subscription())
@@ -416,7 +431,7 @@ class WarMonitor(commands.Cog):
await channel.send(msg)
async def log_ally_attacks(self, warattack: pnwkit.WarAttack):
if not warattack.att_id in REFILL_LIST:
if not warattack.att_id in self.allied_nations:
return
channel = await self.bot.fetch_channel(ALLIANCE_ATK_CH)
attacker, defender = await get_nation(self.kit, [warattack.att_id, warattack.def_id])