コード例 #1
0
ファイル: ActionHandler.cs プロジェクト: Stefancanvas/Chaskis
        // ---------------- Function ----------------

        public void HandleEvent(HandlerArgs args)
        {
            ArgumentChecker.IsNotNull(args, nameof(args));

            PrivateMessageResult pmResult = this.pmHelper.ShouldSend(args);

            if (pmResult.ShouldSend == false)
            {
                return;
            }

            ActionHandlerArgs response = new ActionHandlerArgs(
                args.IrcWriter,
                pmResult.ParseResult.RemoteUser,
                pmResult.ParseResult.Channel,
                pmResult.ParseResult.Message,
                pmResult.Regex,
                pmResult.Match
                );

            this.LineAction(response);
        }
コード例 #2
0
        // ------------------------ Function ------------------------

        /// <summary>
        /// Fires the action if the line regex matches.
        /// </summary>
        public void HandleEvent(HandlerArgs args)
        {
            ArgumentChecker.IsNotNull(args, nameof(args));

            PrivateMessageParseResult parseResult = this.pmHelper.ParseAndCheckHandlerArgs(args);

            if (parseResult.Success == false)
            {
                return;
            }

            // Ensure none of the other PRIVMSG types match for their message.  If they do, THAT handler type
            // should fire, not this one.
            foreach (Regex regex in otherPrivmsgRegexes)
            {
                if (regex.IsMatch(parseResult.Message))
                {
                    return;
                }
            }

            // If we are a bridge bot, we need to change
            // the nick and the channel
            foreach (string bridgeBotRegex in args.IrcConfig.BridgeBots.Keys)
            {
                Match nameMatch = Regex.Match(parseResult.RemoteUser, bridgeBotRegex);
                if (nameMatch.Success)
                {
                    Match bridgeBotMatch = Regex.Match(parseResult.Message, args.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))
                        {
                            parseResult.RemoteUser = newNick;
                            parseResult.Message    = newMessage;
                        }

                        break;  // We have our message, break out of the loop.
                    }
                }
            }

            PrivateMessageResult pmResult = this.pmHelper.ShouldSend(args, parseResult);

            if (pmResult.ShouldSend == false)
            {
                return;
            }

            MessageHandlerArgs response = new MessageHandlerArgs(
                args.IrcWriter,
                pmResult.ParseResult.RemoteUser,
                pmResult.ParseResult.Channel,
                pmResult.ParseResult.Message,
                pmResult.Regex,
                pmResult.Match
                );

            this.LineAction(response);
        }