fix war channels logic
This commit is contained in:
1 parent
c1a8315145
commit
af3f98527f
2 files changed
+39
-20
No files matched your search
+3
-1
@@ -24,6 +24,8 @@ from utils.base import BasicView
|
|||||||
from utils.emojis import Emojis
|
from utils.emojis import Emojis
|
||||||
from utils.paginator import Paginator
|
from utils.paginator import Paginator
|
||||||
|
|
||||||
|
OFFSHORE_ID = 10198
|
||||||
|
|
||||||
|
|
||||||
class BaseMul:
|
class BaseMul:
|
||||||
money = 1000000
|
money = 1000000
|
||||||
@@ -177,7 +179,7 @@ class Banking(commands.Cog):
|
|||||||
await self.kit.mutation(
|
await self.kit.mutation(
|
||||||
"bankWithdraw",
|
"bankWithdraw",
|
||||||
{
|
{
|
||||||
"receiver": 10198,
|
"receiver": OFFSHORE_ID,
|
||||||
"receiver_type": 2,
|
"receiver_type": 2,
|
||||||
"money": resources.money,
|
"money": resources.money,
|
||||||
"food": resources.food,
|
"food": resources.food,
|
||||||
|
|||||||
+36
-19
@@ -4,6 +4,7 @@ import functools
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
import random
|
import random
|
||||||
@@ -11,6 +12,7 @@ from typing import List, Literal, Optional, Union
|
|||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
|
from discord.state import Channel
|
||||||
import pnwkit
|
import pnwkit
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
from discord.utils import format_dt
|
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
|
ALLIANCE_ID = 10177
|
||||||
GUILD = 1353930666311421952
|
GUILD = 1353930666311421952
|
||||||
CATEGORY = 1356240812861821048
|
CATEGORIES = [1356240812861821048, 1356240812861821048]
|
||||||
ARCHIVE_CATEGORY = 1367458846708334703
|
ARCHIVE_CATEGORY = 1367458846708334703
|
||||||
OFFENSIVE_LOG_CHANNEL = 1353940560771027034
|
OFFENSIVE_LOG_CHANNEL = 1353940560771027034
|
||||||
DEFENSIVE_LOG_CHANNEL = 1353940670246686843
|
DEFENSIVE_LOG_CHANNEL = 1353940670246686843
|
||||||
@@ -96,10 +98,11 @@ class WarMonitor(commands.Cog):
|
|||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
category = await self.bot.fetch_channel(CATEGORY)
|
# categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES]
|
||||||
war_ids = [ch.name.split("-")[-1] for ch in category.text_channels]
|
# channels = [ch for cat in categories for ch in cat.text_channels]
|
||||||
war_ids = [int(x) for x in war_ids if x.isdigit()]
|
# war_ids = [ch.name.split("-")[-1] for ch in channels]
|
||||||
self.monitored_wars.extend(war_ids)
|
# war_ids = [int(x) for x in war_ids if x.isdigit()]
|
||||||
|
# self.monitored_wars.extend(war_ids)
|
||||||
await self.set_allied_nations()
|
await self.set_allied_nations()
|
||||||
self.war_check.start()
|
self.war_check.start()
|
||||||
self.reload_subscriptions.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_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_update_task = self.bot.loop.create_task(self.war_update_subscription())
|
||||||
self.war_attacks_task = self.bot.loop.create_task(self.warattack_subscription())
|
self.war_attacks_task = self.bot.loop.create_task(self.warattack_subscription())
|
||||||
category = await self.bot.fetch_channel(CATEGORY)
|
categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES]
|
||||||
war_ids = [ch.name.split("-")[-1] for ch in category.text_channels]
|
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()]
|
war_ids = [int(x) for x in war_ids if x.isdigit()]
|
||||||
self.monitored_wars.extend(war_ids)
|
self.monitored_wars.extend(war_ids)
|
||||||
|
|
||||||
@@ -208,8 +212,9 @@ class WarMonitor(commands.Cog):
|
|||||||
|
|
||||||
async def get_war_channel(self, id: int) -> discord.TextChannel:
|
async def get_war_channel(self, id: int) -> discord.TextChannel:
|
||||||
id = str(id)
|
id = str(id)
|
||||||
category = await self.bot.fetch_channel(CATEGORY)
|
categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES]
|
||||||
channel = [c for c in category.text_channels if id in c.name]
|
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:
|
if channel:
|
||||||
channel = channel[0]
|
channel = channel[0]
|
||||||
return channel
|
return channel
|
||||||
@@ -320,13 +325,18 @@ class WarMonitor(commands.Cog):
|
|||||||
return
|
return
|
||||||
if war.id not in self.monitored_wars:
|
if war.id not in self.monitored_wars:
|
||||||
self.monitored_wars.append(war.id)
|
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])
|
attacker, defender = await get_nation(self.kit, [war.att_id, war.def_id])
|
||||||
if defender.alliance_position.name == "APPLICANT":
|
if defender.alliance_position.name == "APPLICANT":
|
||||||
return
|
return
|
||||||
|
# try creating channels
|
||||||
|
pos = ch_count // 50
|
||||||
|
category = categories[pos]
|
||||||
channel = await category.create_text_channel(
|
channel = await category.create_text_channel(
|
||||||
name=f"{attacker.nation_name.lower()}-{war.id}"
|
name=f"{attacker.nation_name.lower()}-{war.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
atk_card = await self.build_nation_card(attacker, discord.Color.red())
|
atk_card = await self.build_nation_card(attacker, discord.Color.red())
|
||||||
def_card = await self.build_nation_card(defender, discord.Color.green())
|
def_card = await self.build_nation_card(defender, discord.Color.green())
|
||||||
war_card = await self.build_war_card(war)
|
war_card = await self.build_war_card(war)
|
||||||
@@ -506,13 +516,18 @@ class WarMonitor(commands.Cog):
|
|||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
@commands.has_role("The Croak Council")
|
@commands.has_role("The Croak Council")
|
||||||
async def archive(self, ctx: CustomCtx):
|
async def archive(self, ctx: CustomCtx):
|
||||||
category = await self.bot.fetch_channel(CATEGORY)
|
categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES]
|
||||||
if ctx.channel not in category.text_channels:
|
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}")
|
await ctx.send(f"this command only works inside {category.name}")
|
||||||
return
|
return
|
||||||
await ctx.channel.edit(
|
archive = await self.bot.fetch_channel(ARCHIVE_CATEGORY)
|
||||||
category=(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(
|
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."
|
"> 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_permissions(administrator=True)
|
||||||
@commands.has_role("The Croak Council")
|
@commands.has_role("The Croak Council")
|
||||||
async def addm(self, ctx: CustomCtx, *, member: discord.Member):
|
async def addm(self, ctx: CustomCtx, *, member: discord.Member):
|
||||||
category = await self.bot.fetch_channel(CATEGORY)
|
categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES]
|
||||||
if ctx.channel not in category.text_channels:
|
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}")
|
await ctx.send(f"this command only works inside {category.name}")
|
||||||
return
|
return
|
||||||
await ctx.channel.set_permissions(
|
await ctx.channel.set_permissions(
|
||||||
@@ -568,8 +584,9 @@ class WarMonitor(commands.Cog):
|
|||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def inrange(self, ctx: CustomCtx):
|
async def inrange(self, ctx: CustomCtx):
|
||||||
category = await self.bot.fetch_channel(CATEGORY)
|
categories = [await self.bot.fetch_channel(cat) for cat in CATEGORIES]
|
||||||
if ctx.channel not in category.text_channels:
|
channels = [ch for cat in categories for ch in cat.text_channels]
|
||||||
|
if ctx.channel not in channels:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
f"this command only works inside {category.name}", delete_after=5
|
f"this command only works inside {category.name}", delete_after=5
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user