// -------- Functions -------- /// <summary> /// Handles the event and sends the responses to the channel if desired. /// </summary> /// <param name="line">The RAW line from IRC to check.</param> /// <param name="ircConfig">The irc config to use when parsing this line.</param> /// <param name="ircWriter">The way to write to the irc channel.</param> public void HandleEvent(string line, IIrcConfig ircConfig, IIrcWriter ircWriter) { ArgumentChecker.StringIsNotNullOrEmpty(line, nameof(line)); ArgumentChecker.IsNotNull(ircConfig, nameof(ircConfig)); ArgumentChecker.IsNotNull(ircWriter, nameof(ircWriter)); Match match = pattern.Match(line); if (match.Success) { string remoteUser = match.Groups["nick"].Value; // Don't fire if we were the ones to trigger the event. if (remoteUser.ToUpper() == ircConfig.Nick.ToUpper()) { return; } IrcResponse response = new IrcResponse( remoteUser, match.Groups["channel"].Value, string.Empty ); this.PartAction(ircWriter, response); } }
// -------- Functions -------- /// <summary> /// Handles the event. /// </summary> /// <param name="line">The RAW line from IRC to check.</param> /// <param name="ircConfig">The irc config to use when parsing this line.</param> /// <param name="ircWriter">The way to write to the irc channel.</param> public void HandleEvent(string line, IIrcConfig ircConfig, IIrcWriter ircWriter) { ArgumentChecker.StringIsNotNullOrEmpty(line, nameof(line)); ArgumentChecker.IsNotNull(ircConfig, nameof(ircConfig)); ArgumentChecker.IsNotNull(ircWriter, nameof(ircWriter)); IrcResponse response = new IrcResponse( string.Empty, string.Empty, line ); this.AllAction(ircWriter, response); }
// -------- Function -------- /// <summary> /// Fires the action if the line regex matches. /// </summary> /// <param name="line">The RAW line from IRC to check.</param> /// <param name="ircConfig">The irc config to use when parsing this line.</param> /// <param name="ircWriter">The way to write to the irc channel.</param> public void HandleEvent(string line, IIrcConfig ircConfig, IIrcWriter ircWriter) { ArgumentChecker.StringIsNotNullOrEmpty(line, nameof(line)); ArgumentChecker.IsNotNull(ircConfig, nameof(ircConfig)); ArgumentChecker.IsNotNull(ircWriter, nameof(ircWriter)); Match match = pattern.Match(line); if (match.Success) { string nick = match.Groups["nick"].Value; string channel = match.Groups["channel"].Value; string message = match.Groups["theIrcMessage"].Value; // If we are a bridge bot, we need to change // the nick and the channel foreach (string bridgeBotRegex in ircConfig.BridgeBots.Keys) { Match nameMatch = Regex.Match(nick, bridgeBotRegex); if (nameMatch.Success) { Match bridgeBotMatch = Regex.Match(message, ircConfig.BridgeBots[bridgeBotRegex]); // If the regex matches, then we'll update the nick and message // to be whatever came from the bridge. if (bridgeBotMatch.Success) { string newNick = bridgeBotMatch.Groups["bridgeUser"].Value; string newMessage = bridgeBotMatch.Groups["bridgeMessage"].Value; // Only change the nick anme and the message if the nick and the message aren't empty. if ((string.IsNullOrEmpty(newNick) == false) && (string.IsNullOrEmpty(newMessage) == false)) { nick = newNick; message = newMessage; } break; // We have our message, break out of the loop. } } } // Take the message from the PRIVMSG and see if it matches the regex this class is watching. // If not, return and do nothing. Match messageMatch = Regex.Match(message, this.LineRegex); if (messageMatch.Success == false) { return; } IrcResponse response = new IrcResponse( nick, channel, message ); // Return right away if the nick name from the remote user is our own. if ((this.RespondToSelf == false) && (response.RemoteUser.ToUpper() == ircConfig.Nick.ToUpper())) { return; } // Return right away if we only wish to respond on the channel we are listening on (ignore PMs). else if ((this.ResponseOption == ResponseOptions.RespondOnlyToChannel) && (response.Channel.ToUpper() != ircConfig.Channel.ToUpper())) { return; } // Return right away if we only wish to respond to Private Messages (the channel will be our nick name). else if ((this.ResponseOption == ResponseOptions.RespondOnlyToPMs) && (response.Channel.ToUpper() != ircConfig.Nick.ToUpper())) { return; } else { DateTime currentTime = DateTime.UtcNow; TimeSpan timeSpan = currentTime - this.LastEvent; // Only fire if our cooldown was long enough. Cooldown of zero means always fire. // Need to explictly say Cooldown == 0 since DateTime.UtcNow has a innacurracy of +/- 15ms. Therefore, // if the action happens too quickly, it can incorrectly not be triggered. if ((this.CoolDown == 0) || (timeSpan.TotalSeconds > this.CoolDown)) { this.LineAction(ircWriter, response); this.LastEvent = currentTime; } } } }