~sircmpwn/ChatSharp

794812b94668673eae6470c1f1df0e56706cce2f — Alexandre Oliveira 5 years ago f0ffe47
Add support for account-notify cap
M ChatSharp/Handlers/ChannelHandlers.cs => ChatSharp/Handlers/ChannelHandlers.cs +8 -0
@@ 18,6 18,14 @@ namespace ChatSharp.Handlers
                if (!user.Channels.Contains(channel))
                    user.Channels.Add(channel);

                // account-notify capability
                if (client.Capabilities.IsEnabled("account-notify"))
                    client.Who(user.Nick, WhoxFlag.None, WhoxField.Nick | WhoxField.AccountName, (whoQuery) =>
                    {
                        if (whoQuery.Count == 1)
                            user.Account = whoQuery[0].User.Account;
                    });

                client.OnUserJoinedChannel(new ChannelUserEventArgs(channel, user));
            }
        }

M ChatSharp/Handlers/MessageHandlers.cs => ChatSharp/Handlers/MessageHandlers.cs +1 -0
@@ 47,6 47,7 @@ namespace ChatSharp.Handlers
            client.SetHandler("319", UserHandlers.HandleWhoIsChannels);
            client.SetHandler("330", UserHandlers.HandleWhoIsLoggedInAs);
            client.SetHandler("354", UserHandlers.HandleWhox);
            client.SetHandler("ACCOUNT", UserHandlers.HandleAccount);

            // Listing handlers
            client.SetHandler("367", ListingHandlers.HandleBanListPart);

M ChatSharp/Handlers/UserHandlers.cs => ChatSharp/Handlers/UserHandlers.cs +7 -1
@@ 164,7 164,7 @@ namespace ChatSharp.Handlers

                    if ((fields & WhoxField.AccountName) != 0)
                    {
                        whox.Account = message.Parameters[fieldIdx];
                        whox.User.Account = message.Parameters[fieldIdx];
                        fieldIdx++;
                    }



@@ 198,5 198,11 @@ namespace ChatSharp.Handlers
            request.Callback?.Invoke(request);
            client.OnWhoxReceived(new Events.WhoxReceivedEventArgs(whoxList.ToArray()));
        }

        public static void HandleAccount(IrcClient client, IrcMessage message)
        {
            var user = client.Users.GetOrAdd(message.Prefix);
            user.Account = message.Parameters[0];
        }
    }
}

M ChatSharp/IrcClient.Commands.cs => ChatSharp/IrcClient.Commands.cs +16 -0
@@ 84,6 84,22 @@ namespace ChatSharp
                joinCmd += string.Format(" {0}", key);

            SendRawMessage(joinCmd, channel);

            // account-notify capability
            var flags = WhoxField.Nick | WhoxField.Hostname | WhoxField.AccountName | WhoxField.Username;

            if (Capabilities.IsEnabled("account-notify"))
                Who(channel, WhoxFlag.None, flags, (whoList) =>
                {
                    if (whoList.Count > 0)
                    {
                        foreach (var whoQuery in whoList)
                        {
                            var user = Users.GetOrAdd(whoQuery.User.Hostmask);
                            user.Account = whoQuery.User.Account;
                        }
                    }
                });
        }

        /// <summary>

M ChatSharp/IrcClient.cs => ChatSharp/IrcClient.cs +2 -1
@@ 168,7 168,8 @@ namespace ChatSharp

            // List of supported capabilities
            Capabilities.AddRange(new string[] {
                "server-time", "multi-prefix", "cap-notify", "znc.in/server-time", "znc.in/server-time-iso"
                "server-time", "multi-prefix", "cap-notify", "znc.in/server-time", "znc.in/server-time-iso",
                "account-notify"
            });

            IsNegotiatingCapabilities = false;

M ChatSharp/IrcUser.cs => ChatSharp/IrcUser.cs +6 -0
@@ 13,6 13,7 @@ namespace ChatSharp
        {
            Channels = new ChannelCollection();
            ChannelModes = new Dictionary<IrcChannel, List<char?>>();
            Account = "*";
        }

        /// <summary>


@@ 97,6 98,11 @@ namespace ChatSharp
        /// </summary>
        /// <value>The channels.</value>
        public ChannelCollection Channels { get; set; }
        /// <summary>
        /// The user's account. If 0 or *, the user is not logged in.
        /// Otherwise, the user is logged in with services.
        /// </summary>
        public string Account { get; set; }

        internal Dictionary<IrcChannel, List<char?>> ChannelModes { get; set; }


M ChatSharp/WhoX.cs => ChatSharp/WhoX.cs +0 -5
@@ 19,7 19,6 @@ namespace ChatSharp
            Flags = string.Empty;
            Hops = -1;
            TimeIdle = -1;
            Account = "*";
            OpLevel = "n/a";
        }



@@ 57,10 56,6 @@ namespace ChatSharp
        /// </summary>
        public int TimeIdle { get; internal set; }
        /// <summary>
        /// User account name (NickServ or similar)
        /// </summary>
        public string Account { get; internal set; }
        /// <summary>
        /// OP level of the user in the channel
        /// </summary>
        public string OpLevel { get; internal set; }