<commit_before>module Syslog2irc
  class SyslogListener
    def initialize(bot, port)
      @bot  = bot
      @listener = UDPSocket.new
      @listener.bind("0.0.0.0", port)
    end

    def start
      loop do
        begin
          data, meta = @listener.recvfrom(9000)
          parsed = SyslogProtocol.parse(data, meta[2])

          #puts "Blacklisted: #{parsed.content}\n" if Obscenity.profane?(parsed.content) # uncomment to see blacklisted message on cli
          next if Obscenity.profane?(parsed.content)
          next if Obscenity.profane?(parsed.tag)

          begin
            host = Resolv.getname(meta[2]).to_s
	        rescue
            host = meta[2].to_s
          end

          #puts parsed.inspect

          message = "#{StringIrc.new(parsed.severity_name.upcase).bold.to_s} #{StringIrc.new(host).bold.to_s} - #{parsed.tag if parsed.tag != 'unknown'} #{parsed.content}"
          case parsed.severity_name
          when 'notice'
            message = StringIrc.new(message).light_blue
          when 'info'
            message = StringIrc.new(message).blue
          when 'warn'
            message = StringIrc.new(message).yellow
          when 'error', 'alert', 'crit', 'err'
            message = StringIrc.new(message).red
          else
            message = StringIrc.new(message).green
          end

          @bot.handlers.dispatch(:syslog, nil, message.to_s)
        rescue Exception => ex
	        puts ex.message
  	      puts ex.backtrace.join("\n")
          @bot.handlers.dispatch(:syslog, nil, 'syslog exception')
          raise ex
        end
      end
    end
  end
end<commit_msg>show plain message on exception<commit_after>module Syslog2irc
  class SyslogListener
    def initialize(bot, port)
      @bot  = bot
      @listener = UDPSocket.new
      @listener.bind("0.0.0.0", port)
    end

    def start
      loop do
        begin
          data, meta = @listener.recvfrom(9000)
          parsed = SyslogProtocol.parse(data, meta[2])

          #puts "Blacklisted: #{parsed.content}\n" if Obscenity.profane?(parsed.content) # uncomment to see blacklisted message on cli
          next if Obscenity.profane?(parsed.content)
          next if Obscenity.profane?(parsed.tag)

          begin
            host = Resolv.getname(meta[2]).to_s
	        rescue
            host = meta[2].to_s
          end

          #puts parsed.inspect

          message = "#{StringIrc.new(parsed.severity_name.upcase).bold.to_s} #{StringIrc.new(host).bold.to_s} - #{parsed.tag if parsed.tag != 'unknown'} #{parsed.content}"
          case parsed.severity_name
          when 'notice'
            message = StringIrc.new(message).light_blue
          when 'info'
            message = StringIrc.new(message).blue
          when 'warn'
            message = StringIrc.new(message).yellow
          when 'error', 'alert', 'crit', 'err'
            message = StringIrc.new(message).red
          else
            message = StringIrc.new(message).green
          end

          @bot.handlers.dispatch(:syslog, nil, message.to_s)
        rescue Exception => ex
          puts "PLAIN: #{data}"
	        puts ex.message
  	      puts ex.backtrace.join("\n")
          @bot.handlers.dispatch(:syslog, nil, 'syslog exception')
          raise ex
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11003627569528417, 'fraction_numerical': 0.007255139056831923, 'mean_word_length': 1.9387211367673178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5304156', 'n_tokens_mistral': 1023, 'n_tokens_neox': 1021, 'n_words': 218}