diff --git a/exts/banking.py b/exts/banking.py index 50776c6..c69e6a5 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -24,6 +24,8 @@ from utils.base import BasicView from utils.emojis import Emojis from utils.paginator import Paginator +OFFSHORE_ID = 10198 + class BaseMul: money = 1000000 @@ -177,7 +179,7 @@ class Banking(commands.Cog): await self.kit.mutation( "bankWithdraw", { - "receiver": 10198, + "receiver": OFFSHORE_ID, "receiver_type": 2, "money": resources.money, "food": resources.food, diff --git a/exts/war_monitor.py b/exts/war_monitor.py index 35f340d..7aad4d6 100644 --- a/exts/war_monitor.py +++ b/exts/war_monitor.py @@ -4,6 +4,7 @@ import functools import io import json import logging +import math import os import pprint import random @@ -11,6 +12,7 @@ from typing import List, Literal, Optional, Union import aiohttp import discord +from discord.state import Channel import pnwkit from discord.ext import commands, tasks from discord.utils import format_dt @@ -23,7 +25,7 @@ from utils.funcs import format_count, timeline_button, get_nation, get_war ALLIANCE_ID = 10177 GUILD = 1353930666311421952 -CATEGORY = 1356240812861821048 +CATEGORIES = [1356240812861821048, 1356240812861821048] ARCHIVE_CATEGORY = 1367458846708334703 OFFENSIVE_LOG_CHANNEL = 1353940560771027034 DEFENSIVE_LOG_CHANNEL = 1353940670246686843 @@ -96,10 +98,11 @@ class WarMonitor(commands.Cog): @commands.Cog.listener() async def on_ready(self): - category = await self.bot.fetch_channel(CATEGORY) - 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) + # categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES] + # channels = [ch for cat in categories for ch in cat.text_channels] + # war_ids = [ch.name.split("-")[-1] for ch in channels] + # war_ids = [int(x) for x in war_ids if x.isdigit()] + # self.monitored_wars.extend(war_ids) await self.set_allied_nations() self.war_check.start() self.reload_subscriptions.start() @@ -117,8 +120,9 @@ class WarMonitor(commands.Cog): self.war_create_task = self.bot.loop.create_task(self.war_create_subscription()) self.war_update_task = self.bot.loop.create_task(self.war_update_subscription()) self.war_attacks_task = self.bot.loop.create_task(self.warattack_subscription()) - category = await self.bot.fetch_channel(CATEGORY) - war_ids = [ch.name.split("-")[-1] for ch in category.text_channels] + categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES] + channels = [ch for cat in categories for ch in cat.text_channels] + war_ids = [ch.name.split("-")[-1] for ch in channels] war_ids = [int(x) for x in war_ids if x.isdigit()] self.monitored_wars.extend(war_ids) @@ -208,8 +212,9 @@ class WarMonitor(commands.Cog): async def get_war_channel(self, id: int) -> discord.TextChannel: id = str(id) - category = await self.bot.fetch_channel(CATEGORY) - channel = [c for c in category.text_channels if id in c.name] + categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES] + channels = [ch for cat in categories for ch in cat.text_channels] + channel = [c for c in channels if id in c.name] if channel: channel = channel[0] return channel @@ -320,13 +325,18 @@ class WarMonitor(commands.Cog): return if war.id not in self.monitored_wars: self.monitored_wars.append(war.id) - category = await self.bot.fetch_channel(CATEGORY) + categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES] + ch_count = sum([len(cat.text_channels) for cat in categories]) attacker, defender = await get_nation(self.kit, [war.att_id, war.def_id]) if defender.alliance_position.name == "APPLICANT": return + # try creating channels + pos = ch_count // 50 + category = categories[pos] channel = await category.create_text_channel( name=f"{attacker.nation_name.lower()}-{war.id}" ) + atk_card = await self.build_nation_card(attacker, discord.Color.red()) def_card = await self.build_nation_card(defender, discord.Color.green()) war_card = await self.build_war_card(war) @@ -506,13 +516,18 @@ class WarMonitor(commands.Cog): @commands.has_permissions(administrator=True) @commands.has_role("The Croak Council") async def archive(self, ctx: CustomCtx): - category = await self.bot.fetch_channel(CATEGORY) - if ctx.channel not in category.text_channels: + categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES] + channels = [ch for cat in categories for ch in cat.text_channels] + if ctx.channel not in channels: await ctx.send(f"this command only works inside {category.name}") return - await ctx.channel.edit( - category=(await self.bot.fetch_channel(ARCHIVE_CATEGORY)) - ) + archive = await self.bot.fetch_channel(ARCHIVE_CATEGORY) + if len(archive.text_channels) == 50: + await ctx.send( + "> hit channel limit in archive, please delete some channels first" + ) + return + await ctx.channel.edit(category=archive) await ctx.channel.send( "> channel moved to archive, you can also do fr delete to delete the channel or fr delall to delete all channels in archive." ) @@ -523,8 +538,9 @@ class WarMonitor(commands.Cog): @commands.has_permissions(administrator=True) @commands.has_role("The Croak Council") async def addm(self, ctx: CustomCtx, *, member: discord.Member): - category = await self.bot.fetch_channel(CATEGORY) - if ctx.channel not in category.text_channels: + categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES] + channels = [ch for cat in categories for ch in cat.text_channels] + if ctx.channel not in channels: await ctx.send(f"this command only works inside {category.name}") return await ctx.channel.set_permissions( @@ -568,8 +584,9 @@ class WarMonitor(commands.Cog): @commands.command() async def inrange(self, ctx: CustomCtx): - category = await self.bot.fetch_channel(CATEGORY) - if ctx.channel not in category.text_channels: + categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES] + channels = [ch for cat in categories for ch in cat.text_channels] + if ctx.channel not in channels: await ctx.send( f"this command only works inside {category.name}", delete_after=5 )