fix slow mode and nsfw in channel creation
This commit is contained in:
parent
430fac4ed2
commit
0b5f18b69a
2 changed files with 41 additions and 19 deletions
|
|
@ -261,19 +261,13 @@ class MigrationEngine:
|
||||||
for ch in channels:
|
for ch in channels:
|
||||||
discord_id = str(ch.id)
|
discord_id = str(ch.id)
|
||||||
fluxer_id = self.state.get_fluxer_channel_id(discord_id)
|
fluxer_id = self.state.get_fluxer_channel_id(discord_id)
|
||||||
discord_parent_id = str(ch.category_id) if ch.category_id else None
|
|
||||||
|
|
||||||
if force or not fluxer_id:
|
if force or not fluxer_id:
|
||||||
# We'll resolve the parent_id in the loop after categories are created
|
# We'll resolve the parent_id in the loop after categories are created
|
||||||
channels_to_create.append(ch)
|
channels_to_create.append(ch)
|
||||||
else:
|
else:
|
||||||
current_fluxer_parent = fluxer_parent_map.get(fluxer_id)
|
# Always add to move/sync list to ensure properties (topic, nsfw, slowmode) are synced
|
||||||
# Case A: Its category is being created right now
|
# even if the parent category is already correct.
|
||||||
# Case B: It has a category that exists but is not set in Fluxer correctly
|
|
||||||
will_create_parent = discord_parent_id in missing_category_ids
|
|
||||||
expected_parent_fluxer_id = self.state.get_fluxer_category_id(discord_parent_id) if discord_parent_id else None
|
|
||||||
|
|
||||||
if will_create_parent or current_fluxer_parent != expected_parent_fluxer_id:
|
|
||||||
channels_to_move.append((ch, fluxer_id))
|
channels_to_move.append((ch, fluxer_id))
|
||||||
|
|
||||||
total = len(missing_categories) + len(channels_to_create) + len(channels_to_move)
|
total = len(missing_categories) + len(channels_to_create) + len(channels_to_move)
|
||||||
|
|
@ -303,6 +297,8 @@ class MigrationEngine:
|
||||||
nsfw = getattr(channel, 'nsfw', False)
|
nsfw = getattr(channel, 'nsfw', False)
|
||||||
slowmode = getattr(channel, 'slowmode_delay', 0)
|
slowmode = getattr(channel, 'slowmode_delay', 0)
|
||||||
|
|
||||||
|
logger.debug(f"Creating channel {channel.name}: topic={topic}, nsfw={nsfw}, slowmode={slowmode}")
|
||||||
|
|
||||||
parent_id = self.state.get_fluxer_category_id(str(channel.category_id)) if channel.category_id else None
|
parent_id = self.state.get_fluxer_category_id(str(channel.category_id)) if channel.category_id else None
|
||||||
|
|
||||||
fluxer_id = await self.fluxer_writer.create_channel(
|
fluxer_id = await self.fluxer_writer.create_channel(
|
||||||
|
|
@ -315,21 +311,36 @@ class MigrationEngine:
|
||||||
)
|
)
|
||||||
self.state.set_channel_mapping(state_key, fluxer_id)
|
self.state.set_channel_mapping(state_key, fluxer_id)
|
||||||
|
|
||||||
|
# Sync again immediately because some properties (like slowmode) are ignored on creation
|
||||||
|
await self.fluxer_writer.modify_channel(
|
||||||
|
channel_id=fluxer_id,
|
||||||
|
parent_id=parent_id,
|
||||||
|
name=channel.name,
|
||||||
|
topic=topic,
|
||||||
|
nsfw=nsfw,
|
||||||
|
slowmode_delay=slowmode
|
||||||
|
)
|
||||||
|
|
||||||
current_idx += 1
|
current_idx += 1
|
||||||
if progress_callback: await progress_callback(channel.name, "Copying", current_idx, total)
|
if progress_callback: await progress_callback(channel.name, "Copying", current_idx, total)
|
||||||
await asyncio.sleep(self.config.migration.rate_limit_delay_seconds)
|
await asyncio.sleep(self.config.migration.rate_limit_delay_seconds)
|
||||||
|
|
||||||
# Move existing channels if needed
|
# Move/Sync existing channels
|
||||||
for channel, fluxer_id in channels_to_move:
|
for channel, fluxer_id in channels_to_move:
|
||||||
if not self.is_running: break
|
if not self.is_running: break
|
||||||
|
|
||||||
parent_id = self.state.get_fluxer_category_id(str(channel.category_id)) if channel.category_id else None
|
parent_id = self.state.get_fluxer_category_id(str(channel.category_id)) if channel.category_id else None
|
||||||
nsfw = getattr(channel, 'nsfw', False)
|
nsfw = getattr(channel, 'nsfw', False)
|
||||||
slowmode = getattr(channel, 'slowmode_delay', 0)
|
slowmode = getattr(channel, 'slowmode_delay', 0)
|
||||||
|
topic = getattr(channel, 'topic', "") or ""
|
||||||
|
|
||||||
|
logger.debug(f"Syncing existing channel {channel.name} ({fluxer_id}): topic={topic}, nsfw={nsfw}, slowmode={slowmode}")
|
||||||
|
|
||||||
await self.fluxer_writer.modify_channel(
|
await self.fluxer_writer.modify_channel(
|
||||||
channel_id=fluxer_id,
|
channel_id=fluxer_id,
|
||||||
parent_id=parent_id,
|
parent_id=parent_id,
|
||||||
|
name=channel.name,
|
||||||
|
topic=topic,
|
||||||
nsfw=nsfw,
|
nsfw=nsfw,
|
||||||
slowmode_delay=slowmode
|
slowmode_delay=slowmode
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional, List, Dict, Any
|
from typing import Optional, List, Dict, Any
|
||||||
from fluxer import Bot, Webhook
|
from fluxer import Bot, Webhook, Forbidden
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -162,6 +162,8 @@ class FluxerWriter:
|
||||||
"""
|
"""
|
||||||
assert self.client is not None
|
assert self.client is not None
|
||||||
|
|
||||||
|
logger.debug(f"Fluxer: Creating channel {name} (type {type}) with topic='{topic}', nsfw={nsfw}, slowmode={slowmode_delay}")
|
||||||
|
|
||||||
guild_channel = await self.client.create_guild_channel(
|
guild_channel = await self.client.create_guild_channel(
|
||||||
guild_id=self.community_id,
|
guild_id=self.community_id,
|
||||||
name=name,
|
name=name,
|
||||||
|
|
@ -178,6 +180,10 @@ class FluxerWriter:
|
||||||
Updates channel properties.
|
Updates channel properties.
|
||||||
"""
|
"""
|
||||||
assert self.client is not None
|
assert self.client is not None
|
||||||
|
|
||||||
|
logger.debug(f"Fluxer: Modifying channel {channel_id}: name={name}, topic='{topic}', parent_id={parent_id}, nsfw={nsfw}, slowmode={slowmode_delay}")
|
||||||
|
|
||||||
|
try:
|
||||||
await self.client.modify_channel(
|
await self.client.modify_channel(
|
||||||
channel_id=channel_id,
|
channel_id=channel_id,
|
||||||
name=name,
|
name=name,
|
||||||
|
|
@ -186,6 +192,11 @@ class FluxerWriter:
|
||||||
nsfw=nsfw,
|
nsfw=nsfw,
|
||||||
rate_limit_per_user=slowmode_delay
|
rate_limit_per_user=slowmode_delay
|
||||||
)
|
)
|
||||||
|
except Forbidden as e:
|
||||||
|
if getattr(e, 'code', None) == "NSFW_CONTENT_AGE_RESTRICTED":
|
||||||
|
logger.warning(f"Fluxer: Could not update certain properties (likely NSFW) on channel {channel_id}: {e.message}")
|
||||||
|
return False
|
||||||
|
raise
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def move_channel(self, channel_id: str, parent_id: Optional[str]) -> bool:
|
async def move_channel(self, channel_id: str, parent_id: Optional[str]) -> bool:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue