fix issues
This commit is contained in:
@@ -246,7 +246,10 @@ namespace ChatBot.Services
|
||||
if (content.Length < _aiSettings.MinMessageLengthForSummarization)
|
||||
{
|
||||
return content.Length > _aiSettings.MaxSummarizedMessageLength
|
||||
? content.Substring(0, _aiSettings.MaxSummarizedMessageLength) + "..."
|
||||
? string.Concat(
|
||||
content.AsSpan(0, _aiSettings.MaxSummarizedMessageLength),
|
||||
"..."
|
||||
)
|
||||
: content;
|
||||
}
|
||||
|
||||
@@ -267,10 +270,13 @@ namespace ChatBot.Services
|
||||
var summary = await GenerateSummaryAsync(summaryMessages, cancellationToken);
|
||||
|
||||
return string.IsNullOrEmpty(summary)
|
||||
? content.Substring(
|
||||
0,
|
||||
Math.Min(content.Length, _aiSettings.MaxSummarizedMessageLength)
|
||||
) + "..."
|
||||
? string.Concat(
|
||||
content.AsSpan(
|
||||
0,
|
||||
Math.Min(content.Length, _aiSettings.MaxSummarizedMessageLength)
|
||||
),
|
||||
"..."
|
||||
)
|
||||
: summary;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -345,7 +351,7 @@ namespace ChatBot.Services
|
||||
|
||||
var result = response.ToString().Trim();
|
||||
return result.Length > _aiSettings.MaxSummarizedMessageLength
|
||||
? result.Substring(0, _aiSettings.MaxSummarizedMessageLength) + "..."
|
||||
? string.Concat(result.AsSpan(0, _aiSettings.MaxSummarizedMessageLength), "...")
|
||||
: result;
|
||||
}
|
||||
|
||||
@@ -419,8 +425,10 @@ namespace ChatBot.Services
|
||||
return new ChatMessage
|
||||
{
|
||||
Role = message.Role,
|
||||
Content =
|
||||
message.Content.Substring(0, _aiSettings.MaxSummarizedMessageLength) + "...",
|
||||
Content = string.Concat(
|
||||
message.Content.AsSpan(0, _aiSettings.MaxSummarizedMessageLength),
|
||||
"..."
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ namespace ChatBot.Services.Telegram.Commands
|
||||
/// </summary>
|
||||
public class CommandRegistry
|
||||
{
|
||||
private readonly Dictionary<string, ITelegramCommand> _commands = new();
|
||||
private readonly Dictionary<string, ITelegramCommand> _commands = new(
|
||||
StringComparer.OrdinalIgnoreCase
|
||||
);
|
||||
private readonly ILogger<CommandRegistry> _logger;
|
||||
|
||||
public CommandRegistry(
|
||||
@@ -32,12 +34,9 @@ namespace ChatBot.Services.Telegram.Commands
|
||||
/// </summary>
|
||||
private void RegisterCommand(ITelegramCommand command)
|
||||
{
|
||||
if (command == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(command));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
var commandName = command.CommandName.ToLower();
|
||||
var commandName = command.CommandName;
|
||||
if (_commands.ContainsKey(commandName))
|
||||
{
|
||||
_logger.LogWarning("Command '{CommandName}' is already registered", commandName);
|
||||
@@ -53,8 +52,7 @@ namespace ChatBot.Services.Telegram.Commands
|
||||
/// </summary>
|
||||
public ITelegramCommand? GetCommand(string commandName)
|
||||
{
|
||||
var key = commandName.ToLower();
|
||||
return _commands.TryGetValue(key, out var command) ? command : null;
|
||||
return _commands.TryGetValue(commandName, out var command) ? command : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace ChatBot.Services.Telegram.Commands
|
||||
command = command.Split('@')[0];
|
||||
}
|
||||
|
||||
return command == CommandName.ToLower();
|
||||
return string.Equals(command, CommandName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace ChatBot.Services.Telegram.Services
|
||||
messageText,
|
||||
chatId,
|
||||
userName,
|
||||
message.Chat.Type.ToString().ToLower(),
|
||||
message.Chat.Type.ToString(),
|
||||
message.Chat.Title ?? "",
|
||||
replyInfo,
|
||||
cancellationToken
|
||||
|
||||
Reference in New Issue
Block a user