sharp-chat/SharpChat.Protocol.IRC/ClientCommands/ListCommand.cs

32 lines
1.2 KiB
C#
Raw Permalink Normal View History

2022-08-30 15:05:29 +00:00
using SharpChat.Channels;
using SharpChat.Protocol.IRC.Replies;
using System;
namespace SharpChat.Protocol.IRC.ClientCommands {
public class ListCommand : IClientCommand {
public const string NAME = @"LIST";
public string CommandName => NAME;
public bool RequireSession => true;
public ChannelManager Channels { get; }
public ChannelUserRelations ChannelUsers { get; }
public ListCommand(ChannelManager channels, ChannelUserRelations channelUsers) {
Channels = channels ?? throw new ArgumentNullException(nameof(channels));
ChannelUsers = channelUsers ?? throw new ArgumentNullException(nameof(channelUsers));
}
public void HandleCommand(ClientCommandContext ctx) {
// todo: special LIST comments for Modern IRC
Channels.GetChannels(channels => { // probably needs to check if a user actually has access
foreach(IChannel channel in channels)
ChannelUsers.CountUsers(channel, userCount => ctx.Connection.SendReply(new ListItemReply(channel, userCount)));
ctx.Connection.SendReply(new ListEndReply());
});
}
}
}