Sha256: 4f93ee7964c4c5344c5977328ff6e7180c42a7df96f1b1c5844fcd0e9405cc2a

Contents?: true

Size: 845 Bytes

Versions: 2

Compression:

Stored size: 845 Bytes

Contents

module MadChatter
  module MessageListeners
    class Code
      
      include MadChatter::Actions
      
      @@regex = %r{^/code (.+)}
      
      def handle(msg)
        if msg.original_text =~ @@regex
          # puts msg.original_text
          code = parse(msg.original_text)
          # puts code
          message = MadChatter::Message.new('message', nil, msg.token, msg.channel)
          message.html = "<pre>" + message.filter(code) + "</pre>"
          message.growl = msg.username + ' has shared a code sample' if msg.username
          channel = MadChatter::find_channel_by_id(msg.channel)
          channel.send_message(message)
          stop_message_handling
        end
      end
      
      def parse(text)
        text.sub!('/code', '')
        # @@regex.match(message_text).captures[0]
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mad_chatter-0.3.1 lib/mad_chatter/message_listeners/code.rb
mad_chatter-0.3.0 lib/mad_chatter/message_listeners/code.rb