Add support for account-notify cap

This commit is contained in:
Alexandre Oliveira 2017-10-13 12:56:25 -03:00
parent f0ffe47b67
commit 794812b946
7 changed files with 40 additions and 7 deletions

View File

@ -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));
}
}

View File

@ -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);

View File

@ -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];
}
}
}

View File

@ -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>

View File

@ -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;

View File

@ -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; }

View File

@ -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; }