private void Client_MessageReceived(object sender, MessageReceivedEventArgs e) { var ircMessage = new IrcMessage(e.Message); switch (ircMessage.Command) { case "001": OnLoggedIn(); break; case "JOIN": { string userName = ircMessage.GetUserName(); string channel = ircMessage.GetChannel(); if (UserName.Equals(userName)) { OnChannelJoined(channel); } else { OnUserJoined(userName, channel); } break; } case "PART": { string userName = ircMessage.GetUserName(); string channel = ircMessage.GetChannel(); if (UserName.Equals(userName)) { OnChannelParted(channel); } else { OnUserParted(userName, channel); } break; } case "PING": string serverAddress = ircMessage.GetParameterByIndex(0); OnPingReceived(serverAddress); break; case "MODE": var channelMode = new ChannelMode(ircMessage); OnChannelModeReceived(channelMode); break; default: OnUnprocessedIrcMessageReceived(ircMessage); break; } OnIrcMessageReceived(ircMessage); }
public TwitchChannelHost(IrcMessage message) { HostingChannel = message.GetChannel(); string[] parameters = message.GetParameterByIndex(1).Split(' '); if (!parameters[0].Equals("-")) { TargetChannel = $"#{parameters[0]}"; } if (int.TryParse(parameters[1], out int numberOfViewers)) { NumberOfViewers = numberOfViewers; } }
public TwitchHostedChannel(IrcMessage message) { string channel = message.GetChannel(); TargetChannel = $"#{channel}"; string jtvMessage = message.GetParameterByIndex(1); IsAutohost = jtvMessage.Contains("auto hosting"); string[] parameters = jtvMessage.Split(' '); if (int.TryParse(parameters[parameters.Length - 1], out int numberOfViewers)) { NumberOfViewers = numberOfViewers; } HosterDisplayName = parameters[0]; }
protected override void OnUnprocessedIrcMessageReceived(IrcMessage message) { switch (message.Command) { case "GLOBALUSERSTATE": var globalUserState = new TwitchGlobalUserState(message); OnGlobalUserStateReceived(globalUserState); break; case "PRIVMSG": if (message.GetUserName().Equals("jtv")) { var hostedChannel = new TwitchHostedChannel(message); OnChannelBeingHosted(hostedChannel); } else { var chatMessage = new TwitchChatMessage(message); OnChatMessageReceived(chatMessage); } break; case "WHISPER": var whisperMessage = new TwitchWhisperMessage(message); OnWhisperMessageReceived(whisperMessage); break; case "ROOMSTATE": var channelState = new TwitchChannelState(message); OnChannelStateChanged(channelState); break; case "USERSTATE": var userState = new TwitchUserState(message); OnUserStateReceived(userState); break; case "USERNOTICE": FireAnEventBasedOnUserNoticeType(message); break; case "HOSTTARGET": var channelHost = new TwitchChannelHost(message); if (!string.IsNullOrEmpty(channelHost.TargetChannel)) { OnChannelHostingStarted(channelHost); } else { OnChannelHostingStopped(channelHost); } break; case "CLEARCHAT": if (message.Tags.ContainsKey("ban-duration")) { var userTimeout = new TwitchUserTimeout(message); OnUserTimedOut(userTimeout); } else if (message.Tags.ContainsKey("ban-reason")) { var userBan = new TwitchUserBan(message); OnUserBanned(userBan); } else { string channel = message.GetChannel(); OnChatCleared(channel); } break; default: base.OnUnprocessedIrcMessageReceived(message); break; } }