fix war channels logic

This commit is contained in:
un1xx committed 2025-11-02 11:50:48 +05:30
1 parent c1a8315145
commit af3f98527f
2 files changed
+39 -20

No files matched your search

+36 -19
View File
@@ -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
)