Add reply functionality to manual message override with mention control
- Added optional reply message ID field to web UI
- Added radio buttons to control mention/ping behavior in replies
- Updated frontend JavaScript to send reply parameters
- Modified /manual/send and /dm/{user_id}/manual endpoints to support replies
- Fixed async context by moving message fetching inside bot event loop task
- Supports both channel and DM reply functionality
This commit is contained in:
43
bot/api.py
43
bot/api.py
@@ -493,7 +493,9 @@ async def reset_role_color_to_fallback():
|
||||
async def manual_send(
|
||||
message: str = Form(...),
|
||||
channel_id: str = Form(...),
|
||||
files: List[UploadFile] = File(default=[])
|
||||
files: List[UploadFile] = File(default=[]),
|
||||
reply_to_message_id: str = Form(None),
|
||||
mention_author: bool = Form(True)
|
||||
):
|
||||
try:
|
||||
channel = globals.client.get_channel(int(channel_id))
|
||||
@@ -516,10 +518,23 @@ async def manual_send(
|
||||
# Use create_task to avoid timeout context manager error
|
||||
async def send_message_and_files():
|
||||
try:
|
||||
# Get the reference message if replying (must be done inside the task)
|
||||
reference_message = None
|
||||
if reply_to_message_id:
|
||||
try:
|
||||
reference_message = await channel.fetch_message(int(reply_to_message_id))
|
||||
except Exception as e:
|
||||
print(f"⚠️ Could not fetch message {reply_to_message_id} for reply: {e}")
|
||||
return
|
||||
|
||||
# Send the main message
|
||||
if message.strip():
|
||||
await channel.send(message)
|
||||
print(f"✅ Manual message sent to #{channel.name}")
|
||||
if reference_message:
|
||||
await channel.send(message, reference=reference_message, mention_author=mention_author)
|
||||
print(f"✅ Manual message sent as reply to #{channel.name}")
|
||||
else:
|
||||
await channel.send(message)
|
||||
print(f"✅ Manual message sent to #{channel.name}")
|
||||
|
||||
# Send files if any
|
||||
for file_info in file_data:
|
||||
@@ -886,7 +901,9 @@ async def send_custom_prompt_dm(user_id: str, req: CustomPromptRequest):
|
||||
async def send_manual_message_dm(
|
||||
user_id: str,
|
||||
message: str = Form(...),
|
||||
files: List[UploadFile] = File(default=[])
|
||||
files: List[UploadFile] = File(default=[]),
|
||||
reply_to_message_id: str = Form(None),
|
||||
mention_author: bool = Form(True)
|
||||
):
|
||||
"""Send manual message via DM to a specific user"""
|
||||
try:
|
||||
@@ -910,10 +927,24 @@ async def send_manual_message_dm(
|
||||
|
||||
async def send_dm_message_and_files():
|
||||
try:
|
||||
# Get the reference message if replying (must be done inside the task)
|
||||
reference_message = None
|
||||
if reply_to_message_id:
|
||||
try:
|
||||
dm_channel = user.dm_channel or await user.create_dm()
|
||||
reference_message = await dm_channel.fetch_message(int(reply_to_message_id))
|
||||
except Exception as e:
|
||||
print(f"⚠️ Could not fetch DM message {reply_to_message_id} for reply: {e}")
|
||||
return
|
||||
|
||||
# Send the main message
|
||||
if message.strip():
|
||||
await user.send(message)
|
||||
print(f"✅ Manual DM message sent to user {user_id}")
|
||||
if reference_message:
|
||||
await user.send(message, reference=reference_message, mention_author=mention_author)
|
||||
print(f"✅ Manual DM reply message sent to user {user_id}")
|
||||
else:
|
||||
await user.send(message)
|
||||
print(f"✅ Manual DM message sent to user {user_id}")
|
||||
|
||||
# Send files if any
|
||||
for file_info in file_data:
|
||||
|
||||
Reference in New Issue
Block a user