Port some cqbot script handling code