Sha256: 491156602906506a361efa28b91d726946c225d8769abe11ad4b4d0e0a704e2b

Contents?: true

Size: 1.91 KB

Versions: 6

Compression:

Stored size: 1.91 KB

Contents

module Jekyll
  module RpLogs
    class MIRCParser < RpLogs::Parser
      # Add this class to the parsing dictionary
      FORMAT_STR = "MIRC"
      RpLogGenerator.add self

      # Remember to change this for your date format
      # For example, this regex is for, mm dd yy[HH:nn] or 06 14 15[18:48]
      # The default mirc date format is HH:nn
      DATE_REGEXP = /(?<timestamp>\d\d \d\d \d\d\[\d\d:\d\d\])/
      # Also make sure to change this - http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html
      # If you are using the default mirc format, this should be "[%H:%M]"
      TIMESTAMP_FORMAT = "%m %d %y[%H:%M]"

      # Crappy but works
      USER_AT_HOST = /\(\w+@[^)]+\)/
      MSG = /(?<msg>[^\n]*)/
      # The ()?((?=\d{4})(\d\d))? bit of code is to remove the  and two random numbers in front of lines.
      # This assumes that you have a two digit date code stating your time stamp.
      JUNK = /()?((?=\d{4})(\d\d))?#{DATE_REGEXP} \* #{MODE}#{NICK} (sets mode:|is now known as|(#{USER_AT_HOST} (has joined|Quit|has left))).*$/
      EMOTE = /^#{FLAGS}()?((?=\d{4})(\d\d))?#{DATE_REGEXP}\s\*\s#{MODE}#{NICK}\s+#{MSG}$/
      TEXT  = /^#{FLAGS}()?((?=\d{4})(\d\d))?#{DATE_REGEXP}\s<#{MODE}#{NICK}>\s#{MSG}$/

      def self.parse_line(line, options = {})
        case line
        when JUNK
          return nil
        when EMOTE
          type = :rp
        when TEXT
          type = :ooc
          mode = $LAST_MATCH_INFO[:mode]
          mode = " " if mode == ""
        else
          # Only put text and emotes in the log
          return nil
        end
        date = DateTime.strptime($LAST_MATCH_INFO[:timestamp], TIMESTAMP_FORMAT)
        LogLine.new(
          date,
          options,
          sender: $LAST_MATCH_INFO[:nick],
          contents: $LAST_MATCH_INFO[:msg],
          flags: $LAST_MATCH_INFO[:flags],
          type: type,
          mode: mode
        )
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jekyll-rp_logs-0.5.0 lib/jekyll/rp_logs/parsers/mirc.rb
jekyll-rp_logs-0.4.0 lib/jekyll/rp_logs/parse_mirc.rb
jekyll-rp_logs-0.3.1 lib/jekyll/rp_logs/parse_mirc.rb
jekyll-rp_logs-0.3.0 lib/jekyll/rp_logs/parse_mirc.rb
jekyll-rp_logs-0.2.1 lib/jekyll/rp_logs/parse_mirc.rb
jekyll-rp_logs-0.2.0 lib/jekyll/rp_logs/parse_mirc.rb