copy channel topic, slow mode & nsfw settings
This commit is contained in:
parent
ab31f889a4
commit
aa82c97329
3 changed files with 40 additions and 10 deletions
|
|
@ -299,14 +299,19 @@ class MigrationEngine:
|
|||
if not self.is_running: break
|
||||
|
||||
state_key = str(channel.id)
|
||||
topic = channel.topic if channel.topic else ""
|
||||
topic = getattr(channel, 'topic', "") or ""
|
||||
nsfw = getattr(channel, 'nsfw', False)
|
||||
slowmode = getattr(channel, 'slowmode_delay', 0)
|
||||
|
||||
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(
|
||||
name=channel.name,
|
||||
topic=topic,
|
||||
type=0,
|
||||
parent_id=parent_id
|
||||
parent_id=parent_id,
|
||||
nsfw=nsfw,
|
||||
slowmode_delay=slowmode
|
||||
)
|
||||
self.state.set_channel_mapping(state_key, fluxer_id)
|
||||
|
||||
|
|
@ -319,10 +324,18 @@ class MigrationEngine:
|
|||
if not self.is_running: break
|
||||
|
||||
parent_id = self.state.get_fluxer_category_id(str(channel.category_id)) if channel.category_id else None
|
||||
await self.fluxer_writer.move_channel(fluxer_id, parent_id)
|
||||
nsfw = getattr(channel, 'nsfw', False)
|
||||
slowmode = getattr(channel, 'slowmode_delay', 0)
|
||||
|
||||
await self.fluxer_writer.modify_channel(
|
||||
channel_id=fluxer_id,
|
||||
parent_id=parent_id,
|
||||
nsfw=nsfw,
|
||||
slowmode_delay=slowmode
|
||||
)
|
||||
|
||||
current_idx += 1
|
||||
if progress_callback: await progress_callback(channel.name, "Moving", current_idx, total)
|
||||
if progress_callback: await progress_callback(channel.name, "Syncing", current_idx, total)
|
||||
await asyncio.sleep(self.config.migration.rate_limit_delay_seconds)
|
||||
|
||||
async def sync_permissions(self, progress_callback: Callable[[str, int, int], Awaitable[None]] | None = None):
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ class FluxerWriter:
|
|||
"permissions": permissions
|
||||
}
|
||||
|
||||
async def create_channel(self, name: str, topic: str = "", type: int = 0, parent_id: Optional[str] = None) -> str:
|
||||
async def create_channel(self, name: str, topic: str = "", type: int = 0, parent_id: Optional[str] = None, nsfw: bool = False, slowmode_delay: int = 0) -> str:
|
||||
"""
|
||||
Creates a new channel in the target Fluxer community.
|
||||
Returns the new Fluxer channel ID.
|
||||
|
|
@ -167,21 +167,33 @@ class FluxerWriter:
|
|||
name=name,
|
||||
type=type,
|
||||
topic=topic or None,
|
||||
parent_id=parent_id
|
||||
parent_id=parent_id,
|
||||
nsfw=nsfw,
|
||||
rate_limit_per_user=slowmode_delay
|
||||
)
|
||||
return str(guild_channel["id"])
|
||||
|
||||
async def move_channel(self, channel_id: str, parent_id: Optional[str]) -> bool:
|
||||
async def modify_channel(self, channel_id: str, parent_id: Optional[str] = None, name: Optional[str] = None, topic: Optional[str] = None, nsfw: Optional[bool] = None, slowmode_delay: Optional[int] = None) -> bool:
|
||||
"""
|
||||
Updates the parent category of an existing channel.
|
||||
Updates channel properties.
|
||||
"""
|
||||
assert self.client is not None
|
||||
await self.client.modify_channel(
|
||||
channel_id=channel_id,
|
||||
parent_id=parent_id
|
||||
name=name,
|
||||
topic=topic,
|
||||
parent_id=parent_id,
|
||||
nsfw=nsfw,
|
||||
rate_limit_per_user=slowmode_delay
|
||||
)
|
||||
return True
|
||||
|
||||
async def move_channel(self, channel_id: str, parent_id: Optional[str]) -> bool:
|
||||
"""
|
||||
Backward compatibility for moving a channel to a category.
|
||||
"""
|
||||
return await self.modify_channel(channel_id, parent_id=parent_id)
|
||||
|
||||
async def get_channels(self) -> List[Dict[str, Any]]:
|
||||
"""Returns all channels in the community."""
|
||||
assert self.client is not None
|
||||
|
|
|
|||
|
|
@ -800,11 +800,16 @@ class MigrationCLI:
|
|||
parent_id = self.engine.state.get_fluxer_category_id(str(source_channel.category_id))
|
||||
|
||||
topic = getattr(source_channel, 'topic', "") or ""
|
||||
nsfw = getattr(source_channel, 'nsfw', False)
|
||||
slowmode = getattr(source_channel, 'slowmode_delay', 0)
|
||||
|
||||
new_id = await self.engine.fluxer_writer.create_channel(
|
||||
name=source_channel.name,
|
||||
topic=topic,
|
||||
type=0,
|
||||
parent_id=parent_id
|
||||
parent_id=parent_id,
|
||||
nsfw=nsfw,
|
||||
slowmode_delay=slowmode
|
||||
)
|
||||
if new_id:
|
||||
self.engine.state.set_channel_mapping(str(source_channel.id), new_id)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue