Update bot name

This commit is contained in:
2025-06-09 02:00:33 +07:00
parent 64183fface
commit 26098d8c42
3 changed files with 88 additions and 10 deletions

View File

@@ -629,6 +629,20 @@ public class BotController : BaseController
}
}
// If the bot name is being changed, check for conflicts
var isNameChanging = !string.IsNullOrEmpty(request.Config.Name) &&
request.Config.Name != request.Identifier;
if (isNameChanging)
{
// Check if new name already exists
var existingBotWithNewName = bots.FirstOrDefault(b => b.Identifier == request.Config.Name);
if (existingBotWithNewName != null)
{
return BadRequest($"A bot with the name '{request.Config.Name}' already exists");
}
}
// Validate the money management if provided
if (request.Config.MoneyManagement != null)
{
@@ -662,19 +676,27 @@ public class BotController : BaseController
return BadRequest("CloseEarlyWhenProfitable requires MaxPositionTimeHours to be set");
}
// Update the bot configuration using the new method
// Update the bot configuration using the enhanced method
var success = await _botService.UpdateBotConfiguration(request.Identifier, request.Config);
if (success)
{
await _hubContext.Clients.All.SendAsync("SendNotification",
$"Bot {request.Identifier} configuration updated successfully by {user.Name}.", "Info");
var finalBotName = isNameChanging ? request.Config.Name : request.Identifier;
return Ok("Bot configuration updated successfully");
await _hubContext.Clients.All.SendAsync("SendNotification",
$"Bot {finalBotName} configuration updated successfully by {user.Name}." +
(isNameChanging ? $" (renamed from {request.Identifier})" : ""), "Info");
await NotifyBotSubscriberAsync();
return Ok(isNameChanging
? $"Bot configuration updated successfully and renamed to '{request.Config.Name}'"
: "Bot configuration updated successfully");
}
else
{
return BadRequest("Failed to update bot configuration");
return BadRequest("Failed to update bot configuration. " +
(isNameChanging ? "The new name might already be in use." : ""));
}
}
catch (Exception ex)