def encode_irc!(string, encoding = :irc)
      if encoding == :irc
        # If your text contains only characters that fit inside the CP1252
        # code page (aka Windows Latin-1), the entire line will be sent
        # that way. mIRC users should see it correctly. XChat users who
        # are using UTF-8 will also see it correctly, because it will fail
        # UTF-8 validation and will be assumed to be CP1252, even by older
        # XChat versions.
        #
        # If the text doesn't fit inside the CP1252 code page, (for example if you
        # type Eastern European characters, or Russian) it will be sent as UTF-8. Only
        # UTF-8 capable clients will be able to see these characters correctly
        #
        # (from http://xchat.org/encoding/#hybrid)
        begin
          string.encode!("CP1252")
        rescue ::Encoding::UndefinedConversionError
        end
      else
        string.encode!(encoding, {:invalid => :replace, :undef => :replace}).force_encoding("ASCII-8BIT")
      end

      return string
    end
def encode_irc!(string, encoding = :irc)
      if encoding == :irc
        # If your text contains only characters that fit inside the CP1252
        # code page (aka Windows Latin-1), the entire line will be sent
        # that way. mIRC users should see it correctly. XChat users who
        # are using UTF-8 will also see it correctly, because it will fail
        # UTF-8 validation and will be assumed to be CP1252, even by older
        # XChat versions.
        #
        # If the text doesn't fit inside the CP1252 code page, (for example if you
        # type Eastern European characters, or Russian) it will be sent as UTF-8. Only
        # UTF-8 capable clients will be able to see these characters correctly
        #
        # (from http://xchat.org/encoding/#hybrid)
        begin
          string.encode!("CP1252")
        rescue ::Encoding::UndefinedConversionError
        end
      else
        string.encode!(encoding, {:invalid => :replace, :undef => :replace}).force_encoding("ASCII-8BIT")
      end

      return string
    end
Encode a message to be sent over an IRC connection, modifying it in place.
 @param [String] string The string you want to encode.
 @param [Symbol] encoding The target encoding.
 @return [String] A string encoded in the encoding you specified.