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 HandleRommstateMessage(IrcClient client, IrcMessage message) { string channelName = message.Parameters[0].Substring(1); TwitchChannel channel = (TwitchChannel)client.Channels[channelName]; if (message.Tags.ContainsKey("emote-only") && int.TryParse(message.Tags["emote-only"], out int emoteOnlyMode)) { channel.EmoteOnlyMode = emoteOnlyMode == 1; } if (message.Tags.ContainsKey("followers-only") && int.TryParse(message.Tags["followers-only"], out int followersOnlyModeMinutes)) { channel.FollowersOnlyMode = followersOnlyModeMinutes != -1; channel.FollowersOnlyModeMinutes = followersOnlyModeMinutes; } if (message.Tags.ContainsKey("r9k") && int.TryParse(message.Tags["r9k"], out int r9kMode)) { channel.R9KMode = r9kMode == 1; } if (message.Tags.ContainsKey("slow") && int.TryParse(message.Tags["slow"], out int slowModeSeconds)) { channel.SlowModeSeconds = slowModeSeconds; } if (message.Tags.ContainsKey("subs-only") && int.TryParse(message.Tags["subs-only"], out int subscribersOnlyMode)) { channel.SubscribersOnlyMode = subscribersOnlyMode == 1; } if (!channel.ChannelJoinedEventFired) { // This is the first ROOMSTATE message for this channel received. // Fire the ChannelJoined event with a fully initialized TwitchChannel instance. var e = new IrcUserEventArgs(channel, client.User); client.OnChannelJoined(e); channel.ChannelJoinedEventFired = true; } return(Task.CompletedTask); }