A few things. Instead of putting things like and
$server
instead of doing you could do
$port
and for some servers, you could do
$replace($server,irc.,www.)
instead of