Add username input to prompt submission; update event handler to include username in message formatting

This commit is contained in:
pacnpal
2025-02-25 20:27:15 -05:00
parent e8f57b976a
commit 5c38774e2f
4 changed files with 27 additions and 7 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -636,7 +636,7 @@ class EventHandler:
},
)
async def send_prompt_to_channel(self, prompt: str, channel_id: int) -> None:
async def send_prompt_to_channel(self, prompt: str, channel_id: int, username: str = "Web User") -> None:
"""Send a prompt to the LLM and post response in Discord channel."""
try:
# Get the channel
@@ -661,8 +661,8 @@ class EventHandler:
"id": str(self.bot.user.id),
},
"user_info": {
"name": "web_user",
"display_name": "Web User",
"name": username.lower().replace(" ", "_"),
"display_name": username,
"id": "0",
},
"timeout_env": "GLHF_TIMEOUT"
@@ -675,8 +675,8 @@ class EventHandler:
id=str(uuid.uuid4()),
author=SimpleNamespace(
id=0,
name="web_user",
display_name="Web User",
name=username.lower().replace(" ", "_"),
display_name=username,
bot=False,
discriminator="0000"
),

View File

@@ -39,6 +39,10 @@ async def send_prompt():
if not data or 'prompt' not in data:
return jsonify({'error': 'Missing prompt'}), 400
username = data.get('username', 'Web User')
if not username.strip():
username = 'Web User'
try:
channel_id = int(str(data.get('channel_id', '1198637345701285999')))
except (ValueError, TypeError):
@@ -48,8 +52,8 @@ async def send_prompt():
return jsonify({'error': 'Channel ID is required'}), 400
try:
# Attempt to send prompt to channel
await event_handler.send_prompt_to_channel(data['prompt'], channel_id)
# Attempt to send prompt to channel with username
await event_handler.send_prompt_to_channel(data['prompt'], channel_id, username=username)
return jsonify({
'status': 'processing',
'message': f'Prompt sent to channel {channel_id}'

View File

@@ -25,6 +25,20 @@
placeholder="Enter your prompt here..."
></textarea>
</div>
<div>
<label for="username" class="block text-sm font-medium text-gray-700 mb-1">
Username
</label>
<input
type="text"
id="username"
name="username"
class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500"
placeholder="Enter your username..."
required
>
</div>
<div>
<label for="channelId" class="block text-sm font-medium text-gray-700 mb-1">
@@ -66,6 +80,7 @@
e.preventDefault();
const prompt = document.getElementById('prompt').value;
const username = document.getElementById('username').value;
const channelId = document.getElementById('channelId').value;
const resultDiv = document.getElementById('result');
const resultMessage = document.getElementById('resultMessage');
@@ -78,6 +93,7 @@
},
body: JSON.stringify({
prompt: prompt,
username: username,
channel_id: channelId ? String(channelId) : "1198637345701285999"
})
});