Example #1
0
 function reportEvent($event_name, $source, $arg1 = "", $arg2 = "", $arg3 = "", $arg4 = "", $arg5 = "", $is_command = false)
 {
     if (!$is_command && !REPORT_EVENTS || $is_command && !REPORT_COMMANDS) {
         return;
     }
     if ($is_command) {
         $channel = COMMAND_CHANNEL;
     } else {
         $channel = EVENT_CHANNEL;
     }
     $bot = $this->default_bot;
     if (isServer($source)) {
         $source = BOLD_START . $source->getNameAbbrev(NICK_LEN) . BOLD_END;
     } elseif (isUser($source)) {
         $source = $source->getNick();
     }
     for ($i = 1; $i <= 5; $i++) {
         eval('$arg = $arg' . $i . ';');
         if (!is_object($arg)) {
             continue;
         }
         if (isServer($arg) || isChannel($arg)) {
             $arg = $arg->getName();
         } elseif (isUser($arg)) {
             $arg = $arg->getNick();
         }
         eval('$arg' . $i . ' = $arg;');
     }
     if (strlen($source) > NICK_LEN) {
         $source = substr($source, 0, NICK_LEN);
     }
     $margin = substr_count($source, BOLD_START);
     $misc = $arg1 . ' ' . $arg2 . ' ' . $arg3 . ' ' . $arg4 . ' ' . $arg5;
     $misc = trim($misc);
     if (!$this->finished_burst) {
         $this->pending_events[] = array('chan_name' => $channel, 'margin' => $margin, 'source' => $source, 'event_name' => $event_name, 'misc' => $misc);
     }
     $bot->messagef($channel, '[%' . (NICK_LEN + $margin) . 's] %s %s', $source, $event_name, $misc);
     /*
     			if ($this->finished_burst)
     				$bot->messagef($channel, "[%". (NICK_LEN + $margin) ."s] %s %s", $source, $event_name, $misc);
     */
     return true;
 }
Example #2
0
 function isBadchan($chan_name)
 {
     if (isChannel($chan_name)) {
         $chan_name = $chan_name->getName();
     }
     foreach ($this->db_badchans as $b_key => $badchan) {
         if ($badchan->matches($chan_name)) {
             return true;
         }
     }
     return false;
 }
 /**
  * sendMode
  * This method simply formats and sends along a mode change string
  * to sendModeLine for further processing.
  */
 function sendMode($source, $chan_name, $modes)
 {
     if (isServer($source) || isUser($source)) {
         $source = $source->getNumeric();
     }
     if (isChannel($chan_name)) {
         $chan_name = $chan_name->getName();
     }
     $mode_line = irc_sprintf(FMT_MODE_NOTS, $source, $chan_name, $modes);
     $this->sendModeLine($mode_line);
 }
/**
 * irc_vsprintf: Identical to vsprintf, except extended to allow the IRC-specific
 * conversion specifiers documented with irc_sprintf.
 */
function irc_vsprintf($format, $args)
{
    $std_types = 'bcdeufFosxX';
    $custom_types = 'ACHNU';
    $len = strlen($format);
    $arg_index = -1;
    $pct_count = 0;
    for ($i = 0; $i < $len - 1; $i++) {
        $char = $format[$i];
        $next = $format[$i + 1];
        if ($char == '%') {
            $pct_count++;
        } else {
            $pct_count = 0;
        }
        /**
         * Skip this character if we don't have the start of a spec yet, or
         * if we do and the following character is a '%', indicating that
         * vsprintf will simply substitute a percent sign.
         */
        if ($pct_count != 1 || $next == '%') {
            continue;
        }
        // Found a spec; hold its place
        $spec_start = $i;
        $spec_end = $i + 1;
        $type = '';
        /**
         * Loop through the characters immediately following so that we can
         * attempt to find the type of spec this is. The formatting flags will
         * be preserved, so we'll ignore them.
         */
        for ($j = $i + 1; $j < $len; $j++) {
            $tmp_char = $format[$j];
            $is_std_type = false !== strpos($std_types, $tmp_char);
            $is_cust_type = false !== strpos($custom_types, $tmp_char);
            if ($is_std_type || $is_cust_type) {
                // Found a valid standard or custom flag, mark its place and stop
                $type = $tmp_char;
                $arg_index++;
                $spec_end = $j;
                break;
            }
        }
        // If we found a custom type in this spec, process it accordingly
        if ($is_cust_type) {
            $arg_obj = $args[$arg_index];
            $cust_text = '';
            switch ($type) {
                /**
                 * %A: Flat array to string conversion
                 */
                case 'A':
                    $cust_text = implode(' ', $arg_obj);
                    break;
                    /**
                     * %H: Human-readable name of given object
                     */
                /**
                 * %H: Human-readable name of given object
                 */
                case 'C':
                case 'H':
                    if (isUser($arg_obj)) {
                        $cust_text = $arg_obj->getNick();
                    } elseif (isChannel($arg_obj) || isServer($arg_obj)) {
                        $cust_text = $arg_obj->getName();
                    } elseif (isGline($arg_obj)) {
                        $cust_text = $arg_obj->getMask();
                    }
                    break;
                    /**
                     * %N: ircu P10 numeric of given object
                     */
                /**
                 * %N: ircu P10 numeric of given object
                 */
                case 'N':
                    if (isUser($arg_obj) || isServer($arg_obj)) {
                        $cust_text = $arg_obj->getNumeric();
                    }
                    break;
                    /**
                     * %U: Account name of user or account object
                     */
                /**
                 * %U: Account name of user or account object
                 */
                case 'U':
                    if (isUser($arg_obj)) {
                        $cust_text = $arg_obj->getAccountName();
                    } elseif (isAccount($arg_obj)) {
                        $cust_text = $arg_obj->getName();
                    }
                    break;
                    /**
                     * I'm sorry, Dave, I'm afraid I can't do that.
                     * Will pass this unknown spec to vsprintf as-is.
                     */
                /**
                 * I'm sorry, Dave, I'm afraid I can't do that.
                 * Will pass this unknown spec to vsprintf as-is.
                 */
                default:
                    continue;
            }
            /**
             * Change the custom flag to an 's' (string) and replace the argument
             * with whatever string we determined was most appropriate for it.
             */
            $format[$spec_end] = 's';
            $args[$arg_index] = $cust_text;
            /**
             * No need to look at this entire spec anymore, so advance to the next
             * char after the end of the spec.
             */
            $i = $spec_end + 1;
        }
    }
    // vsprintf takes care of the standard flags.
    return vsprintf($format, $args);
}