Finch is a powerful text user interface instant messaging client based on libpurple, and it comes included in the Pidgin source, the popular GNOME IM client. Finch supports various protocols, including AIM, ICQ, MSN, Yahoo and IRC.
A great amount of Pidgin's functionality is exposed through D-Bus, so you can do a lot with a script that uses D-Bus to communicate with a running Pidgin. D-Bus has bindings for many languages; this means you can write such a script in many languages including Python, Perl, C++, Java, Ruby, and Haskell.