Ported from scrib/ScribIRC