pull apart refactoring in bot.pl as a prelude to push it down