From 0b5f18b69a6cb829038cecc9312979530cb8adc7 Mon Sep 17 00:00:00 2001 From: rambros Date: Sun, 22 Feb 2026 22:45:22 +0530 Subject: [PATCH] fix slow mode and nsfw in channel creation --- src/core/engine.py | 31 +++++++++++++++++++++---------- src/fluxer_bot/writer.py | 29 ++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/core/engine.py b/src/core/engine.py index 299e566..8c4cd79 100644 --- a/src/core/engine.py +++ b/src/core/engine.py @@ -261,20 +261,14 @@ class MigrationEngine: for ch in channels: discord_id = str(ch.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: # We'll resolve the parent_id in the loop after categories are created channels_to_create.append(ch) else: - current_fluxer_parent = fluxer_parent_map.get(fluxer_id) - # Case A: Its category is being created right now - # 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)) + # Always add to move/sync list to ensure properties (topic, nsfw, slowmode) are synced + # even if the parent category is already correct. + channels_to_move.append((ch, fluxer_id)) total = len(missing_categories) + len(channels_to_create) + len(channels_to_move) current_idx = 0 @@ -303,6 +297,8 @@ class MigrationEngine: nsfw = getattr(channel, 'nsfw', False) 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 fluxer_id = await self.fluxer_writer.create_channel( @@ -315,21 +311,36 @@ class MigrationEngine: ) 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 if progress_callback: await progress_callback(channel.name, "Copying", current_idx, total) 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: if not self.is_running: break parent_id = self.state.get_fluxer_category_id(str(channel.category_id)) if channel.category_id else None nsfw = getattr(channel, 'nsfw', False) 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( channel_id=fluxer_id, parent_id=parent_id, + name=channel.name, + topic=topic, nsfw=nsfw, slowmode_delay=slowmode ) diff --git a/src/fluxer_bot/writer.py b/src/fluxer_bot/writer.py index 90ea5d2..f2d0517 100644 --- a/src/fluxer_bot/writer.py +++ b/src/fluxer_bot/writer.py @@ -1,7 +1,7 @@ import asyncio import logging from typing import Optional, List, Dict, Any -from fluxer import Bot, Webhook +from fluxer import Bot, Webhook, Forbidden logger = logging.getLogger(__name__) @@ -162,6 +162,8 @@ class FluxerWriter: """ 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_id=self.community_id, name=name, @@ -178,14 +180,23 @@ class FluxerWriter: Updates channel properties. """ assert self.client is not None - await self.client.modify_channel( - channel_id=channel_id, - name=name, - topic=topic, - parent_id=parent_id, - nsfw=nsfw, - rate_limit_per_user=slowmode_delay - ) + + 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( + channel_id=channel_id, + name=name, + topic=topic, + parent_id=parent_id, + nsfw=nsfw, + 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 async def move_channel(self, channel_id: str, parent_id: Optional[str]) -> bool: