internal static Task HandleJoinMessage(IrcClient client, IrcMessage message) { if (message.Parameters.Length > 0) { string channelName = message.Parameters[0].Substring(1); var hostMask = IrcHostMask.Parse(message.Prefix); if (hostMask != null) { IrcChannel channel; var user = new IrcUser(client, hostMask); if (!client.Channels.ContainsKey(channelName)) { // The client joined the channel. if (client is TwitchIrcClient) { channel = new TwitchChannel(client, channelName); client.Channels.Add(channelName, channel); // Return to not fire the ChannelJoined event and let the ROOMSTATE message handler handle it. return(Task.CompletedTask); } channel = new IrcChannel(client, channelName); client.Channels.Add(channelName, channel); client.User.Update(hostMask); } else { channel = client.Channels[channelName]; } var e = new IrcUserEventArgs(channel, user); client.OnChannelJoined(e); } else { throw new IrcProtocolException("Invalid source."); } } else { throw new IrcProtocolException("1 parameter is required to determine the channel."); } return(Task.CompletedTask); }
internal static Task HandleNickMessage(IrcClient client, IrcMessage message) { if (message.Parameters.Length == 1) { string newNickname = message.Parameters[0]; var hostMask = IrcHostMask.Parse(message.Prefix); var user = new IrcUser(client, hostMask); if (user == client.User) { client.User.NickName = newNickname; } } return(Task.CompletedTask); }
internal static Task HandlePartMessage(IrcClient client, IrcMessage message) { if (message.Parameters.Length > 0) { string channelName = message.Parameters[0].Substring(1); if (client.Channels.ContainsKey(channelName)) { var hostMask = IrcHostMask.Parse(message.Prefix); if (hostMask != null) { var user = new IrcUser(client, IrcHostMask.Parse(message.Prefix)); var channel = client.Channels[channelName]; //The local user left the channel. if (Equals(client.User, user)) { client.Channels.Remove(channelName); client.OnChannelLeft(new IrcChannelEventArgs(client, channel)); } else { var e = new IrcUserEventArgs(channel, user); channel.OnUserLeft(e); } } else { throw new IrcProtocolException("Invalid source."); } } else { throw new IrcProtocolException("PART message received from a channel the client is not present in."); } } else { throw new IrcProtocolException("1 parameter is required to determine the channel."); } return(Task.CompletedTask); }
/// <summary> /// Initializes a new instance of <see cref="IrcUser"/> /// </summary> /// <param name="hostMask">The parsed hostmask of the user</param> public IrcUser(IrcClient client, IrcHostMask hostMask) : this(client, hostMask.NickName, hostMask.Ident, hostMask.Host) { }
public void Update(IrcHostMask hostMask) { NickName = hostMask.NickName; Ident = hostMask.Ident; Host = hostMask.Host; }
public TwitchUser(IrcClient client, IrcHostMask hostMask, Dictionary <string, string> tags) : base(client, hostMask) { Init(tags); }
/// <summary> /// Initializes a new instance of <see cref="IrcTargetedMessage"/>. /// </summary> /// <param name="message"></param> public IrcTargetedMessage(IrcClient client, IrcMessage message) { if (message.Prefix == null) { throw new ArgumentException("Message contains no prefix."); } if (message.Parameters.Length < 2) { throw new ArgumentException("The message needs to have 2 parameters to specify the target and the message."); } if (message.Command == "PRIVMSG") { Type = MessageType.Privmsg; } else if (message.Command == "NOTICE") { Type = MessageType.Notice; } else { Type = MessageType.Unknown; } IrcHostMask hostMask = IrcHostMask.Parse(message.Prefix); if (hostMask != null) { if (client is TwitchIrcClient) { Source = new TwitchUser(client, hostMask, message.Tags); } else { Source = new IrcUser(client, hostMask); } } else { Source = new IrcServer(message.Prefix); } if (message.Parameters[0].StartsWith("#")) { string channelName = message.Parameters[0].Substring(1); if (client.Channels.ContainsKey(channelName)) { Target = client.Channels[channelName]; } else { Debug.WriteLine("[IrcTargetedMessage] Could not find the targeted channel in the client's channels list."); } IsChannelMessage = true; } else { Target = client.User; } Tags = message.Tags; Message = message.Parameters[1]; Client = client; }