Adds onAttach event.

This still needs ~~a lot of~~ some work.

– ~~The build system needs to be updated~~ (no it doesn't)
– ~~Tests need to be added~~
– The code needs cleaned up. I did it pretty fast
– Docs

=====

This adds `onAttach`. Ref #1856 for more about why this event is important.
:(