move bot code out of Connection::event_loop, move tests out of crate root