mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
I refactored Govor.Console to use the command pattern. Here's what I did:
- I implemented a command-based architecture for Govor.Console. - Each of your actions (e.g., login, send friend request, list friends) is now encapsulated in its own command class inheriting from BaseCommand. - I integrated friend-related functionalities (search, list, send/accept/reject request, block/unblock) using a mix of SignalR Hub and REST API calls. - I included admin functionalities for managing friendships (list all, list user's, remove). - I added a /help (-h) command to display available commands and their usage. - I refactored Program.cs to handle command parsing and execution. - I updated FriendsClient.cs, removing methods now handled directly by commands via SignalR. - I added SignalR event handlers for real-time notifications (friend requests, accepts, etc.).
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Govor.ConsoleClient.Commands
|
||||
{
|
||||
public class HelpCommand : BaseCommand
|
||||
{
|
||||
private readonly Dictionary<string, ICommand> _availableCommands;
|
||||
|
||||
// The HelpCommand needs access to the list of all commands to display their help messages.
|
||||
// This will be injected from Program.cs where the commands are registered.
|
||||
public HelpCommand(Dictionary<string, ICommand> availableCommands)
|
||||
{
|
||||
_availableCommands = availableCommands;
|
||||
}
|
||||
|
||||
public override Task ExecuteAsync(string? argument)
|
||||
{
|
||||
Console.WriteLine("Доступные команды:");
|
||||
if (!string.IsNullOrWhiteSpace(argument))
|
||||
{
|
||||
string commandKey = argument.StartsWith("/") ? argument : "/" + argument;
|
||||
if (_availableCommands.TryGetValue(commandKey.ToLower(), out var specificCommand))
|
||||
{
|
||||
Console.WriteLine(specificCommand.GetHelp());
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Команда '{argument}' не найдена. Введите /help для списка всех команд.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var commandEntry in _availableCommands.OrderBy(c => c.Key))
|
||||
{
|
||||
Console.WriteLine(commandEntry.Value.GetHelp());
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override string GetHelp()
|
||||
{
|
||||
return "/help [команда] - Показать список всех команд или помощь по конкретной команде.";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user