support file attachments via webhook
This commit is contained in:
parent
bfdd7b3411
commit
f078fe2cf5
3 changed files with 16 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
git+https://github.com/akarealemil/fluxer.py.git
|
git+https://github.com/rambros3d/fluxer.py.git # API wrapper for Fluxer
|
||||||
discord.py>=2.3.2
|
discord.py # API wrapper for Discord
|
||||||
rich>=13.7.0
|
rich # Terminal formatting and rich text
|
||||||
PyYAML>=6.0.1
|
PyYAML # YAML parsing and serialization
|
||||||
pydantic>=2.5.3 # Good for configuration validation and mapping
|
pydantic # Data validation using Python type hints
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
async def log_audit_event(context: MigrationContext, title: str, description: str, files: list[dict] | None = None) -> None:
|
async def log_audit_event(context: MigrationContext, title: str, description: str, files: list[dict] | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
Logs an event by sending a summary to the `#fluxer-reaper` audit channel.
|
Logs an event by sending a summary to the `#reaper-logs` audit channel.
|
||||||
If the channel does not exist, it will dynamically create it and hide it from @everyone.
|
If the channel does not exist, it will dynamically create it and hide it from @everyone.
|
||||||
"""
|
"""
|
||||||
# 1. Initialize or Validate channel
|
# 1. Initialize or Validate channel
|
||||||
|
|
@ -31,16 +31,16 @@ async def log_audit_event(context: MigrationContext, title: str, description: st
|
||||||
|
|
||||||
for ch in channels:
|
for ch in channels:
|
||||||
name = str(ch.get("name", "")).lower()
|
name = str(ch.get("name", "")).lower()
|
||||||
if name in ["fluxer-reaper", "fluxer_reaper"]:
|
if name in ["reaper-logs", "reaper_logs"]:
|
||||||
channel_id = str(ch.get("id"))
|
channel_id = str(ch.get("id"))
|
||||||
logger.info(f"Found existing audit channel: {channel_id}")
|
logger.info(f"Found existing audit channel: {channel_id}")
|
||||||
break
|
break
|
||||||
|
|
||||||
if not channel_id:
|
if not channel_id:
|
||||||
logger.info("Audit log channel not found. Creating #fluxer-reaper.")
|
logger.info("Audit log channel not found. Creating #reaper-logs.")
|
||||||
# Create channel
|
# Create channel
|
||||||
channel_id = await context.fluxer_writer.create_channel(
|
channel_id = await context.fluxer_writer.create_channel(
|
||||||
name="fluxer-reaper",
|
name="reaper-logs",
|
||||||
topic="Fluxer Reaper - Migration audit logs.",
|
topic="Fluxer Reaper - Migration audit logs.",
|
||||||
type=0
|
type=0
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -241,13 +241,14 @@ class FluxerWriter:
|
||||||
final_content = prefix + display_content if display_content else prefix
|
final_content = prefix + display_content if display_content else prefix
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Current limitation: fluxer.py execute_webhook doesn't support 'files' or 'message_reference' yet.
|
# Current limitation: fluxer.py execute_webhook doesn't support 'message_reference' yet.
|
||||||
# So if we have files OR a reply, we MUST use the bot's direct send method.
|
# So if we have a reply, we MUST use the bot's direct send method.
|
||||||
if webhook and not files and not reply_to_message_id:
|
if webhook and not reply_to_message_id:
|
||||||
msg = await webhook.send(
|
msg = await webhook.send(
|
||||||
content=final_content,
|
content=final_content,
|
||||||
username=f"{author_name} (discord)",
|
username=f"{author_name} (discord)",
|
||||||
avatar_url=author_avatar_url,
|
avatar_url=author_avatar_url,
|
||||||
|
files=files,
|
||||||
wait=True
|
wait=True
|
||||||
)
|
)
|
||||||
return str(msg.id) if msg else None
|
return str(msg.id) if msg else None
|
||||||
|
|
@ -437,7 +438,7 @@ class FluxerWriter:
|
||||||
sorted_channels = sorted(channels, key=lambda c: 0 if c.get("type") == 4 else -1)
|
sorted_channels = sorted(channels, key=lambda c: 0 if c.get("type") == 4 else -1)
|
||||||
for ch in sorted_channels:
|
for ch in sorted_channels:
|
||||||
name = str(ch.get("name", "")).lower()
|
name = str(ch.get("name", "")).lower()
|
||||||
if name in ["fluxer-reaper", "fluxer_reaper"]:
|
if name in ["reaper-logs", "reaper_logs"]:
|
||||||
logger.info(f"Danger Zone: Skipping deletion of audit channel {name}")
|
logger.info(f"Danger Zone: Skipping deletion of audit channel {name}")
|
||||||
total -= 1
|
total -= 1
|
||||||
continue
|
continue
|
||||||
|
|
@ -462,7 +463,7 @@ class FluxerWriter:
|
||||||
processed = 0
|
processed = 0
|
||||||
for ch in channels:
|
for ch in channels:
|
||||||
name = str(ch.get("name", "")).lower()
|
name = str(ch.get("name", "")).lower()
|
||||||
if name in ["fluxer-reaper", "fluxer_reaper"]:
|
if name in ["reaper-logs", "reaper_logs"]:
|
||||||
logger.info(f"Danger Zone: Skipping permission reset for audit channel {name}")
|
logger.info(f"Danger Zone: Skipping permission reset for audit channel {name}")
|
||||||
total -= 1
|
total -= 1
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue