<commit_before><?php

/**
 * Looks for Dxxxx, Txxxx and links to them.
 *
 * @group irc
 */
final class PhabricatorBotObjectNameHandler extends PhabricatorBotHandler {

  /**
   * Map of PHIDs to the last mention of them (as an epoch timestamp); prevents
   * us from spamming chat when a single object is discussed.
   */
  private $recentlyMentioned = array();

  public function receiveMessage(PhabricatorBotMessage $original_message) {

    static $jokes = array(
      'When Chuck Norris throws exceptions, it\'s across the room.',
      'Chuck Norris burst the dot com bubble.',
      'All browsers support the hex definitions #chuck and #norris for the colors black and blue.',
      'Chuck Norris can solve the Towers of Hanoi in one move.',
      'Project managers never ask Chuck Norris for estimations...ever.',
      '"It works on my machine" always holds true for Chuck Norris.',
      'When Chuck Norris is web surfing, websites get the message "Warning: Internet Explorer has deemed this user to be malicious or dangerous. Proceed?".',
      'Chuck Norris can divide by zero.',
      'Chuck Norris can access private methods.',
      'Chuck Norris can instantiate an abstract class.',
      'Chuck Norris has faster upstream than downstream because even data runs from him.',
      'No statement can catch the ChuckNorrisException.',
      'Chuck Norris can binary search unsorted data.',
      'Chuck Norris’s keyboard has the Any key.',
      'Chuck Norris can retrieve anything from /dev/null.',
      'Every programming language accepts "Chuck Norris" as the line terminator.',
    );

    switch ($original_message->getCommand()) {
    case 'MESSAGE':
      $message = $original_message->getBody();
      $matches = null;

      $paste_ids = array();
      $commit_names = array();
      $vote_ids = array();
      $file_ids = array();
      $object_names = array();
      $output = array();

      $pattern =
        '@'.
        '(?<!/)(?:^|\b)'.
        '(R2D2|C3PO|Chewbacca|Chuck Norris)'.
        '(?:\b|$)'.
        '@i';

      if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
          switch ($match[1]) {
            case 'R2D2':
              $output[$match[1]] = pht('beep hoop bop');
              break;
            case 'Chewbacca':
              $output[$match[1]] = pht('Uuuuuur Ahhhhhrrr Uhrrr Ahhhrrr Aaargh');
              break;
            case 'C3PO':
              $output[$match[1]] = pht('Excuse me sir, but might I inquire as to what\'s going on?');
              break;
            case '<NAME>':
              $output[$match[1]] = pht($jokes[array_rand($jokes)]);
              break;
          }
        }
      }

      $pattern =
        '@'.
        '(?<!/)(?:^|\b)'. // Negative lookbehind prevent matching "/D123".
        '([A-Z])(\d+)'.
        '(?:\b|$)'.
        '@';

      if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {<commit_msg>do not throttle the jokes as much<commit_after><?php

/**
 * Looks for Dxxxx, Txxxx and links to them.
 *
 * @group irc
 */
final class PhabricatorBotObjectNameHandler extends PhabricatorBotHandler {

  /**
   * Map of PHIDs to the last mention of them (as an epoch timestamp); prevents
   * us from spamming chat when a single object is discussed.
   */
  private $recentlyMentioned = array();

  public function receiveMessage(PhabricatorBotMessage $original_message) {

    static $jokes = array(
      'When <NAME> throws exceptions, it\'s across the room.',
      'Chuck Norris burst the dot com bubble.',
      'All browsers support the hex definitions #chuck and #norris for the colors black and blue.',
      'Chuck Norris can solve the Towers of Hanoi in one move.',
      'Project managers never ask Chuck Norris for estimations...ever.',
      '"It works on my machine" always holds true for Chuck Norris.',
      'When Chuck Norris is web surfing, websites get the message "Warning: Internet Explorer has deemed this user to be malicious or dangerous. Proceed?".',
      'Chuck Norris can divide by zero.',
      'Chuck Norris can access private methods.',
      'Chuck Norris can instantiate an abstract class.',
      'Chuck Norris has faster upstream than downstream because even data runs from him.',
      'No statement can catch the ChuckNorrisException.',
      'Chuck Norris can binary search unsorted data.',
      'Chuck Norris’s keyboard has the Any key.',
      'Chuck Norris can retrieve anything from /dev/null.',
      'Every programming language accepts "Chuck Norris" as the line terminator.',
    );

    switch ($original_message->getCommand()) {
    case 'MESSAGE':
      $message = $original_message->getBody();
      $matches = null;

      $paste_ids = array();
      $commit_names = array();
      $vote_ids = array();
      $file_ids = array();
      $object_names = array();
      $output = array();

      $pattern =
        '@'.
        '(?<!/)(?:^|\b)'.
        '(R2D2|C3PO|Chewbacca|Chuck Norris)'.
        '(?:\b|$)'.
        '@i';

      if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
          switch ($match[1]) {
            case 'R2D2':
              $output[$match[1]] = pht('beep hoop bop');
              break;
            case 'Chewbacca':
              $output[$match[1]] = pht('Uuuuuur Ahhhhhrrr Uhrrr Ahhhrrr Aaargh');
              break;
            case 'C3PO':
              $output[$match[1]] = pht('Excuse me sir, but might I inquire as to what\'s going on?');
              break;
            case 'Chuck Norris':
              $joke = array_rand($jokes);
              $output[$match[1] . $joke] = pht($jokes[$joke]);
              break;
          }
        }
      }

      $pattern =
        '@'.
        '(?<!/)(?:^|\b)'. // Negative lookbehind prevent matching "/D123".
        '([A-Z])(\d+)'.
        '(?:\b|$)'.
        '@';

      if (preg_match_all($pattern, $message, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
{'fraction_non_alphanumeric': 0.1299128432823549, 'fraction_numerical': 0.004604505837855616, 'mean_word_length': 2.3657996679579414, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3318032', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1737, 'n_words': 599}