Sha256: 417bfcb84e5c9237d7f186c077dfecebd1ab2cca40e4de22a2fa6648eb19a626

Contents?: true

Size: 598 Bytes

Versions: 6

Compression:

Stored size: 598 Bytes

Contents

module MadChatter
  module Actions
    class Rename < MadChatter::Action
      
      @@regex = /\/nick (.+)/
      
      def handle(message)
        if message.text =~ @@regex
          old_username = message.username
          username = parse_username(message.text)
          MadChatter::Users.update(message.token, username)
          send_status_message "#{old_username} is now known as #{username}"
          send_users_list
          stop_message_handling
        end
      end
      
      def parse_username(text)
        @@regex.match(text).captures[0]
      end
      
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mad_chatter-0.2.1 lib/mad_chatter/actions/rename.rb
mad_chatter-0.2.0 lib/mad_chatter/actions/rename.rb
mad_chatter-0.1.3 lib/mad_chatter/actions/rename.rb
mad_chatter-0.1.2 lib/mad_chatter/actions/rename.rb
mad_chatter-0.1.1 lib/mad_chatter/actions/rename.rb
mad_chatter-0.1.0 lib/mad_chatter/actions/rename.rb