Forward-port of https://github.com/inspircd/inspircd-extras/commit/a311dbcaea1abad68b87ebbb283fc6d75a207a53 into master